Tuesday, 23 April 2019

Single Test case Run parallel with TestNG Framework

1) Create TestNG class.

package com.software.testing;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class TC1 {
WebDriver driver;

@Test
public void firstTestCase() {
// Printing Id of the thread on using which test method got executed
System.setProperty("webdriver.chrome.driver", "Your Driver Path");
driver = new ChromeDriver();
driver.get("https://www.google.com");
}
}
2) Now Create testng.xml file into your project folder

<suite name="ParallelTestingGoogle" verbose="1" parallel="tests" thread-count="5">
    <test name="1stExecution">
        <classes>
            <class name="com.software.testing.TC1"></class>
        </classes>
    </test>
    <test name="2ndExecution">
        <classes>
            <class name="com.software.testing.TC1" />
        </classes>
    </test>
    <test name="3rdExecution">
        <classes>
            <class name="com.software.testing.TC1" />
        </classes>
    </test>
    <test name="4thExecution">
        <classes>
            <class name="com.software.testing.TC1" />
        </classes>
    </test>
    <test name="5thExecution">
        <classes>
            <class name="com.software.testing.TC1" />
        </classes>
    </test>
</suite>

Note : Don't forget to specify parallel="tests".

When you run your testNg suite it will open five chrome window and run your test case parallel.

Single Test case Run parallel with TestNG Framework

1) Create TestNG class. package com.software.testing; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome....