[英]capybara chrome headless confirm dialog
I'm trying to use headless mode of chrome with capybara/selenium in rspec Ruby on Rails and getting a error when try to click on confirm dialog 我试图在rspec Ruby on Rails中使用无头模式的chrome和capybara / selenium,并在尝试单击确认对话框时出现错误
Capybara.register_driver(:headless_chrome) do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: { args: %w[headless disable-gpu test-type window-size=1920x1080] }
)
driver = Capybara::Selenium::Driver.new(
app,
browser: :chrome,
desired_capabilities: capabilities
)
driver
end
Capybara.server = :puma
Capybara.javascript_driver = :headless_chrome
scenario 'delete movie' do
login_as user
visit edit_public_movie_path(movie)
expect(page).to have_selector('span[ng-click="ctrl.deleteMovie()"]')
find('span[ng-click="ctrl.deleteMovie()"]').click
page.driver.browser.switch_to.alert.accept
wait_for_ajax(wait_after: 1)
expect(page).to have_content('Click here to upload movie (Max: 500 MB)')
end
And got this error 并得到了这个错误
Event movie success delete movie
Failure/Error: page.driver.browser.switch_to.alert.accept
Selenium::WebDriver::Error::NoSuchAlertError:
no alert open
(Session info: headless chrome=59.0.3071.115)
(Driver info: chromedriver=2.29.461585 (0be2cd95f834e9ee7c46bcc7cf405b483f5ae83b),platform=Mac OS X 10.12.5 x86_64)
With common mode it works without errors. 使用普通模式,它可以正常工作。 Seems the selenium don't support headless mode or need to other approach to do it. 似乎硒不支持无头模式或需要其他方法来做到这一点。 Any ideas? 有任何想法吗?
Update(resolved) 更新(解决)
So, I spent a lot of time and find working environments. 所以,我花了很多时间找工作环境。
You need to last build of chromium because preview versions have a bug . 您需要持续构建chrome,因为预览版本存在错误 。 You can get it by these scripts linux or Mac 你可以通过linux或Mac这些脚本来获取它
Here is my capybara config 这是我的水豚配置
Capybara.register_driver(:headless_chrome) do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: {
args: %w[headless disable-gpu disable-popup-blocking no-sandbox window-size=1920x1920],
binary: "#{Dir.home}/chromium-latest-#{platrofm}/latest/#{chrome_file}"
})
driver = Capybara::Selenium::Driver.new(app,
browser: :chrome,
desired_capabilities: capabilities)
driver
end
Capybara.server = :puma
Capybara.javascript_driver = :headless_chrome
Capybara.default_max_wait_time = 20
Capybara.server_port = 55305
def platform
if /linux/ =~ RUBY_PLATFORM
"linux"
else
"macosx"
end
end
def platform_linux?
platform == "linux"
end
def chrome_file
if platform_linux?
"chrome"
else
"Chromium.app/Contents/MacOS/Chromium"
end
end
And you should use page.driver.browser.switch_to.alert.accept instead of page.accept_alert 你应该使用page.driver.browser.switch_to.alert.accept而不是page.accept_alert
Had the same problem. 有同样的问题。 Please use the disable-popup-blocking in chromeOptions. 请使用chromeOptions中的disable-popup-blocking。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.