Selenium中没有网格的多个WebDriver实例? [英] Multiple WebDriver instances in Selenium without Grid?

查看:114
本文介绍了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:

org.openqa.selenium.remote.SessionNotFoundException:在调用quit()后无法使用FirefoxDriver. 内部版本信息:版本:"2.39.0",修订版:"14fa800511cc5d66d426e08b0b2ab926c7ed7398",时间:"2013-12-16 13:18:38" 系统信息:主机:'T61',ip:'127.0.1.1',操作系统名称:'Linux',os.arch:'i386',os.version:'3.11.0-15-generic',java.version :"1.7.0_51"

org.openqa.selenium.remote.SessionNotFoundException: The FirefoxDriver cannot be used after quit() was called. Build info: version: '2.39.0', revision: '14fa800511cc5d66d426e08b0b2ab926c7ed7398', time: '2013-12-16 13:18:38' System info: host: 'T61', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'i386', os.version: '3.11.0-15-generic', java.version: '1.7.0_51'

@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实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