Parameterization And Parallel Execution Of The Script Using TestNG

Posted By : Kuldeep Sidana | 30-Jan-2018
  • Executing the scripts parallely using TestNG suite file is called Parallel Execution.
  • Executing the scripts with the multiple browsers is called cross browser testing.
  • To achieve cross browser testing we introduce parallel execution using TestNG.
  • Using TestNG theoretically we can execute five browser but practically we can execute three browsers parallely.

Code for Parallel Execution

 

/**

* 

* @author Kuldeep Sidana

*/

public class ParametrizationTest {

    public WebDriver driver ;

    @BeforeMethod

    @Parameters(value="browser")

    

    /**

     * @param browser

     */

    public void preCondition(String browser)

    {

        if(browser.equalsIgnoreCase("firefox"))

        {

            driver = new FirefoxDriver();

            Reporter.log("firefox launched",true);

        }

        else if (browser.equalsIgnoreCase("chrome"))

        {

            System.setProperty("webdriver.chrome.driver",".\\exefiles\\chromedriver.exe");

            driver =  new ChromeDriver();

            Reporter.log("chrome launched",true);

        }

        else if(browser.equalsIgnoreCase("IE"))

        {

            System.setProperty("webdriver.ie.driver",".\\exefiles\\chromedriver.exe");

            driver =  new InternetExplorerDriver();

            Reporter.log("IE launched",true);

        }

        else

        {

            driver = new FirefoxDriver();

            Reporter.log("IE launched",true);

        }


        driver.manage().window().maximize();

        driver.get("http://dev.kairosplanning.com");

        Reporter.log("Navigating to url", true);

 
        WaitStatementLib wLib = new WaitStatementLib();

        wLib.implicitWaitForSeconds(driver, 10);

        

    }

      @Test public void FBlogin() throws InterruptedException {

     

          driver.findElement(By.id("userName")).sendKeys("[email protected]");

            driver.findElement(By.id("password")).sendKeys("ulk@123");

            

           

            Thread.sleep(2000);

            driver.findElement(By.xpath("//input[contains(@value,'VERIFY')]")).click();

            System.out.println("login successfully");

            

        }  

     

      @AfterMethod
  public void afterTest() {

     

            driver.quit();

     

        }

     

    }
                
        

 

 
  • Parameter value is passed as an argument in suit file.

XML Suit File

               


 

  

   

     

   

  



  

   

     

   

  



  

   

     

   

  

 

        
 

 

 

About Author

Author Image
Kuldeep Sidana

Kuldeep Sidana is an orient QA Engineer having dexterity in Core Java and vouched with Automation Testing tool (Selenium Web Driver) and Manual Testing.

Request for Proposal

Name is required

Comment is required

Sending message..