LambdaTest Community

Find answers, support, and inspiration from other users

Questions
LambdaTest Community
Answered

How can I run parallel tests with Gauge?

Can anyone please tell me how can I run parallel tests with Gauge.

Up Vote Down Vote 0 Votes
Posted 4 months ago

Answers


Gauge is a free open source test automation framework released by creators of Selenium, ThoughtWorks. Test automation with Gauge framework is used to create readable and maintainable tests with

languages of your choice. Users who are looking for integrating continuous testing pipeline into their CI-CD(Continuous Integration and Continuous Delivery) process for supporting faster release cycles. Gauge framework is gaining the popularity as a great test automation framework for performing cross browser testing.

This article would help you understand the benefits of using Gauge test automation framework, installing and running your first automation script for test automation with Gauge test automation framework. I will also show you how to use LambdaTest Selenium grid for executing your automation script for test automation with Gauge test automation framework to perform extensive, automated browser compatibility testing with Gauge on cloud. Here we go!

Why Choose Gauge For Cross Browser Testing Out Of Other Test Automation Frameworks?

Now, that we are aware of the basics regarding the Gauge framework and cross browser testing. Let me tell you why I prefer to perform test automation with Gauge test automation framework over other test automation frameworks.

  1. Wide range of templates are available in a language of your choice to have an easy kick start to the project.
  2. Command Line support which makes the integration easier with CI-CD tools.
  3. Test automation with Gauge framework supports all major programming languages along with GoLang.
  4. It supports wide variety of plugins, here is a list of all plugin categories available.

a. Language Runners: Java runner, C# runner, C# runner(.Net Core), Ruby runner, Javascript runner, Golang runner and Python runner. b. IDE Plugins: Visual Studio Code, IntelliJ and Visual Studio. c. Reports: HTML Report, XML Report, JSON Report, Spectacle and Flash. d. Build Management: Maven and Gradle You can even create your own plugin using their open source Gauge API. 5. Quickly detect issues through screenshots of event failures and multiple reporting formats available instead of navigating through stack traces. 6. Allows you to create scalable tests through parallel execution and being an open-source it offers integrations with cloud-based solutions like LambdaTest for addressing the cross browser testing goals. 7. Better management of data sets through data driven testing with multiple data sets is possible while keeping specifications highly readable. 8. Easy to write effective test cases by members across the team. 9. Automated cross browser testing made easy. 10. Scalability of product requirements across the QA, Dev and Business teams. Running First Automation Script Using Gauge Framework With Selenium Grid

Step 1: Create a specification file for searching a keyword in google and if results are displayed as expected.

Specification heading in the specs file would be denoted with ‘#’ notation as defined in our project. Example: #Google Search Specification

Scenario would be defined using ‘##’ notation, quoting an example below for reference. Example: ## Searching google should return the name of the query.

Steps would be defined using ‘*’ notation. Example: * Navigate to “https://www.google.co.in“. Spec file create for Google search is as below:

Google Search Specification

Searching google should return the name of query

  • Navigate to “https://www.google.co.in”
  • Enter query “query” in the search box and submit
  • The search results should show “LambdaTest” as a result

Step 2: Create a step implementation file, with below-mentioned code to define acceptance tests as defined in specification files.

package com.thoughtworks.gauge.maven;
 
import com.thoughtworks.gauge.Step;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import static org.junit.Assert.assertEquals;
 
public class StepImplementation {
 
    public static WebDriver driver;
 
    @Step("Navigate to <https://www.google.co.in>")
    public void navigateTo(String url) throws InterruptedException {
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\Dexy\\IdeaProjects\\GaugeSampleProject\\libs\\chromedriver.exe");
        driver = new ChromeDriver();
        driver.get(url);
        Thread.sleep(2000);
    }
 
    @Step("Enter query <query> in the search box and submit")
    public void enterQuery(String queryL) throws InterruptedException {
        WebElement searchBox = driver.findElement(By.name("q"));
        searchBox.sendKeys("LambdaTest");
        searchBox.submit();
        Thread.sleep(2000);
    }
 
    @Step("The search results should show <Jupiter> as result")
    public void verifySearchResult(String resultString) {
        WebElement result = driver.findElement(By.className("LC20lb"));
        assertEquals(resultString, result.getText());
    }
}

Step 3: Execute the test case from the specification file created. Right click on the file and select option as shown in the image below. Browser specification could be provided in env folder’s default.properties file as

#Browser Usage BROWSER = CHROME

We can provide maven command to execute with conditions as below.

