Modifying first script for TestNG

In the last post, we learned how to install TestNG in Eclipse. Today we will see how we can run our test scripts using TestNG annotations. We have created one small script to launch browser so we are going to modify that script according to TestNG.

First, create a method launchFireFox() in class LaunchBrowser and copy the code inside the main() method to this method.

testngscrpt1

We don’t need main() method anymore as we are going to run our scripts with TestNG so we will remove main() method.

testngscrpt2.jpg

We can see one error on line 8 as we didn’t import annotation class in this class. so, click on error symbol and click Import ‘Test’ (org.testng.annotations) and save the changes

testngscrpt3.jpg

Error should disappear and our script should be ready to run. To run it,

Click on down arrow highlighted in image > Run As > TestNG Test

testngscrpt4

The test case should execute successfully.

testngscrpt5

So that’s it for now. Reach out to me if you have any query or suggestions.

Have a great Day!!!

Leave a comment