【问题标题】:Capybara/selenium browser refreshed with the blank pageCapybara/selenium 浏览器用空白页刷新
【发布时间】:2014-06-17 17:01:00
【问题描述】:

添加 selenium-webdriver gem 后,启动 capybara 测试时,浏览器开始显示主页,之后刷新为空白页面。

这会导致我之前通过的测试失败。显示Capybara::ElementNotFound 错误。

我使用capybara 2.2.1硒 2.42.0; 红宝石 2.1.0; 导轨 4.1.0; rspec 3.0

这是我的测试:

require 'spec_helper'

describe "Navigation" do

    it "changing active menu element depending on route", js: true do

    visit '/'


    first(:link, 'WHAT IS DREAMDO?').click
    expect(find('.navigation').find('.active').find('a').text).to eq('WHAT IS DREAMDO?')

    first(:link, 'DISCOVER DREAMS').click
    expect(find('.navigation').find('.active').find('a').text).to eq('DISCOVER DREAMS')

    first(:link, 'DREAMDO WEEKLY').click
    expect(find('.dreamdo-menu-items').find('.active').find('a').text).to eq('Dreamdo Weekly')

    end

end
describe "Search", js: true do

    it "checks for the availability and search results" do
      search_text = find(:xpath, '//input[@id="search_text"]').set("chocolate")
      search_text.native.send_keys :return
      page.should have_content "chocolate"
    end

end

你能推荐我怎么做吗?

【问题讨论】:

  • 您使用的是什么版本的 selenium、capybara 和 rspec?
  • @Xerif917 我使用水豚 2.2.1;硒2.42.0;红宝石2.1.0;导轨 4.1.0; rspec 3.0

标签: ruby-on-rails selenium-webdriver capybara


【解决方案1】:

其实用selenium也不好,因为它不能运行多个实例: http://robots.thoughtbot.com/capybara-webkit

尝试使用capybara-webkit,希望能解决你的问题。

【讨论】: