Selenium Grid DriverSafe测试分发

时间:2014-12-17 17:42:15

标签: selenium-webdriver automated-tests testng selenium-grid parallel-testing

我按照this post中的说明设置了网格。另外,我在this post中设置了测试类。

由于我希望每个driverInstance使用自己的someControllersomeData,因此我更改了BaseTest,如下所示:

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) {
                try {
                this.someData       = SomeDataSetup.getSafeSomeData(new SomeData());
                this.driver             = WebDriverSetup.getDriver();
                this.someController = SomeController.getSafeSomeController(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();
            }
        }

为了获得每个单独的实例,我创建了以下类

    public class SomeDataSetup {

        public static SomeData getSafeSomeData(SomeData someDataSet ) {

            ThreadLocal<SomeData> someData = null;
            someData = new ThreadLocal<SomeData>();
            someData.set(someDataSet);
            return someData.get();
        }
    }

someController的类似内容。以下测试将在someData中使用自己的someControllerdriverTestClass实例,如下所示。

public class Tests extends BaseTest {
//This is used to do some setup in the super class
@Parameters({"testName", "env" })
public Tests( @Optional String testName, @Optional String env ) {
    super( null, testName, null, env );
}

@BeforeMethod
    public void setup() throws Exception {
        try {
            SomeData someData;
            SomeController someController;
            RemoteWebDriver driver;

            this.someData = SomeDataSetup.getSafeSomeData(new SomeData());
            this.driver = super.driver;
            this.someController = SomeControllerSetup
                    .getSomeController(new SomeController(
                            this.driver, this.someData));
            this.driver.navigate().to("https://" + this.host);

}  

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
}

获取每个someData,someController或驱动程序的线程安全实例是一种好方法,还是有一些可以在BaseTest本身中完成以返回每个实例的threadlocal实例?

0 个答案:

没有答案