I am using Capybara and Cucumber to run some integration tests, one of which requires JavaScript to be disabled, I can achieve this manually by going to developer tools and disabling JS (Chrome), but how can I automate this process. I would like an option to start a browser up with JS disabled or enable/disable mid test
Capybara.register_driver :chrome do |app|
chrome_binary = ENV["HENDRICKS_CHROME_BINARY"]
if chrome_binary.nil?
Capybara::Selenium::Driver.new(app, :browser => :chrome)
else
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
"chromeOptions" => {
"binary" => chrome_binary + "/Contents/MacOS/Chromium"
}
)
Capybara::Selenium::Driver.new(app, :browser => :chrome, :desired_capabilities => capabilities)
end
end
Is this possible with Chrome as my browser?
Why is it when you post a question you figure it out minutes later.. For anyone interested this is what I have done to disable JS
Capybara.register_driver :js_disabled do |app|
chrome_binary = ENV["HENDRICKS_CHROME_BINARY"]
if chrome_binary.nil?
Capybara::Selenium::Driver.new(app, :browser => :chrome)
else
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
"chromeOptions" => {
"prefs" => {
'profile.managed_default_content_settings.javascript' => 2
},
"binary" => chrome_binary + "/Contents/MacOS/Chromium"
}
)
Capybara::Selenium::Driver.new(app, :browser => :chrome, :desired_capabilities => capabilities)
end
end
Note the prefs object passed via the chromeOptions
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.