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
44 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 21 by Abha
• 20,240 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 in Selenium by Anvi
• 12,010 points
61 views
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
• 12,010 points
43 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,780 points
24 views
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,070 points
445 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,610 points
224 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
793 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
• 20,240 points
66 views