Showing posts with label How to execute the testcases parallely in TestNG. Show all posts
Showing posts with label How to execute the testcases parallely in TestNG. Show all posts

Thursday, June 19, 2014

How to execute single testcase in two different browsers parallel in single machine using TestNG.

Sample Test Case

package hello;

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 ParallelExecution {
        @Test
        @Parameters("browserType")  // use @Parameters to pass the input through xml
        public void dummyTest(String browserType){
            WebDriver driver;
            if(browserType.equals("FF")){
                driver= new FirefoxDriver();
                driver.quit();
            }else if(browserType.equals("IE")){
                System.setProperty("webdriver.ie.driver", "./Drivers/IEDriverServer.exe");
                driver = new InternetExplorerDriver();
                driver.quit();
            }
     }
}


testng.xml

<suite name="Suite" parallel="tests" thread-count="2"> //here parallel="tests" means run both the test in parallel and thread-count="2" means run two test cases parallel. 
  <test name="Test1">
  <parameter name="browserType" value="FF" />  //to pass the input to the java class
   <classes>
          <class name="hello.ParallelExecution"/>   //here hello is package name and ParallelExecution is class name
   </classes>
  </test>
  <test name="Test2">
  <parameter name="browserType" value="IE" />
   <classes>
          <class name="hello.ParallelExecution"/> //here hello is package name and ParallelExecution is class name
   </classes>
  </test>
</suite> 

Wednesday, May 14, 2014

How to execute the testcases parallely in TestNG

Test cases can be run parallel by updating testng.xml.

ex- Here two browsers will open as thread-count = "2" (you can change it according to your requirement). In one browser all the classes will be executed which are under 1st test and in 2nd browser, all the classes will be executed which are under 2nd test.

<suite name="Suite" parallel="tests" thread-count="2">
  <test name="Test1">
    <classes>
      <class name="Library.Module1"/>
    </classes>
  </test>
  <test name="Test2">
    <classes>
      <class name="Library.Module2"/>
    </classes>
  </test>
</suite>


Go back to Interview Ques-Ans for Automation Tester

Go to Example with Real Scenario