TestNG

TestNG is a test automation framework emerged to overcome the limitations of both JUnit and NUnit. It has many new features which are more powerful and easy to use.

  • Annotations.
  • Multithread safe tests.
  • Data driven testing.
  • Parameterization support.

Test NG supports a different variety of tests like unit, integration, system, functional and end to end.

Setup TestNG:

It can be installed into eclipse via two methods.

  • From Eclipse Marketplace.
  • From update site.

Install from Eclipse Marketplace:

Step 1: Open Eclipse and click on Help┬ápresent in the Menu bar. Then click on Eclipse Marketplace…

Step 2: Enter testng in the search box and click on Go button. Click on install button.

Step 3: Do not change anything in the next screen and click on Confirm button.


Step 4: Sofware installation begins and a Security Warning popup displays on the screen.

Click on OK button present in the Security Warning.

Step 5: Software is installed and it will ask you to restart the Eclipse to reflect the changes.

Step 6: Check whether TestNG is installed or not. Go to Project –> Properties.

Step 7: We can see TestNG from the left side section.

 

Install from the update site:

Step 1: Open Eclipse and click on Help present in the Menu bar. Then click on Install New Software…


Step 2: Type http://beust.com/eclipse as below and press enter button. TestNG will get populated from that site. Click on Next button.

 

Step 3: Do not modify anything and click on Next button.

 

Step 4: Accept the license agreement and click on Finish button.

 

Step 5: TestNG will be installed successfully.

 

Learn Test NG annotations from below link.
TestNG annotations.

 

package com;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import java.util.concurrent.TimeUnit
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterTest;
public class TestNG {
WebDriver driver;
@BeforeTest<
public void beforeTest() {
// chrome driver
System.setProperty(“webdriver.chrome.driver”,”C:\\Users\\username\\Downloads\\chromedriver_win32\\chromedriver.exe”);
driver = new ChromeDriver();

@Test
public void selenium99_TestNG() {
// this opens the url
driver.get(“https://selenium99.com”);
// Implicit wait used for each step to wait for specified period of
// time
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
// Prints the applications title<
System.out.println(driver.getTitle());
}
@AfterTest<
public void afterTest() {
// closes the browser.
driver.close();
}
}