Let me describe you steps of writing your first test case with TestNG.
1) Create New Project and New package for TestNG
- File -> New -> Java Project -> give new project name as "TestNG_Project"
- Richt click on "src" inside project name as "TestNG_Project" -> New -> Package -> give name as TestNG_Package
2) Add TestNG library
- Goto your project's Properties -> Java Build Path -> Libraries Tab.
- Click on Add Library button -> Select TestNG from Add Library popup and then click on Next and Finish buttons.
- And then verify it will add TestNg library in your project under library tab. Now click on OK button to close that window.
3) Create TestNG Class
- TO create TestNG class is different steps compare to create normal class in java project. Follow below steps to create TestNG class
- Right click on package as TestNG_package and click -> new -> other - it will open new wizard window
- Select TestNG from new wizard window and click on next button.
- on next screen add class name as "TestNG_Test1" and click finish.
- It will as new class as "TestNG_class1" under TestNG_Project with below coding.
package TestNG_Package;
public class TestNG_Test1 {
@Test
public void f(){
}
}
4) Add/write sample webdriver test script.
Write your own test script or add bellow given script in TestNG class file.
package TestNG_Package;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class TestNG_Test1 {
WebDriver driver1=new FirefoxDriver();
@BeforeMethod
public void OpenBrowser(){
driver1.get("http://google.com");
driver1.manage().window().maximize();
}
@AfterMethod
public void CloseBrowser(){
driver1.quit();
}
@Test
public void f() {
String title = driver1.getTitle();
System.out.println("title"+title);
}
}
5) Run Webdriver test script with TestNG
- Go to Run -> Run As -> And Click on TestNg Test
- It will run your webdriver test with TestNG.
- we can the result after complete the execution.
6) View test execution HTML report generated by TestNG
- Right click on Project named as "TestNG_Project and select Refresh.
- then Folder with name = "test-output" will be created under your project folder.
- Explorer that "test-output" folder. then we can see the "index.html" file.
- Right click on "index.html" file then select open with -> Web browser - To see the HTML report in Eclipse.
(Also the testng-customsuite.xml file will create automatically and configure the web driver test. Path = C:\Users\arunraj\AppData\Local\Temp\testng-eclipse--360075510\testng-customsuite.xml)
No comments:
Post a Comment