我正在建立一个框架,并希望在多个浏览器实例中并行运行一个测试方法(点击url然后执行一些操作)
(例如:通过同时打开〜5个Chrome浏览器实例来访问网址)

我以前可以并行运行不同的测试方法,但我想一次运行多个测试案例(并行)

GoogleTest.java

@Test(invocationCount=2)
public void hitUrl() throws Exception {
    WebDriver driver = getDriver();
    driver.get("https://google.com");
}


TestNG.xml

<suite thread-count="2" verbose="2" name="Gmail Suite"
    annotations="JDK" parallel="methods">

    <test name="Google_Test">
        <classes>
            <class name="big.GoogleTest">
                <methods>
                    <include name="hitUrl" />
                </methods>
            </class>
        </classes>
    </test>


我期望一次打开chrome的两个浏览器实例,但是它们正在一个浏览器实例中一个又一个地运行。

最佳答案

使用@Test(invocationCount= int Values),它将在同一浏览器中运行指定值的代码。

您可以为每次要运行该类的节点创建一个节点,然后按test进行并行化。您还希望将并行化属性移动到<suite>节点。例如:

TestNG.xml

<suite name="ParallelTestingGoogle" verbose="1" parallel="tests" thread-count="5">
    <test name="1st">
        <classes>
            <class name="packageName.className"/>
        </classes>
    </test>
    <test name="2nd">
        <classes>
            <class name="packageName.className" />
        </classes>
    </test>
    <test name="3rd">
        <classes>
            <class name="packageName.className" />
        </classes>
    </test>
    <test name="4th">
        <classes>
            <class name="packageName.className" />
        </classes>
    </test>
    <test name="5th">
        <classes>
            <class name="packageName.className" />
        </classes>
    </test>
</suite>


java - 如何在没有 Selenium 网格的情况下在多个浏览器实例中并行运行单个测试用例-LMLPHP

JAVA:

public class TC1 {
    WebDriver driver;

    @Test
    public void testCaseOne() {
        // Printing Id of the thread on using which test method got executed
        System.setProperty("webdriver.chrome.driver", "your ChromeDriver path");
        driver = new ChromeDriver();
        driver.get("https://www.google.com");
    }
}

08-18 15:06
查看更多