Thursday, January 9, 2014

Creating testng.xml to Run Test Suite

The main advantage of using TestNG framework in Selenium is its ease of running multiple tests from multiple classes using just one configuration (We can also have many configurations, which depends upon how we design our test). Testng.xml is an XML file that describes the runtime definition of a test suite. It describes complex test definition while still remain easy to edit.
Using Testng.xml file we can run test available in one or more class file and make them as a single group, hence making test more meaningful, we call them as scenario based testing.
Can I run test without using testng.xml file?
Well answer is yes, you can run. But once your test become larger and requires configuration of multiple test at one place, the best option is testng.xml.
The testng.xml file will have following hierarchy
  • The root tag of this file is .
  • tag can contain one or more tags.
  • tag can contain one or more tags.
  • tag can contain one or more tags.
  • For more information on Tags and other tags that you can use in your XML file, check out the details here
    Your xml file with just one test in a one class file will look something like this.

    As you could see above, the Class name has Test.NewTest, which is nothing but the “Fully qualified” name of the Class. It means NewTest is the class file which is available under package Test.
    Now your  Eclipse IDE should look something like this.

    I have added the testng.xml file in our project, so that we can use it for running test.

    Try Running Test using Testng.xml

    Just right click on the testng.xml file in package explorer of Eclipse and select Run As Testng Suite, the test will run .

    if you want to pass parameters create xml file like this:



My .java test file looks like this:
public class Gmail
{
public WebDriver driver;

 
 
@Test
@Parameters({"Urlsite"})
public void GmailAccess(String value) 
{
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
try{
driver.get(value);
driver.close();

No comments:

Post a Comment