Effective and best way to write testng script in Selenium

Hello Welcome to TestNG tutorial, today we will see how to write testng script in Selenium. Before moving forward make Sure TestNG  and Eclipse is ready is Installed.

If you are new to Eclipse the check Eclipse tips and tricks also.

 

write testng script

Q1-Difference between Java Program and TestNg Script?
Ans- When we execute Java program and TestNG script then functionality wise nothing will change because our script is performing the same functionality but using TestNG you will get some additional functionality.

Some benefit of TestNG Script

1- For even single test case you will get 3 reports. These reports generated by TestNG
2-You can check execution time i.e. How much time test case has taken
3-Parallel execution  etc

Let’s write 1 simple java program and 1 TestNG script then will compare

Basic Java Program 

 

Steps to Write testng script

 


Q2- How we can write TestNG Script?

Ans- To execute TestNG script we don’t have to write the separate class. We can use simple java class but here we will not write public static void main(String []args) because we are not going to execute this from JVM.

TestNG works with Annotations and annotation can be represented by @ symbol

@Test- is this the main annotation from where TestRunner will start execution.
In other words, you can say @Test in entry point

 

  • Step 1- Select your project
  • Step 2- Go to src and create a new package and give any name (I gave demo)
  • Step 3- Now select above created package and create a new class and give any name (I gave TestScript1)
  • Step 4- create a simple java method and before that method use @ Test

Complete program write testng script

 

Step 5- Once you completed the script simply right click on above created program and select run as> TestNG Test.

 

Check Official documentation of TestNG  for more info 🙂

Thanks for visiting my Blog. Keep reading and visiting.

Have a nice day.

 

28 Comments

  1. bhaskar