TOPICS:
1.Introduction
2.Parallel Execution with TestNG
3.Cross Browser Testing with TestNG
4.Data Provider in TestNG
5.Example Program
6.Conclusion
1.INTRODUCTION:
It is essential to guarantee the quality and dependability of applications in the ever-changing field of software development. A strong and efficient testing framework for Java, TestNG provides an extensive feature set to enable test automation. This article examines three essential TestNG features—cross-browser testing, parallel execution, and data providers and shows how to use them to improve the efficacy and efficiency of test automation initiatives.
2.PARALLEL EXECUTION WITH TESTNG:
Test automation is revolutionized by parallel execution, which enables tests to execute simultaneously across several threads or processes. TestNG's native support for parallel execution makes it possible to run tests more quickly and receive feedback on application changes more quickly. Teams can expedite the development of high-quality software and drastically reduce test execution time by utilizing parallel execution.
2.1 TESTNG OFFERS SEVERAL STRATEGIES FOR PARALLEL EXECUTION:
2.1.1.Parallel by Methods : If the parallel parameter is set to "method", Then TestNG will execute each of our test methods concurrently on distinct threads for every @Test method.
2.1.2.Parallel by Classes : If the parallel parameter is set to "test". Then TestNG will execute each test case defined in the tags in many threads.
2.1.3.Parallel by Tests : If the parallel parameter is set to "classes". Every test case found within the XML-based classes will execute parallel.
3.CROSS-BROWSER TESTING WITH TESTNG:
In order to guarantee consistency and compatibility across various web browsers, cross-browser testing is crucial. With TestNG strong cross-browser testing capability, developers can create browser-neutral test scripts and run them in a variety of browser scenarios.
TestNG uses WebDriver, an effective web browser automation tool, to make cross-browser testing easier. TestNG and WebDriver work together flawlessly, enabling developers to create test scripts with WebDriver APIs and run them in a variety of browsers, including Chrome, Firefox, Safari, and Edge.
4.DATA PROVIDER IN TESTNG:
A key component of test automation is data-driven testing, which enables tests to be parameterized using various input data sets. With its built-in data provider functionality, TestNG makes data-driven testing easier by allowing developers to contribute test data from external sources like databases, Excel sheets, CSV files, or custom data providers.
4.1 TESTNG'S DATA PROVIDER FEATURE OFFERS SEVERAL BENEFITS:
1.Separation of Test Data from Test Logic.
2.Re-usability of Test Scripts
3.Comprehensive Test Coverage
5.EXAMPLE PROGRAM:
We will now automate the login process for two basic websites, such as "facebook" and "orangeHRM."
Step 1: Install the Eclipse program on your computer, download the necessary jar files, and add the dependencies to the pom file.
Step 2: Create one package and two Java class files. Additionally, give one Java class file the name "automationLoginPage" and another the name "loginDataProvider".
Step 3: In the "automationLoginPage" java class file, add the test script for the "OrangeHRM" and "Facebook" login pages.
Step 4: Create two OrangeHRM and Facebook sheets in one Excel sheet and include them in the same bundle. and provide the login information.
Step 5: In the Java class file "loginDataProvider". The data is being retrieved from an Excel sheet, stored, and returned to a two-dimensional string array with a @Dataprovider(name="") annotation.
Step 6: Include the name of the data provider in the @Test Annotation.
Step 7: Generate a TestNg.xml file by selecting the package-> selecting TestNG-> converting to TestNG, and then select Finish. We need to add the parallel attribute and thread-count to Suite Level in order to execute the two test methods in parallel.
Step 8: Launch the file TestNG.xml. (The eclipse will simultaneously open two different browsers and initiate the login feature.)
We can view the outcome once the execution is finished.
6.CONCLUSION:
TestNG's extensive feature set, which includes cross-browser testing, parallel execution, and data provider capabilities, enables developers to design effective and dependable test automation solutions. Teams can speed up test cycles and the delivery of high-quality software by utilizing parallel execution. TestNG's cross-browser testing guarantees interoperability in a variety of browser contexts, and its data provider feature makes data-driven testing both adaptable and comprehensive. Teams can improve their test automation efforts and boost their confidence in the caliber of their applications by learning how to leverage TestNG's features.