How to create a test case with TestNG in Selenium?

0 votes
How to create a test case with TestNG in Selenium?
May 21 in Selenium by Deepak
22 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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 21 by Abha
• 9,330 points

Related Questions In Selenium

0 votes
1 answer
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 12 in Selenium by Anvi
• 7,480 points
22 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 13 in Selenium by Pratibha
• 2,520 points
13 views
0 votes
1 answer
0 votes
1 answer

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,050 points
142 views
0 votes
1 answer
0 votes
1 answer

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

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

answered Apr 18, 2018 in Selenium by king_kenny
• 3,590 points
149 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,130 points
531 views
0 votes
1 answer
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 in Selenium by Abha
• 9,330 points
20 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.