Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
539 views
in Technique[技术] by (71.8m points)

webdriver - Popup blocking in Google Chrome causing issues with Capybara/Rspec tests

I'm writing some automated tests using Capybara/RSpec, I choose/configure the driver by using this little bit of ruby:

Capybara.register_driver :selenium_chrome do |app|
  Capybara::Selenium::Driver.new(app, :browser => :chrome)
end

I'm testing whether or not a button I click is opening a popup window and that the window is displaying the content it should. The issue is that when the test opens the window, the Google Chrome popup blocker blocks it, causing the tests to fail. Disabling the blocker from the options menu does not work. Also, I'm afraid that once I run these on the server it will cause the same issue.

Is there a way to disable the popup block for the tests automatically?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

We had a very similar problem. Like John says, the command-line switch no longer works. We tried using a custom profile, but it seemed to be overwritten.

Eventually solved it by manually disabling popups using WebDriver itself:

driver.get('chrome://settings/advanced')
driver.find_element_by_id('privacyContentSettingsButton').click()
driver.find_element_by_name('popups').click()

Which, I guess, is more like what the user would do anyway ;-)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...