Installation of testNG in eclipse and its use

Posted By : Dinesh Dhiman | 28-Apr-2015

TestNG is a testing framework inspired from JUnit and NUnit but introducing some new functionalities that make it more powerful and easier to use, such as: Annotations.

 
Here we see how to install testng and how we use it .
 

Install plugin in eclipse

  1. Go to help -> install new software .

  2. Add this link http://beust.com/eclipse in work with .

   3. Click on testng checkbox .

  4. Click on Next button then Finish button.

 

How to make testng class in eclipse-

  1. Make a new java project .

  2. Open build path -> configure build path.

  3. Click on add library -> TestNG.

  4. Add selenium and testng jar file .

  5. Right click on src -> New -> other -> TestNG class.

  6. Click on finish button .                                                                                                                                      

How testng is useful :

  1. Make a java project .

  2. Add jar file realted to selenium and testng .

  3. Make a testng class.

 package com.app;                                                                                                                                import java.io.FileInputStream;                                                                                                               
import java.io.InputStream;
import java.util.List;
import java.util.Properties;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class Login {
	String url=”any url”;
	WebDriver firefoxDriver = new FirefoxDriver();
	@BeforeTest                                                                                                                     	
        public void operBrowser() {
		 firefoxDriver.get(url);
	}
	@Test(priority=0)
	public void login() {
		firefoxDriver.findElement(By.linkText("Login")).click();
		firefoxDriver.findElement(By.name("email")).sendKeys("your id");
                firefoxDriver.findElement(By.id("login_password")).sendKeys("yourpassword");
		firefoxDriver.findElement(By.name("login-form")).submit();

	}
	@AfterTest
	public void closeBrowser() {
		firefoxDriver.close();
	}
      }
 
       4. Make an xml file to run the test cases .
 
  
    
      
 
 


 

5. Right click on xml file -> run as -> run configuration -> go to testNG -> testng.xml .

 

6. RUN

 

After run your test case refer the project you will see a folder with name <test-output> inside this folder you found index.html copy the path of that html and open into the browser  you will see the report of you test cases.

 

THANKS

 

 

 

Related Tags

About Author

Author Image
Dinesh Dhiman

Dinesh is good in java and grails with having extra knowledge in AngularJS , HTML ,SQL , Selenium

Request for Proposal

Name is required

Comment is required

Sending message..