简体   繁体   English

TestNG和Selenium-并行执行问题

[英]TestNG and Selenium - parallel execution issues

I'm having some issues with parallel execution of tests using TestNG + Selenium (Chrome WebDriver). 我在使用TestNG + Selenium(Chrome WebDriver)并行执行测试时遇到一些问题。 Basically, my tests don't actually appear to be truly executed in parallel. 基本上,我的测试实际上并没有真正并行执行。

Trying to achieve: Data being read from an Excel spreadsheet. 试图实现:正在从Excel电子表格中读取数据。 All test cases in TestSuite.java should execute for every row of data, in separate WebDriver instances - running in parallel. TestSuite.java中的所有测试用例应在单独的WebDriver实例中针对每一行数据执行-并行运行。 Eg testing 5 separate login/password combinations simultaneously in separate browser windows. 例如,在不同的浏览器窗口中同时测试5种不同的登录名/密码组合。

Simplified illustration: 简化图:

public class TestSuite {
    private String param;

    @DataProvider
    public static Object[][] provider() {
        return new Object[][] {{"1"},{"2"}};
    }

    @Factory(dataProvider = "provider")
    public TestSuite(String data) {
        this.param = data;
        System.out.println(String.format("[Thread: %d] TestSuite (%s)", Thread.currentThread().getId(), param));
        // Can't initialise webdriver instances here, different thread
    }

    @BeforeClass
    public void init() {
        System.out.println(String.format("[Thread: %d] BeforeClass (%s)", Thread.currentThread().getId(), param));
        // This is where I'm retrieving webdriver instances
    }

    @Test
    public void TC_001() {
        System.out.println(String.format("[Thread: %d] TC_001 (%s)", Thread.currentThread().getId(), param));
    }

    @Test
    public void TC_002() {
        System.out.println(String.format("[Thread: %d] TC_002 (%s)", Thread.currentThread().getId(), param));
    }
}

TestNG.xml: TestNG.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite" parallel="instances" group-by-instances="true">
  <test name="Test">
    <classes>
      <class name="TestSuite" />
    </classes>
  </test>
</suite>

Output: 输出:

[Thread: 1] TestSuite (1)
[Thread: 1] TestSuite (2)
[Thread: 11] BeforeClass (1)
[Thread: 11] TC_001 (1)
[Thread: 11] TC_002 (1)
[Thread: 12] BeforeClass (2)
[Thread: 12] TC_001 (2)
[Thread: 12] TC_002 (2)

The main issue here is that my tests are clearly being executed SEQUENTIALLY. 这里的主要问题是我的测试显然是依次执行的。 Can anyone explain what I have done wrong - what is the correct approach to achieve the desired outcome that I explained above? 谁能解释我做错了什么?实现上述我期望的结果的正确方法是什么?

make parallel as methods in TestNG.xml as below 如下所示将并行作为TestNG.xml中的方法

suite name="Suite" parallel="methods" group-by-instances="true" 套件名称=“ Suite” parallel =“ methods” group-by-instances =“ true”

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

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