Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试使用Selenium和Ruby加载默认chrome配置文件进行测试_Ruby_Google Chrome_Selenium - Fatal编程技术网

尝试使用Selenium和Ruby加载默认chrome配置文件进行测试

尝试使用Selenium和Ruby加载默认chrome配置文件进行测试,ruby,google-chrome,selenium,Ruby,Google Chrome,Selenium,目前,我正在使用Selenium和Ruby进行黄瓜测试。我遇到的一个问题是,在测试期间制作的chrome选项卡没有与我的正常浏览chrome选项卡相关的设置,我需要这些设置,因为我想使用安装在那里的扩展。有没有一种好方法可以用Selenium加载默认的chrome配置文件,这样我就可以实现这一点?我在网上找到的东西在尝试时运气不太好 您可以使用ChromeOptions传递启动浏览器时要加载的扩展的路径: ChromeOptions options = new ChromeOptions();

目前,我正在使用Selenium和Ruby进行黄瓜测试。我遇到的一个问题是,在测试期间制作的chrome选项卡没有与我的正常浏览chrome选项卡相关的设置,我需要这些设置,因为我想使用安装在那里的扩展。有没有一种好方法可以用Selenium加载默认的chrome配置文件,这样我就可以实现这一点?我在网上找到的东西在尝试时运气不太好

您可以使用
ChromeOptions
传递启动浏览器时要加载的扩展的路径:

ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/path/to/extension.crx"));
ChromeDriver driver = new ChromeDriver(options);

一般来说,您的测试不应依赖于个人浏览器的状态。使用selenium webdrivers的一个好处是实际上有一个可定义的固定状态作为开始。

您应该能够使用“--user data dir”加载现有的chrome配置文件路径

例如:

require "selenium-webdriver"
class MyClass
dir='path of your existing chrome profile'
@driver = Selenium::WebDriver.for :chrome, :switches => %W[--ignore-certificate-errors --user-data-dir=#{dir} --enable-logging]