How to create a test case with TestNG in Selenium

0 votes
How to create a test case with TestNG in Selenium?
May 21, 2019 in Selenium by Deepak
1,165 views

1 answer to this question.

0 votes

Hey Deepak, to create a Test Case with TestNG in Selenium, follow these steps:

  1. Press Ctrl+N or Right click on Test Case folder,  select “TestNG Class” under TestNG category and click Next:

  2. Set Class name as ‘TestNG‘. Under Annotations, check “@BeforeMethod”, “@AfterMethod” and click Finish. That’s it.

  3. Now it will display the newly created TestNg class under the Test Case package(folder). Project explorer will look like this with TestNG class.

  4. Now write the first TestNG test case. You can divide the test case into three parts:

    • @BeforeMethod : Launch Firefox and direct it to the Base URL

    • @Test : Enter Username & Password to Login, Print console message and Log out

    • @AfterMethod : Close Firefox browser.

  5. Run the test by right click on the test case script and select Run As > TestNG Test.

  6. Give it few minutes to complete the execution, once it is finished the results will look like this in the TestNg Result window.

  7. TestNG also produce HTML reports. To access those reports go to the Project directory and open test-output folder.

answered May 22, 2019 by Abha
• 28,140 points

Related Questions In Selenium

0 votes
1 answer

How to create a Base Class in Selenium and use it with test scripts?

Hi Donna, you can use following code ...READ MORE

answered Jul 18, 2019 in Selenium by Anvi
• 14,150 points
12,479 views
0 votes
1 answer

How to disable a test case in testNG?

You can use the enable method to ...READ MORE

answered Jan 3, 2019 in Selenium by Nabarupa
2,095 views
0 votes
1 answer

How can I create a POM test case in Selenium Webdriver?

Hey Akshay, follow these steps to create ...READ MORE

answered May 13, 2019 in Selenium by Anvi
• 14,150 points
1,435 views
0 votes
1 answer

How to write a test case in Selenium IDE?

Hey Sam, to write a test case ...READ MORE

answered May 14, 2019 in Selenium by Pratibha
• 3,690 points
2,775 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,428 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,003 views
0 votes
2 answers

What is the role of TestNG & JUnit frameworks in Selenium?

TestNG and JUnit are test frameworks . it ...READ MORE

answered Sep 4, 2020 in Selenium by Sri
• 3,190 points
2,772 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,113 views
0 votes
1 answer

How to pass parameter through testng.xml file to a test case in Selenium Webdriver?

Hello Revathi, to pass parameter through testng.xml ...READ MORE

answered Jun 12, 2019 in Selenium by Abha
• 28,140 points
7,590 views
0 votes
1 answer

How to run a group of test cases using TestNG in Selenium Webdriver?

Hey Kajal, TestNG allows you to perform ordered ...READ MORE

answered Jun 12, 2019 in Selenium by Abha
• 28,140 points
2,887 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP