【问题标题】:Setting separate profiles for Parallel Selenium Tests为并行 Selenium 测试设置单独的配置文件
【发布时间】:2015-02-21 02:18:03
【问题描述】:

我正在研究如何使用 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());
}

【问题讨论】:

  • 你怎么称呼这个? methodName 是什么?
  • 所以每个测试都有单独的配置文件?您确定所有这些配置文件都存在吗?
  • 由于所有这些测试都在远程运行并且这些配置文件不存在,我希望它能够即时创建并将其分配给驱动程序。是不是不能创建一个配置文件目录并将其分配为每个驱动程序的配置文件?
  • selenium 默认创建一个新的配置文件然后运行测试。如果您不需要“重用”配置文件,则无需执行任何操作。如果你想分配一个创建的配置文件,你需要先创建它们并使用 selenium 来加载它们,就像你已经做的那样

标签: selenium selenium-grid selenium-firefoxdriver remotewebdriver parallel-testing


【解决方案1】:

如果您不想自定义 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);

【讨论】:

  • 如果我们运行多个 RemoteWebdriver 实例,它将如何影响测试。鉴于我根本没有设置配置文件,每个驱动程序实例是否会将 cookie 存储在其自己的默认配置文件中,或者是否有可能共享 cookie?如果是,那么我应该如何证明 cookie 是否被共享?
  • Cookie 不共享!由于 Selenium 为每个实例制作了配置文件的“副本”。您可以通过使用不同用户凭据的简单登录测试来对此进行测试。
猜你喜欢
  • 2015-12-17
  • 1970-01-01
  • 1970-01-01
  • 2011-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多