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.
Install plugin in eclipse
-
Go to help -> install new software .
-
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-
-
Make a new java project .
-
Open build path -> configure build path.
-
Click on add library -> TestNG.
-
Add selenium and testng jar file .
-
Right click on src -> New -> other -> TestNG class.
-
Click on finish button .
How testng is useful :
-
Make a java project .
-
Add jar file realted to selenium and testng .
-
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();
}
}
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
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Dinesh Dhiman
Dinesh is good in java and grails with having extra knowledge in AngularJS , HTML ,SQL , Selenium