Selenium中没有网格的多个WebDriver实例

Selenium中没有网格的多个WebDriver实例

本文介绍了Selenium中没有网格的多个WebDriver实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在本地使用多个Selenium Webdriver而不使用Selenium网格同时运行多个测试?

Is it possible to use multiple selenium webdrivers locally without using selenium grid to run multiple test at the same time?

我通过调用new FireFoxDriver()创建多个实例,但是Windows中的会话似乎相互干扰.

I am creating multiple instances by calling new FireFoxDriver() but the sessions in the windows seem to interfere with each other.

驱动程序由下面显示的JUnit方法创建和销毁.对于每个测试类,都有一个WebDriver,但是每个测试用例都有不同的执行持续时间.在第一个Test类完成后,从该类中调用tearDownClass().抛出此异常:

The driver is created and destroyed by the JUnit-Methods shown below. For every Test-class there is one WebDriver but each testcase has a different execution duration. And after the first Test-class has finished and tearDownClass() from this class was called.This exception this thrown:

@BeforeClass
public static void setUpClass() {
    driver = new FireFoxDriver();
}

@AfterClass
public static void tearDownClass() {
    driver.quit(); // this should only kill the current driver
}

推荐答案

然后尝试对不同的实例使用不同的驱动程序变量:

Then Try to use different driver variables for different instances:

例如:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class Testing
{
    WebDriver driver1, driver2;
    @BeforeClass
    public void BeforeClass()
    {
        driver1 = new FirefoxDriver();
        driver2 = new FirefoxDriver();
    }
    @Test
    public void Test1() throws InterruptedException
    {
        driver1.get("http://www.google.com");
        driver2.get("http://gmail.com");

    }
    @org.testng.annotations.AfterClass
    public void AfterClass()
    {
        driver1.quit();
    }
}

这篇关于Selenium中没有网格的多个WebDriver实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 08:51