0

我正在研究如何使用 RemoteWebDriver 设置个人配置文件。我一直在以下线程上阅读它。

http://stackoverflow.com/questions/12961037/parallel-execution-of-firefoxdriver-tests-with-profile-share-same-profile-copy

我试图解决它如下:

public static RemoteWebDriver getDriver(String methodName) throws MalformedURLException {

    String SELENIUM_HUB_URL = "http://localhost:4444/wd/hub";
    ThreadLocal<RemoteWebDriver> remoteWebDriver = null;

    File currentProfileFile = new File(methodName);
    //This is where it gives the error
    FirefoxProfile currentFireFoxProfile = new FirefoxProfile(currentProfileFile);
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    capabilities.setCapability(FirefoxDriver.PROFILE, currentFireFoxProfile);       
    String proxy = System.getProperty("proxy");

    try {
        remoteWebDriver = new ThreadLocal<RemoteWebDriver>();
        remoteWebDriver.set(new RemoteWebDriver(new URL(SELENIUM_HUB_URL),
                capabilities));
        } catch (MalformedURLException e) {
            System.out.println("Please fix the RemoteDriverSetup.class");
        }

    remoteWebDriver.get().manage().window()
            .setSize(new Dimension(2880, 1524));
    remoteWebDriver.get().manage().timeouts()
            .pageLoadTimeout(10, TimeUnit.SECONDS);
    remoteWebDriver.get().manage().timeouts()
            .implicitlyWait(10, TimeUnit.SECONDS);

 return remoteWebDriver.get(); // Will return a thread-safe instance of the WebDriver

}

我收到以下错误:

Time elapsed: 1.044 sec  <<< FAILURE!
org.openqa.selenium.firefox.UnableToCreateProfileException: Given model profile directory does      
not exist: TEST001

更新:我在下面的 BaseTest 类中注入方法名称

@BeforeMethod 
public void startTest(Method testMethod) {
        LOG.info("Starting test: " + testMethod.getName());
        this.driver             = WebDriverSetup.getDriver(testMethod.getName());
}
4

1 回答 1

0

如果您不想自定义 Firefox 配置文件上的任何内容,最好通过不提供任何配置文件详细信息来创建 Firefox webdriver 实例(如 Nguyen 所述)。

如果你真的想创建单独的配置文件(可能需要安装一些插件,如 Firebug),在这种情况下,你可以通过不传递任何文件名来实现,如下所示:

   FirefoxProfile currentFireFoxProfile = new FirefoxProfile();
   //Do some customization - add extension
   currentFireFoxProfile.addExtension(pathOfextensionToInstall);

   //or Setup some Firefox config. switch values
   currentFireFoxProfile.setPreference("browser.download.manager.showWhenStarting", false);
于 2014-12-23T06:56:07.683 回答