Thursday, 24 July 2014

Selenium WebDriver and TestNG: Running script in different browsers |Invoke different browsers

In this post will cover how to run a selenium script in different browsers.
To do so we will use TestNG and @Parameters annotation. Using TestNG we can directly pass parameter to test methods from testng.xml.  Below example makes it more clear

Prerequisites:


Java

  • Create a java class name BrowserContoller.java in your workspace.
  • Create a method setBrowser(String browser) to your class. This method takes a String as input parameter.
  • Add the annotation @Parameters ("browser") to this method. Value to the parameter will be passed from xml.

TestNG

  • Create a simple tesng.xml name say BrowserControllerTestng.xml
  • Define Test name, parameter and its value (firefox, chrome,  iexplore ) and class name.


No comments:

Post a Comment