Selenium Test Cases in Java with TestNG Tutorial

In this TestNG tutorial, We are going to cover How you can Start the TestNG in Selenium Java.

TestNG is next generation testing framework like JUnit & NUnit but with extra features(Read keywords, Generate Test Reports, Generate logs) and easy to use. TestNG framework can cover different type of the tests like Integration, Unit, end-to-end, etc.

  Installing TestNG in Eclispe:

  • Open Eclipse , Select Help / Software updates / Find and Install.
  • Search for new features to install.
  • New remote site.
  • For Eclipse 3.4 and above, enter http://beust.com/eclipse.
  • For Eclipse 3.3 and below, enter http://beust.com/eclipse1.
  • Make sure the checkbox next to URL is checked and click Next.
  • Eclipse will then guide you through the process.

We are going to Test a Demo website “http://demoaut.com/mercuryregister.php” and will write a Test case
to Do a Registration in it.

Project Structure:

Step1:
Create a project in the eclipse. Add the Selenium StandAlone jar and TestNG jar into a new libs  folder.
Make sure you add them to Build Path by Right Click – Build Path –> Add to Build Path.

Step2:
Create a Base Class with Test Fixture methods e.g. Setup and Tear Down. Note: I have added function name
as JUnit you can name them as you want), Add annotations as Before Method and After Method.

 

 

Step3 :

Create a Separate Class with Name Registration .java to write a Test case for Registration of the
Demo: Website http://demoaut.com/mercuryregister.php

 

Step4: Now let’s create a Final class and TestNG xml file.

MainClass.java

 

 

Step5:
Now Run the Test by Creating new TestNG configuration by Clicking on the Project->Run Configuration, Select
the TestSuite and browse the XML file(testng.xml). and Now Run the Project.

Step6:
After run successfully, If you refresh you project you will see the test-output folder , Open “index.html” and see that You Test Suite Results. Click on the Report output link you can see max length also.(Used as Logging)

Source code Github

You may also want to checkout

The Definitive Guide to Do API Testing in 2019

How to do Local testing and what is it?

Leave a Comment


This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Shares
Share
Tweet
Pin