To execute mvn gauge:execute To execute all specs: mvn gauge:execute -DspecsDir=specs For parallel execution: mvn gauge:execute -DspecsDir=specs -DinParallel=true Node specification during parallel execution: mvn gauge:execute -DspecsDir=specs -DinParallel=true -Dnodes=2

Step 4: Once execution has been successfully completed you can verify the status of the test in the terminal.

Reports generated can be viewed in reports folder – ‘GaugeSampleProject\reports\html-report’

I would be providing the link to GitHub repository for code references below.

bharadwaj-pendyala/Gauge_Framework

With the above step being done, we have successfully completed installation of Gauge for test automation, creating our first script and running it. Now let’s jump into some of the advanced concepts and values adds which could decrease our execution time drastically for faster releases.

Cross Browser Testing with Parallel Execution using Gauge Framework

Problem Statement: When it comes to cross browser testing there are more than 6 active browsers usage and each browser having more than 4 to 5 version of it in use aggressively.

Case Study Depiction: Let’s consider a case study where we have a regression test repository consisting of 1000 test cases to validate per release. When we consider cross browser testing effort, a calculated effort would be around 1000 test cases* 6 browsers * 5 versions each = 30,000 Test Cases.

Solution:

  1. Local Execution using Selenium-Grid: You would end up executing 30,000 test cases in total. Manually handling the effort would be impossible. Parallelly executing the test cases using Selenium Grid might decrease the effort, however, scalability would be an issue, you can’t execute more than 10-20 instances on your local machine depending on the physical memory and the number of cores CPU has. Also, installing thousands of browsers in a system would be very infeasible.

  2. Cloud Execution using LambdaTest: Utilizing cloud resources of LambdaTest would drastically cut down the effort as scalability wouldn’t be an issue. LambdaTest Selenium Automation Grid for Gauge empowers you to perform end-to-end automation tests on a secure, reliable, and scalable Selenium grid on their cloud platform. You can perform automated cross browser testing with Selenium scripts on 2000+ browsers and operating systems environments providing a higher test coverage and at significantly fewer build times. LambdaTest will help you evaluate how well your web application renders when accessed through a variety of different browser. You can perform automated cross browser testing of your locally hosted web pages using Lambda Tunnel. You could also perform automated parallel test to run a single test across multiple browser/OS configurations, simultaneously. Configuring Our Current Gauge Framework For Test Automation With LambdaTest

Step 1: Create an account for free on LambdaTest to start cross browser testing with parallel execution. For a free account, only 1 concurrent user is available, as more than 1 VM’s need account upgrade. Feel free to look at their pricing plans over here:

https://accounts.lambdatest.com/...

Step 2: Navigate to “Selenium Desiredcapabilities Generator” tool by LambdaTest at Selenium Desired Capabilities To Run Automated Tests | LambdaTest as shown in image below.

Step 3: Select the required programming language and operating system and browser configuration as per the requirement, you can enable screenshots and video recording as well. You have a feature of enabling advance configuration as well, which lets you define tunnel, console and network logs and time zone selections.

Step 4: Copy the code and define the capabilities for remote webdriver in your Step Implementation file. Code for the same as specified below.

package com.thoughtworks.gauge.maven;
 
import com.thoughtworks.gauge.Step;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.MalformedURLException;
import java.net.URL;
import static org.junit.Assert.assertEquals;
 
public class StepImplementation {
 
    String username = " YOUR_USERNAME";
    String accesskey = " YOUR_ACCESS_KEY";
    static RemoteWebDriver driver = null;
    String gridURL = "@hub.lambdatest.com/wd/hub";
    boolean status = false;
 
    @Step("Navigate to <https://www.google.co.in>")
    public void navigateTo(String url) throws InterruptedException {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("build", "your build name");
        capabilities.setCapability("name", "your test name");
        capabilities.setCapability("platform", "Windows 10");
        capabilities.setCapability("browserName", "Chrome");
        capabilities.setCapability("version", "71.0");
        capabilities.setCapability("visual", true);
        try {
            driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
        } catch (MalformedURLException e) {
            System.out.println("Invalid grid URL");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        driver.get(url);
        Thread.sleep(2000);
    }
 
    @Step("Enter query <query> in the search box and submit")
    public void enterQuery(String query) throws InterruptedException {
        WebElement searchBox = driver.findElement(By.name("q"));
        searchBox.sendKeys("LambdaTest");
        searchBox.submit();
        Thread.sleep(2000);
    }
 
    @Step("The search results should show <Jupiter> as result")
    public void verifySearchResult(String resultString) {
        WebElement result = driver.findElement(By.className("LC20lb"));
        assertEquals(resultString, result.getText());
    }
 
}
Up Vote Down Vote 0 Votes
Posted 3 months ago