SDET- QA Automation Techie

Software Testing Blog

  • Home
  • Training
    • Online
    • Self-Paced
  • Video Tutorials
  • Interview Skills
    • HR Interview Questions Videos
    • Domain Knowledge
  • Career Guidance
  • Home
  • Software Testing
    • Manual Testing Tutorials
    • Manual Testing Project
    • Manaul Testing FAQS
    • ISTQB
    • AGILE
  • Web Automation Testing
    • Java Programmng
    • Python Programmng
    • Selenium with Java
    • Selenium with Python
    • Robot Framework(Selenium with Python)
    • selenium with Cucumber
    • TestNG+IntelliJ
    • Mobile App Testing(Appium)
    • JMeter
  • API Automation Testing
    • Rest Assured API Testing (BDD)
    • Rest Assured API Testing (Java+ TestNG)
    • Robot Framework(Rest API Testing with Python)
    • Postman
    • SoapUI
    • API Testing(FAQ's)
  • SDET|DevOps
    • Continuos Integration
    • SDET Essentials
    • AWS For Testers
    • Docker
  • SQL
    • Oracle(SQL)
    • MySQL for Testers
    • NoSQL
  • Unix/Linux
    • UNIX TUTORIALS
    • Linux Shell Scripting
  • ETL Testing
    • ETL Data warehouse Tutorial
    • ETL Concepts Tools and Templates
    • ETL Testing FAQ's
    • ETL Testing Videos
  • Big Data Hadoop
  • Video Tutorials
  • ApachePOI Video Tutorials
  • Downloads
    • E-Books for Professionals
    • Resumes
  • Automation Essencials
    • Cloud Technologies
      • Docker For Testers
      • AWS For Testers
      • Sub Child Category 3
    • Java Collections
    • Selenium Locators
    • Frequently Asked Java Programs
    • Frequently Asked Python Programs
    • Protractor
    • Cypress Web Automation

Configure parallel execution of tests using TestNG selenium

 Configure parallel execution of tests using TestNG selenium   

In testing, it is always important to test application in different browsers. We can perform automation on multiple browsers using selenium and testng. If there are more number of tests that need to be executed in parallel on different browsers also, we can do this using testng. And there is an other challenging task such executing tests in different browser versions and also different Operating systems. This can be achieved with Selenium Grid. 

We will look into the below examples in detail:
Below is the sample test which will only run one browser at a time and to run all the browsers in parallel, we need to add a parameter in testng.xml file which we will see below
package com.pack;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class ParallelTest {
private WebDriver driver;
String baseURL = "http://www.google.com/";
@Parameters({ "browser" })
@BeforeTest
public void openBrowser(String browser) {
try {
if (browser.equalsIgnoreCase("Firefox")) {
driver = new FirefoxDriver();
} else if (browser.equalsIgnoreCase("chrome")) {
System.setProperty("webdriver.chrome.driver",
"D:/chromedriver.exe");
driver = new ChromeDriver();
} else if (browser.equalsIgnoreCase("IE")) {
System.setProperty("webdriver.ie.driver",
"D:/IEDriverServer.exe");
driver = new InternetExplorerDriver();
}
} catch (WebDriverException e) {
System.out.println(e.getMessage());
} }
@Test
public void login_TestCase() {
driver.navigate().to(baseURL);
               //do something
}
@Test
public void search_TestCase() {
driver.navigate().to(baseURL);
             //do something
}
@AfterTest
public void closeBrowser() {
driver.quit();
}
}
In the above code, we have OpenBrowser method with BeforeTest annotation along with parameter 'browser'. In the xml we will define three tests tags to run each test with different browser. We will compare the browser value with the parameter value and based on that we will create the driver instance. We have now defined three tests with three browsers (Firefox, Google Chrome and Internet Explorer)
Below is the testng.xml file which will run all the tests which are defined. We are passing parameter value with browser name for each test. Tests will be executed in there browsers one by one.
="" http://testng.org/testng-1.0.dtd">
<suite name="Parallel test suite">
  <test name="Firefox Test">
  <parameter name="browser" value="Firefox"/>
    <classes>
      <class name="com.pack.ParallelTest"/>
    </classes>
  </test>
  <test name="Chrome Test">
  <parameter name="browser" value="chrome"/>
    <classes>
      <class name="com.pack.ParallelTest"/>
    </classes>
  </test>
    <test name="Internet Explorer Test">
    <parameter name="browser" value="IE"/>
    <classes>
      <class name="com.pack.ParallelTest"/>
    </classes>
  </test>
</suite>
We can also use TestNG to execute tests Simultaneously by defining the "parallel" attribute to "tests" to run all the tests in defined browser with the help of testng.xml configuration file.
<suite name="Parallel test suite" parallel="tests">
We just need to update the single line in above testng.xml. By defining parallel="tests" in suite tag, tests will get executed simultaneously. In order to execute to execute tests simultaneously it is recommended to have good system configuration, so that the execution time can be saved.
It looks like below:
="" http://testng.org/testng-1.0.dtd">
<suite name="Parallel test suite" parallel="tests">
  <test name="Firefox Test">
  <parameter name="browser" value="Firefox"/>
    <classes>
      <class name="com.pack.ParallelTest"/>
    </classes>
  </test>
  <test name="Chrome Test">
  <parameter name="browser" value="chrome"/>
    <classes>
      <class name="com.pack.ParallelTest"/>
    </classes>
  </test>
    <test name="Internet Explorer Test">
    <parameter name="browser" value="IE"/>
    <classes>
      <class name="com.pack.ParallelTest"/>
    </classes>
  </test>
</suite>
After executing you can view the report, which will look like below:
Multi browser tests

  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to TwitterShare to Facebook
Newer Post Older Post Home
popup

Popular Posts

  • How To Explain Project In Interview Freshers and Experienced
    “ Describe an important project you’ve worked on ” is one of the most common questions you can expect in an interview. The purpose of a...
  • MANUAL TESTING REAL TIME INTERVIEW QUESTIONS & ANSWERS
    1. How will you receive the project requirements? A. The finalized SRS will be placed in a project repository; we will access it fr...
  • API/Webservices Testing using RestAssured (Part 1)
    Rest Assured : Is an API designed for automating REST services/Rest API's Pre-Requisites Java Free videos: https://www.you...

Facebook Page

Pages

  • Home
  • Resumes
  • Job Websites India/UK/US
  • ISTQB
  • Selenium with Java
  • E-Books for Professionals
  • Manual Testing Tutorials
  • Agile Methodology
  • Manual Testing Projects

Live Traffic

YouTube


Blog Visitors

Copyright © SDET- QA Automation Techie | Powered by Blogger
Design by SDET | Blogger Theme by | Distributed By Gooyaabi Templates