Saturday, January 25, 2014

How to use TestNG with Selenium WebDriver

(The precondition for this tutorial that the Selenium WebDriver is already installed.)
Firstly go to TestNG website’s download page, and follow the instructions to install the TestNG plugin to Eclipse. (http://testng.org/doc/download.html)
After the TestNG was installed, create a new java class file (without main method).
Create the setUp() function. To this function you can put that the WebDriver use for example the Firefox browser, and for example that the driver get the desired webpage.
This function will start before the test. To ensure that, before the setUp() function need to put @BeforeClass annotation.
@BeforeClass: The annotated method will be run before the first test method in the current class is invoked.
If you use only one test in the java file then you can use the @BeforeTest annotation too.
@BeforeTest: The annotated method will be run before any test method belonging to the classes inside the <test> tag is run.

No comments:

Post a Comment