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> 

2 comments:

  1. Hello,
    The Article on Parallel Execution In Selenium using Testing is amazing give detail information about it.Thanks for Sharing the information about it.It's amazing to know about Selenium Testing. Software Testing Services

    ReplyDelete
    Replies
    1. Thank You . Sure I will provide the detail.

      Delete

Copyright © 2017 QALEARNINGGUIDE.COM || ALL RIGHTS RESERVED