The code which I have written so far, in my previous tutorials, all were in main() function from where the java execution starts. Through Selenium Web Driver we can automate browsers but web driver does not provide any inbuilt reporting feature. So, with TestNG framework we can generate test reports in good format.
Now right click on src folder and select "New" option from the menu and click "Other". Find the below snapshot.
Choose TestNG class like in the below snapshot
To start with TestNG Framework you have to perform the following steps:
First, create the new Java project i.e. 'FirstTestNGProject' in eclipse like below.
Now right click on src folder and select "New" option from the menu and click "Other". Find the below snapshot.
If you are new to TestNG and not used earlier so might be you would not be able to see this TestNG as an option in your eclipse like in the above snapshot. So, you need to download the TestNG framework in your eclipse in order to get this option available for you. So, to download this you have to go to the Help Menu and select Eclipse Marketplace. See the below snapshot.
Then search for TestNG and install it in your eclipse. In my case, it's already installed that is why it is showing Installed in the below snapshot.
After installing this you will get the desired option to create a new TestNG class in eclipse. NOw after selecting the TestNG option we have to provide the source, package and name of the testNG class like below and click on Finish.
The one last task is to add the TestNG library in your project to support all the features provided by TestNG framework. You can not proceed with this framework without adding this library. Please do the following steps which I am going to show in the form of snapshots for more clarity.
After click on "Next" button then click on "Apply and Close" button. Now you are done with this setup and start writing code like the below example which I have already given in my previous post.
package Test;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class FirstTestNG {
@BeforeTest
public void makeDataBaseConnection()
{
System.out.println("Database connection established successfully");
}
@AfterTest
public void closeDataBaseConnection()
{
System.out.println("Database connection closed successfully");
}
@Test(priority=1)
public void doLogin()
{
System.out.println("Login done successfully");
}
@Test(priority=2)
public void ValidateNewEmployeeData()
{
System.out.println("New Employee's data validated successfully");
}
@Test(priority=3)
public void ValidateExistingEmployeeData()
{
System.out.println("Existing Employee's data validated successfully");
}
}
Then search for TestNG and install it in your eclipse. In my case, it's already installed that is why it is showing Installed in the below snapshot.
After installing this you will get the desired option to create a new TestNG class in eclipse. NOw after selecting the TestNG option we have to provide the source, package and name of the testNG class like below and click on Finish.
The one last task is to add the TestNG library in your project to support all the features provided by TestNG framework. You can not proceed with this framework without adding this library. Please do the following steps which I am going to show in the form of snapshots for more clarity.
After click on "Next" button then click on "Apply and Close" button. Now you are done with this setup and start writing code like the below example which I have already given in my previous post.
package Test;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class FirstTestNG {
@BeforeTest
public void makeDataBaseConnection()
{
System.out.println("Database connection established successfully");
}
@AfterTest
public void closeDataBaseConnection()
{
System.out.println("Database connection closed successfully");
}
@Test(priority=1)
public void doLogin()
{
System.out.println("Login done successfully");
}
@Test(priority=2)
public void ValidateNewEmployeeData()
{
System.out.println("New Employee's data validated successfully");
}
@Test(priority=3)
public void ValidateExistingEmployeeData()
{
System.out.println("Existing Employee's data validated successfully");
}
}
*********************************************************************************
Please comment if you have any issues or queries come up on your ways while doing this.
Best of Luck!
No comments:
Post a Comment