目前我可以通过 RemoteWebDriver 发送 firefox 配置文件,但我无法通过配置文件发送 RestCLient 扩展。 我需要某个 REST 客户端扩展(firefox 附加组件)可用于我的测试用例执行。
如果我使用 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);
干杯
最佳答案
创建 FirefoxProfile
之后例如,使用 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);
注意:您不必提前创建配置文件,FirefoxProfile
API 提供了几种方便的方法(“Method Summary”部分)来创建配置文件。例如,如果你想启动预装扩展的 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);
使用远程网络驱动程序的文档:
- RemoteWebDriver
-
RemoteWebDriver
Java API documentation - Grid2 (原始答案)和 Grid4 (2021 年更新)
关于java - Remote webdriver - 使用 Rest Client Extension(附加组件)传递 firefox 配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16616808/