【问题标题】:How to run single test case in multiple instances of browser parallelly without selenium grid如何在没有硒网格的情况下在多个浏览器实例中并行运行单个测试用例
【发布时间】:2019-04-20 15:14:14
【问题描述】:

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

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

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 浏览器实例,但它们一个接一个地在单个浏览器实例中运行。

【问题讨论】:

    标签: java multithreading selenium selenium-webdriver testng


    【解决方案1】:

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

    您可以在每次要运行该类时创建一个节点,然后通过test 进行并行化。您还希望将并行化属性移动到 &lt;suite&gt; 节点。例如:

    测试NG.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:

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

    【讨论】:

      猜你喜欢
      • 2013-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-12
      • 2023-01-28
      • 2018-05-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多