Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

1 like 0 dislike
189 views
by The go-to Tester (344 points)
How to launch our tests using TestNG in Selenium when Java is used as the language

1 Answer

1 like 0 dislike
by The go-to Tester (473 points)
selected by
 
Best answer

Answer is too long and 1 comment allow only 8000 characters hence answring in multiple comments.

There are two methods to launch script in testng.

1) Using run as "TestNG Test"

   For this, install testng plugin in your eclipse.

      Stpes to Install:

         1) Launch the Eclipse IDE and from Help menu, click “Install New Software”.

      2) You will see a dialog window, click “Add” button.

          3) Type name as you wish, lets take “TestNG” and type                                                     “http://beust.com/eclipse/” as location. Click OK.

 

 

by The go-to Tester (473 points)
4) You come back to the previous window but this time you must see TestNG option             in the available software list. Just Click TestNG and press “Next” button.

      5) Click “I accept the terms of the license agreement” then click Finish.

      6) You may or may not encounter a Security warning, if in case you do just click OK.

      7) Click Next again on the succeeding dialog box until it prompts you to Restart the            Eclipse.

      8) You are all done now, just Click Yes.

      9) Proceed with your workplace.

      10) After restart, verify if TestNG was indeed successfully installed. Right click on you         project and see if TestNG is displayed in the opened menu.

Now write the java selenium webdriver program and before each method just include this annotation "@Test"

Now right click on the java program

Click on Run As

Select testNG Test

Here your program will run using testNG method. Your can see the tets report also.
by The go-to Tester (473 points)
2) Another method is using testng.xml file in which we create our suite of test cases which we want to execute.

Creating testng.xml File:

  First of all Create a project which indlude webdriver test cases and methods.

  To create testng.xml file, Right click on project folder and Go to New -> File

  In New file wizard, select "TestNGOne" project and add file                                    name ="testng.xml"

  click on Finish button

    It will add testng.xml file under your project folder. Now add bellow given lines in your testng.xml file.
    <suite name="Suite One" >
 <test name="Test One" >
  <classes>
   <class name="TestNGOnePack.ClassOne" />
  </classes>
 </test>
</suite>
Executing testng.xml File

To Run
Right click on testng.xml file -> Run As -> Select TestNG Suite


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...