问题
I'm using selenium-grid, and want to how to start my tests in parallel on the same browser, for example: Chrome
The problem is, Chrome keeps opening only one instance util the first test is finished, and then start the next test.
Please help me :)
public WebDriver createDriverGrid() throws MalformedURLException {
String hubUrl = "http://localhost:4446/wd/hub";
ChromeOptions capabilities = new ChromeOptions();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "chrome");
driver.set(new RemoteWebDriver(new URL(hubUrl), capabilities));
return driver.get();
}
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="GoogleTestSuite" verbose="2" parallel="tests" thread-count="2" preserve-order="true">
<test name="GoogleTest-CH" parallel="true">
<!--<parameter name="browser" value="chrome"></parameter>-->
<classes>
<class name="com.herokuapp.theinternet.tests.GoogleTests" />
</classes>
</test>
</suite>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="PositiveTestSuite" verbose="2" parallel="tests" thread-count="2" preserve-order="true">
<test name="PositiveTest-CH" parallel="true">
<classes>
<class name="com.herokuapp.theinternet.tests.PositiveTests" />
<!--<class name="com.herokuapp.theinternet.tests.PositiveTests" />-->
</classes>
</test>
</suite>
回答1:
If you want to start the test in parallel executing then you write a twice of your test method. As per your TestNG.xml, you have to write parallel="tests" thread-count="2" that means there has two test method which we want to execute parallelly.
Kindly replace your xml with below code:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="PositiveTestSuite" parallel="tests" thread-count="2">
<test name="PositiveTest-CH">
<classes>
<class name="com.herokuapp.theinternet.tests.PositiveTests" />
</classes>
</test>
<test name="PositiveTest-CH1">
<classes>
<class name="com.herokuapp.theinternet.tests.PositiveTests" />
</classes>
</test>
</suite>
Try this it will be working fine.
回答2:
You can achieve this by using jenkins pipelines, without having to modify your source code
来源:https://stackoverflow.com/questions/55308929/selenium-grid-parallel-execution-on-the-same-browser