- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to run multiple test cases using TestNG Test Suite in Selenium?
We can run multiple test cases using TestNG test suite in Selenium webdriver. To execute test cases simultaneously, we have to enable parallel execution in TestNG.
A TestNG execution is driven by the TestNG xml file. To trigger parallel execution we have to use the attributes – parallel and thread-count. The attribute threadcount controls the number of threads to be triggered while executing the tests in a parallel mode. The values that can be set for parallel attributes are – tests, classes, instances and methods.
Example
import org.testng.annotations.Test; public class TestNG15 { @Test public void tC1() { System.out.println("Test Case 1"); } @Test public void tC2() { System.out.println("Test Case 2"); } @Test public void tC3() { System.out.println("Test Case 3"); } @Test public void tC4() { System.out.println("Test Case 4"); } }
TestNG XML Implementation.
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" > <!—parallel methods set for execution with 2 threads--> <suite name="Test-Suite" parallel="methods" thread-count="2"> <test name="Tutorialspoint" > <classes> <class name="TestNG15" /> </classes> </test> </suite>
Output
TestNG report in html format obtained from project folder test-output→index.html.
- Related Articles
- How to run multiple test classes in TestNG?
- How to run Selenium WebDriver test cases in Chrome?
- How to run test groups in TestNG?
- How to retrieve all test methods name in TestNG suite?
- How to retrieve the test suite name at runtime in TestNG?
- How to set priority to the test cases in TestNG?
- How does TestNG invoke a test method using multiple threads?
- How to combine multiple groups to single Test in TestNG?
- How to incorporate and remove test methods from execution from a\ncollection of test cases in TestNG?
- How can a particular group of test cases get executed in TestNG?
- How to Write Test Cases?
- How to group test cases in Pytest?
- How to exclude a test class from a testing suite using testng.xml?
- How to force end an entire test suite from the BeforeSuite annotation if a condition is met in TestNG?
- How to skip TestNG test at runtime?

Advertisements