What is TestNG in Selenium Webdriver?

What is TestNG in Selenium Webdriver?

TestNG is a test framework designed to cover all test categories: unit, functionality, end-to-end, integration, etc…

We can combine TestNG with Selenium and, through Java, we can write test cases in Eclipse.

Let’s start with TestNG!

Here is a small tutorial who sends quality control test samples to Selenium TestNG and calls Ant’s TestNG collection. You can use any programming language supported by Selenium 2. I used Java in the tutorial below.

Install this software before starting

(if you do not have one):

JDK

Eclipse

TestNG: download TestNG from the Eclipse help menu.

Download the Selenium server from http://docs.seleniumhq.org/download/

Follow-up steps:

Step 1: Use Eclipse. Create a new Java project.

Step 2: Add a Selenium server to a jar file as an external jar file in your project. To do this, right click on any file/folder in the project in Eclipse. Select Generate compilation -> Configure compile compilation. Select the “Libraries” tab. Click on “Add external socket”. Select the Selenium file that you have already downloaded.

Step 3: Use the TestNG library in the project: right-click on any file/folder in the project in Eclipse. Select Generate compilation -> Configure Compilation. Select the “Libraries” tab. Click on “Add library”. Select TestNG. Click on “OK”.

Step 4: TestNG Testsuite contains numerous tests. The TestNG “test” comprises one or more classes, and the TestNG class consists of several “test methods”.

Add a new Java class “TestClass1” to the project. Below is a set of selenium test cases written as the TestNG method. In the code below, 4 test cases are added for demonstration purposes. Add the following code to the Java class.

Step 6: Run the test point by right-clicking on TestNG.xml and select Run as -> TestNG suite. The test points are executed and a summary of the execution of the test is shown in the Eclipse console. TestNG automatically creates a test report. To view the report, go to the project directory and select the test results folder. Open idex.html. As shown in the report below, tests 1, 2 and 3 are passed. The test strip 4 failed.

Step 7: The TestNG suite was successfully implemented! Now we want to use Ant to start the TestNG test instead of the eclipses. We need to determine the location of the Selenium server and the Shrimp TestNG Ant. Create a new folder in the project and give the files a jar.

Create a “lib” folder in your Java project.

Copy the Selenium server to this “lib” folder.

Also, copy testng.jar in the same folder. In the Eclipse directory, go to the add-on directory. There will be a directory, such as org.testng.eclipse_6.8.6.20130914_0724. In this directory, you will have testng.jar in the lib folder.

Step 9: Finish the Ant file. Go to the command line and go to the project directory. Enter the ant. In your project, you will start to run the ant build.xml script. Once the ant script has been executed successfully, see the report created by TestNG in the same location, that is, Files index.html in the test-output directory of your project.