TestNG – 2 || Installation process and a sample program of TestNG.

The installation process is very simple and it’s like installing an extension in a chrome browser.

Installation Process

Installation Process of TestNG software is very simple and easy. Just a few clicks and framework is ready for the use.

  1. Navigate to Help > Install new Software
  2. Click Add
  3. Add Repository > Name : Enter “TestNG
  4. Add Repository > Location: Enter “http://beust.com/eclipse
  5. Click on Add button
  6. Click on TestNG Checkbox under Name field.
  7. Click Next > Next
  8. Select “I Accept the terms of the license agreement” Radio button
  9. Click on Finish
  10. Pop-up gets closed. Please wait till TestNg installed automatically, verify the status on eclipse IDE on the bottom-right corner till Installation completed(100%).
  11. Autopop for Restart the Eclipse message should appear.
  12. Click OK/Restart.

Creating Project and Class File

  1. Create Java Project
  2. Add the latest version of WebDriver Jar files(selenium-java-3.0.0) using Build Path.
  3. Now Insert a Class File in the Project and write below code in that file. Make sure there is no Main() should be present in the class file.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
/**
 * @author ashok.kumar
 */
public class Sample {
	
	@Test //Annotation
	public void LaunchBrowser()
	{
		System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
		WebDriver driver=new ChromeDriver();
		driver.get("http://google.com");
		System.out.println("First Program of TestNG.");
	}
}
  1. You might observe error over @Test annotation.
  2. Just mouse hover on the @Test annotation and click on “TestNG Library”.
  3. The latest version of TestNG Library would get added in our Project.
  4. If not added automatically, we have to download it from the web and put in the project’s library using the build path.

Executing TestNG Program

  1. Right Click on the class file where the above code is written.
  2. Move to Run As option
  3. Click on TestNG Test option.
  4. It will execute the program and output will appear in the console window.

Error/Exceptions during execution

  1. If while running TestNG Program get Error classdefnotfounder, we have to download ‘jcommander.jar’ files and add into the project library using build path.

http://mvnrepository.com/artifact/com.beust/jcommander/1.7

     2. Option TestNG not appearing under RunAs pop-up menu: The possible cause is TestNg is not installed properly. Please re-visit to Installation Process for the same.

Report Analysis

After running the program, the result will be generated in two formats.

  1. Console Report
  2. HTML Report

Console Report

Eclipse Console.
Eclipse Console

This report is generating along with the execution, it means the user can see the step by step progress of the program during execution.

  • Each method which has been defined in the program is considered as a Test Case. So, the console report shows the below results:
    • Any type of console output.
    • Paas/Fail status of each Test Case
    • Total count of executed Test Cases
    • Total count of Failed Test Cases
    • Total count of Skipped Test Cases

HTML Report

TestNG also, generates an HTML Report in the Project Folder. This report generates only after the program execution completed.

To get this report, we need to refresh the project in the ‘Project Explorer’ window. A folder named “test-output” will appear in the root folder.

  • There would be multiple files are present to generate various type of reports. Click to expand the test-output and observe:
    • Index.html:
HTML Report
  • Emailable Report:

Related Links:

Java Basic:

Java File Handling:

OOPs Concept:

Java Question And Answer:

Java Programs:

Excel:


495total visits,3visits today

Leave a Reply

Your email address will not be published. Required fields are marked *