0% found this document useful (0 votes)
2 views

TYPES OF EXECUTION

The document outlines various types of test execution in TestNG, including Batch, Parallel, Group, and Cross Browser Execution, along with instructions for setting up the TestNG.xml file for each type. It also explains the use of assertions in TestNG, distinguishing between Hard and Soft asserts, and provides examples of their implementation. Additionally, it covers how to pass parameters to tests and the significance of the @Parameters annotation.

Uploaded by

vimalelavarasu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

TYPES OF EXECUTION

The document outlines various types of test execution in TestNG, including Batch, Parallel, Group, and Cross Browser Execution, along with instructions for setting up the TestNG.xml file for each type. It also explains the use of assertions in TestNG, distinguishing between Hard and Soft asserts, and provides examples of their implementation. Additionally, it covers how to pass parameters to tests and the significance of the @Parameters annotation.

Uploaded by

vimalelavarasu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

22/03:

TYPES OF EXECUTION:

1.Batch Execution.
2.Parallel Execution.
3.Group Execution.
4.Cross Browser Execution.
i. Series.
ii. Parallel.

1.Batch Execution/Suite Execution:

*. It is used to execute n no of test case to whether in a single


click.
*. To achieve batch execution/any type of execution we have to
testng.xml file.

Steps to Create Testng.xml file:

1.Select the classes which we want to include in execution.


2.Right click and go to TestNG.
3.Then click on convert to TestNG.
4.Provide the file name and finish.

2.Parallel Execution:

*. It is used to execute multiple classes simultaneously in


different window of same browser.
*. To achieve this, we have to create TestNG.xml file and in that
we have to make <suite name="Suite" parallel="classes">

3.Group Execution:

*. It is used to execute a particular group of test case from n no


of test cases.

How to achieve?

*. While creating the test case we have to define the group.


EX:
@Test(priority = 1, groups = “smoke”)

A test case can belong to multiple groups..


EX:
@Test(priority = 1, groups = {“smoke” , ”sanity”})

*. In configuration annotations we have to use:


EX:
@BeforeClass (alwaysRun = true)
(OR)
@BeforeMethod (groups = {“smoke”,” sanity”})

*. In TestNG.xml file either we will include the group or exclude


the group.
EX:
<test thread-count="5" name="Test">
<groups>
<run>
<include name="smoke"></include>
</run>
</groups>
(OR)
<groups>
<run>
<exclude name="smoke"></exclude>
</run>
</groups>
NOTE:
 In one xml file we can include or exclude multiple groups.

24/03:

4.Cross Browser Execution:

*. It is used to execute the script in different different browsers


one after the another.

How To Achieve?

1.changes in base test.


EX:
@Parameters("browser")
@BeforeClass(alwaysRun = true)
public void openBrowser(String browser) {

if (browser.equals(browser)) {

driver = new ChromeDriver();


} else if (browser.equals(browser)) {
driver = new FirefoxDriver();
} else if (browser.equals(browser)) {
driver = new EdgeDriver();
}
driver.manage().window().maximize();

driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(1
0));
driver.get("https://demowebshop.tricentis.com/");
}

Changes in testng.xml File:

*. Under the Suite level we have to create multiple test runners


based on how many browsers we are going to launch.
*. Every test runner should have different name.
*. Under every test runner we have to use parameter tag by
passing the name and value.

EX:
<suite name="Suite">
<test thread-count="5" name="Test1">
<parameter name="browser" value="edge"></parameter>
<classes>
<class name="project_DWS.DWS_Cart"/>
<class name="project_DWS.DWS_Address"/>
</classes>
</test> <!-- Test -->
<test thread-count="5" name="Test2">
<parameter name="browser" value="firefox"></parameter>
<classes>
<class name="project_DWS.DWS_Cart"/>
<class name="project_DWS.DWS_Address"/>
</classes>
</test> <!-- Test -->
<test thread-count="5" name="Test3">
<parameter name="browser" value="chrome"></parameter>
<classes>
<class name="project_DWS.DWS_Cart"/>
<class name="project_DWS.DWS_Address"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->

Parameter Tag:

*. It is used to pass the parameter from testing.xml file to the


test script.
*. It will accept name and value of the parameter.
EX:
<parameter name="browser" value="chrome"></parameter>

*. This we have to use under the test level.


*. It will provide the value to @Parameters Annotation.

@Parameters Annotation:

*. It is used to take the data passed from the parameter tag.


*. In this annotation we have to pass name of the parameter.
*. This annotation we have to bind with either @Test or
configuration annotation.

26/03:

III) Assertions: -

*. It is one of the Feature provided by TestNG.


*. It is used to perform the validation.
*. We will go for Assertions, because if-else doesn’t have the
ability to fail the test case.
*. Assertions are of two types:
1.Hard Assert.
2.Soft Asser.

Difference Between Hard Assert and Soft Assert:

Hard Assert:
*. We can use hard assert for Blocker and Critical defect.
*. To use this TestNG has provided Assert class.
*. Methods of Assert class are static methods.
*. To use this no need to create any object.
*. If hard assert will get fail execution will stop immediately.

How To Use?
 Assert.assertEquals(driver.getTitle(), "Demo Web Shop",
"Welcome Page displayed Successfully...");

Soft Assert:
*. We can use soft assert for major and minor defect.
*. To use this TestNG has provided Soft Assert class.
*. Methods of Soft Assert class are non-static methods.
*. To use this need to create an object of soft Assert class.
*. If soft assert will get fail then also execution will continues.
How To Use?
 SoftAssert ast = new SoftAssert();
ast.assertEquals(driver.getTitle(), "Demo Web Shop",
"Welcome Page displayed Successfully...");

assertAll():
*. It is a compulsory present in Soft Assert class.
*. This we have to use at the last of the script.
*. It will only print the assertions failure in console or report.

You might also like