我on Rails的3.2使用Chromedriver 2.30.477691與谷歌鉻-β60.0.3112.50-1與硒的webdriver 3.4.3後,關閉鉻,我的問題是,只有第一個集成測試傳球和那麼瀏覽器會關閉,所有其他集成測試無論是否在同一個rspec文件或單獨的文件中都會失敗。chromedriver初試
如果我運行任何單個測試重點然後將其傳遞。我試過了,沒有無頭的選項,這沒有什麼區別,在第一次測試之後,我可以看到瀏覽器已關閉,並且不會爲未來的測試重新打開。
這些測試使用Firefox的運行,所以我知道測試運行良好。
這是我在rails_helper.rb
Capybara.register_driver(:headless_chrome) do |app|
caps = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: {
binary: "/opt/google/chrome-beta/google-chrome",
args: %w[headless disable-gpu]
}
)
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
desired_capabilities: caps
)
end
Capybara.current_driver =:headless_chrome
Capybara.javascript_driver = :headless_chrome
我的測試,如果它不是序列中的第一個測試,一個失敗的例子設置。
require "rails_helper"
RSpec.describe "Account Index Page Tests", :type => :feature do
before :each do
admin_sign_in
end
it "Ensure that the index contains one of the default accounts" do
visit "/#/accounts"
expect(find_by_id("heading")).to have_text("Account")
expect(find_by_id("new-btn")).to have_text("New")
expect(find_by_id("name0")).to have_text("Sales")
end
end
運行上述測試作爲第二個測試後,我得到錯誤這個錯誤。如果我按照相反的順序運行它,則另一個測試將失敗,而不是index_accounts。
% rspec spec/integration/accounts/create_accounts_spec.rb spec/integration/accounts/index_accounts_spec.rb
Randomized with seed 30251
.F
Failures:
1) Account Index Page Tests Ensure that the index contains one of the default accounts
Failure/Error: fill_in "Email", with: "[email protected]u"
Capybara::ElementNotFound:
Unable to find field "Email"
# ./spec/integration_helpers/login_helper.rb:43:in `admin_sign_in'
# ./spec/integration/accounts/index_accounts_spec.rb:7:in `block (2 levels) in <top (required)>'
Finished in 5.57 seconds (files took 6.2 seconds to load)
2 examples, 1 failure
Failed examples:
rspec ./spec/integration/accounts/index_accounts_spec.rb:10 # Account Index Page Tests Ensure that the index contains one of the default accounts
我震驚的是,硒的webdriver 2.53.4甚至還可以與最新的Chrome和chromedriver一個測試 - 升級到最新的硒的webdriver。留在硒2.53.4的唯一原因是如果你需要測試傳統的Firefox版本。 –
剛升級到selenium-webdriver 3.4.3,完全一樣的問題。 – map7
將水豚升級至2.14.4 – map7