gpt4 book ai didi

javascript - 运行 Cucumber 测试时禁用 JavaScript

转载 作者:行者123 更新时间:2023-11-29 22:51:04 25 4
gpt4 key购买 nike

我正在使用 Capybara 和 Cucumber 运行一些集成测试,其中一个需要禁用 JavaScript,我可以通过转到开发人员工具并禁用 JS (Chrome) 来手动实现此目的,但我如何才能自动执行此过程。我想要一个在禁用 JS 或启用/禁用中间测试的情况下启动浏览器的选项

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

Chrome 作为我的浏览器是否可行?

最佳答案

这是我为禁用 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

注意通过 chromeOptions 传递的 prefs 对象。

关于javascript - 运行 Cucumber 测试时禁用 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57473232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com