java 远程 webdriver - 使用 Rest Client 扩展(附加组件)传递 firefox 配置文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16616808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remote webdriver - Passing firefox profile with Rest Client Extension (add-on)
提问by LearningSnippet
Currently I am able to send a firefox profile over a RemoteWebDriver, but I am not able to send the RestCLient extension over the profile. I require a certain REST client extension(firefox add-on) to be available for my test case execution.
目前,我可以通过 RemoteWebDriver 发送 firefox 配置文件,但无法通过配置文件发送 RestCLient 扩展。我需要某个 REST 客户端扩展(firefox 附加组件)可用于我的测试用例执行。
If I run the test case locally using firefox driver it works....but how do I achieve the same thing using RemoteWebDriver?
如果我使用 firefox 驱动程序在本地运行测试用例,它可以工作......但是我如何使用 RemoteWebDriver 实现同样的事情?
File profileDirectory = new File("c://mach//lib//prof");
FirefoxProfile profile = new FirefoxProfile(profileDirectory);
driver = new FirefoxDriver(profile);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
Cheers
干杯
回答by Rob W
After creating a FilefoxProfile
instance, transfer the profile using the DesiredCapabilities
API (FirefoxDriver.PROFILE
= "firefox_profile"):
创建FilefoxProfile
实例后,使用DesiredCapabilities
API ( FirefoxDriver.PROFILE
= "firefox_profile")传输配置文件:
File profileDirectory = new File("c://mach//lib//prof");
FirefoxProfile profile = new FirefoxProfile(profileDirectory);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Note: You don't have to create a profile in advance, the FirefoxProfile
API offers several convenient methodsto compose a profile. For instance, if you want to launch Firefox with an extension pre-installed, use:
注意:您不必提前创建配置文件,FirefoxProfile
API 提供了多种方便的方法来编写配置文件。例如,如果您想使用预安装的扩展启动 Firefox,请使用:
FirefoxProfile firefoxProfile = new FirefoxProfile();
File extension = new File("extension.xpi");
firefoxProfile.addExtension(extension);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Documentation for working with the remote web driver:
使用远程 Web 驱动程序的文档: