Parallel Execution In Selenium using TestNG


Program:

package Sample;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class ParallelExecutionDemo{
        @Test
        @Parameters("browserName")
// use @Parameters to pass the input through xml
        public void dummyTest(String browserName){
            WebDriver driver;
            if(browserName.equals("Firefox")){
                driver= new FirefoxDriver();
                driver.quit();
            }else if(browserName.equals("Chrome")){
                System.setProperty("webdriver.chrome.driver", "./Drivers/ChromeDriverServer.exe");
                driver = new ChromeDriver();
                driver.quit();
            }
     }
}


testng.xml

<suite name="Suite" parallel="tests" thread-count="2">
// parallel="tests" indicates here run both the test in parallel and thread-count="2" indicates execute two test cases parallel.
  <test name="Parallel1">
  <parameter name="browserName" value="Firefox" />
   <classes>
          <class name="Sample.ParallelExecutionDemo"/>    </classes>
  </test>
  <test name="Parallel2">
  <parameter name="browserName" value="Chrome" />
   <classes>
          <class name="Sample.ParallelExecutionDemo"/>
   </classes>
  </test>
</suite> 

Copyright © 2017 qatoolsguide.blogspot.com || ALL RIGHTS RESERVED