Selenium Grid并行运行测试 [英] Selenium Grid running tests in parallel

查看:229
本文介绍了Selenium Grid并行运行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我有一个Selenium网格设置,具有1个本地集线器和2个本地节点.集线器能够分发并行运行的测试,并将其分发到节点.我正在并行运行测试.

Currently, I have a Selenium grid setup, with 1 local hub and 2 local nodes. The hub is capable of distributing the tests to run in parallel and distribute it over to the nodes. I am running the tests in parallel.

以下是基础测试

public abstract class BaseTest 
   {    
            String                      testFolder;
            String                      testName;
            protected String            envName;        
            protected Configuration     config;
            protected String            host;
            protected RemoteWebDriver   driver;
            protected String            proxy;
            protected SomeData      someData;
            protected SomeController someController;

            public BaseTest() {
              }

            public BaseTest( String testFolder, String testName) 
            {   
                this.testFolder         = testFolder;
                this.testName           = testName;
                this.envName            = System.getProperty("config");
                this.proxy              = System.getProperty("proxy");
                config = this.envName;
            }

            @BeforeMethod 
            public void startTest(Method testMethod) {
                LOG.info("Starting test: " + testMethod.getName());
                try {
                this.someData       = new SomeData();
                this.driver             = WebDriverSetup.getDriver();
                this.someController = new someController(this.driver, this.someData);
                driver.navigate().to("https://" + this.host);
                } catch (MalformedURLException e) {
                    System.out.println("MalformedURLException");
                }
            }
            @AfterMethod
            public void closeWindow() {
                driver.close();
                driver.quit();
            }
        }

以下是获取RemoteWebDriver的类:

The following is the class to get the RemoteWebDriver:

        public class WebDriverSetup {

            public static RemoteWebDriver getDriver() throws MalformedURLException{

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

                DesiredCapabilities capabilities = DesiredCapabilities.firefox();
                capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
                String proxy = System.getProperty("proxy");

                if (proxy != null && !proxy.isEmpty()) {
                    System.out.println("Using proxy: " + proxy);
                    capabilities.setCapability(CapabilityType.PROXY, proxy);
                }

                try {
                    remoteWebDriver = new ThreadLocal<RemoteWebDriver>();
                    remoteWebDriver.set(new RemoteWebDriver(new URL(SELENIUM_HUB_URL),
                            capabilities));
                } catch (MalformedURLException e) {
                    System.out.println("Tackle Issue with RemoteDriverSetup");
                }

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

我的测试套件就像:

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Multiple Tests Suite" verbose="1" parallel="methods">
    <test name="Test1">
        <classes>
            <class name="com.itesteverything.qa.Tests"></class>
        </classes>
    </test>
</suite>

测试就像:

public class Tests extends BaseTest {

@Parameters({"testName", "env" })
public Tests( @Optional String testName, @Optional String env ) {
    super( null, testName, null, env );
}

@BeforeMethod
public void setup() throws Exception {
    //setSomeData
}   

public void test1() throws Exception {  

use driver from super
use someData from super
use someController is using the driver from super
}

public void test2() throws Exception {  

use driver from super
use someData from super
use someController is using the driver from super
}

在运行这些测试时,出现以下错误

While running these tests, I get the following errors

内部版本信息:版本:"2.44.0",修订版:"76d78cf323ce037c5f92db6c1bba601c2ac43ad8",时间:"2014-10-23 13:11:40" 驱动程序信息:driver.version:RemoteWebDriver org.openqa.selenium.remote.SessionNotFoundException:会话ID为null.调用quit()后使用WebDriver吗? 内部版本信息:版本:"2.44.0",修订版:"76d78cf323ce037c5f92db6c1bba601c2ac43ad8",时间:"2014-10-23 13:11:40" 驱动程序信息:driver.version:RemoteWebDriver 在org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158) 在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:572) 在org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:352) 在org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:393) 在org.openqa.selenium.By $ ById.findElement(By.java:214) 在org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:344) 在org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:59) 在com.sun.proxy.$ Proxy25.sendKeys(未知来源) 在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处 在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:606) 在org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80) 在org.testng.internal.Invoker.invokeMethod(Invoker.java:673) 在org.testng.internal.Invoker.invokeTestMethod(Invoker.java:842) 在org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1166) 在org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) 在org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615) 在java.lang.Thread.run(Thread.java:745) 测试失败:test2 失败原因:会话ID为空.调用quit()后使用WebDriver吗?

Build info: version: '2.44.0', revision: '76d78cf323ce037c5f92db6c1bba601c2ac43ad8', time: '2014-10-23 13:11:40' Driver info: driver.version: RemoteWebDriver org.openqa.selenium.remote.SessionNotFoundException: Session ID is null. Using WebDriver after calling quit()? Build info: version: '2.44.0', revision: '76d78cf323ce037c5f92db6c1bba601c2ac43ad8', time: '2014-10-23 13:11:40' Driver info: driver.version: RemoteWebDriver at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:572) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:352) at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:393) at org.openqa.selenium.By$ById.findElement(By.java:214) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:344) at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:59) at com.sun.proxy.$Proxy25.sendKeys(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80) at org.testng.internal.Invoker.invokeMethod(Invoker.java:673) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:842) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1166) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) TEST FAILED: test2 FAILED REASON: Session ID is null. Using WebDriver after calling quit()?

有人知道吗?

提前谢谢!

推荐答案

不要在基类中设置驱动程序,根本没有驱动程序属性.相同的实例被不同的线程本地驱动程序覆盖.

Do not set driver in the base class, do not have driver property at all. The same instance is being overridden by different threadlocal drivers.

每次您要运行测试时,请在测试方法本身以及after/before方法中参考WebDriverSetup.getDriver().

Any time you want to run your test, refer to WebDriverSetup.getDriver() in your test method itself and in your after/before methods.

这篇关于Selenium Grid并行运行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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