简体   繁体   English

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

[英]Multiple WebDriver instances in Selenium without Grid?

Is it possible to use multiple selenium webdrivers locally without using selenium grid to run multiple test at the same time? 是否可以在本地使用多个Selenium Webdriver而不使用Selenium网格同时运行多个测试?

I am creating multiple instances by calling new FireFoxDriver() but the sessions in the windows seem to interfere with each other. 我通过调用new FireFoxDriver()创建多个实例,但Windows中的会话似乎相互干扰。

The driver is created and destroyed by the JUnit-Methods shown below. 该驱动程序由下面显示的JUnit方法创建和销毁。 For every Test-class there is one WebDriver but each testcase has a different execution duration. 对于每个测试类,都有一个WebDriver,但是每个测试用例都有不同的执行持续时间。 And after the first Test-class has finished and tearDownClass() from this class was called. 在第一个Test类完成后,将tearDownClass()该类中的tearDownClass() This exception this thrown: 抛出此异常:

org.openqa.selenium.remote.SessionNotFoundException: The FirefoxDriver cannot be used after quit() was called. org.openqa.selenium.remote.SessionNotFoundException:调用quit()后不能使用FirefoxDriver。 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' 内部版本信息:版本:'2.39.0',修订版本:'14fa800511cc5d66d426e08b0b2ab926c7ed7398',时间:'2013-12-16 13:18:38'系统信息:主机:'T61',ip:'127.0.1.1',OS。名称:'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: 然后尝试对不同的实例使用不同的驱动程序变量:

Eg: 例如:

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();
    }
}    

尝试使用不同的Eclipse。..我的意思是,启动两个Eclipse并在两个Eclipse中运行相同的程序。

You can use RemoteWebDriver without having a full Selenium Grid. 您可以在没有完整的Selenium网格的情况下使用RemoteWebDriver。 If you start the Selenium Standalone jar locally without defining a role, then it is in effect a Grid and Node combined into one. 如果在不定义角色的情况下在本地启动Selenium Standalone jar,则实际上是将Grid和Node合并为一个。 With this local Selenium Server instance, you can run several browsers concurrently. 使用此本地Selenium Server实例,您可以同时运行多个浏览器。

Creating a Firefox instance via RemoteWebDriver is pretty simple and well documented on line 通过RemoteWebDriver创建一个Firefox实例非常简单,并且在线记录得很好

Default selenium will run on 4444 port. 默认硒将在4444端口上运行。 Please create your instances as such that it takes different port each one by adding 请创建您的实例,以使每个实例占用不同的端口

     -port <port id/number>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM