Skip to main content
No Result Found

Automated tests on Gauge

Quick start guide to integrate Automated tests on BrowserStack Accessibility Testing with Gauge.

Prerequisites

  • You have an account with BrowserStack (even a free trial works) and can get the username and access key from Account & Profile.
  • Gauge should be installed and in $PATH. The latest version of Gauge can be downloaded from the website.
  • You have a pre-existing Gauge test suite integrated with BrowserStack Automate.
  • Maven is installed on your machine, its environment variables are set, and its bin is added to the system path, $PATH.
  • Gauge-maven-plugin to execute specs and manage dependencies using Maven.

Integrate with Automated tests on BrowserStack Accessibility Testing

Follow these steps to get started with adding Automated tests to your test suite:

The minimum version of browserstack-java-sdk that supports Automated tests is 1.13.10.

Install or update to the latest BrowserStack Java SDK

If you already use browserstack-java-sdk, update the entry enclosed within the <version> - </version> tags as LATEST in the pom.xml file of your project and run the following command to update to the latest SDK version.

Terminal
Copy icon Copy
mvn install


If you don’t have browserstack-java-sdk installed already, run the following command on your terminal/command prompt to add browserstack-java-sdk dependency and browserstack.yml file in your project.

mvn archetype:generate -B -DarchetypeGroupId=com.browserstack \
-DarchetypeArtifactId=testng-archetype-integrate -DarchetypeVersion=1.2 \
-DgroupId=com.browserstack -DartifactId=testng-archetype-integrate -Dversion=1.2 \
-DBROWSERSTACK_USERNAME=YOUR_USERNAME -DBROWSERSTACK_ACCESS_KEY=YOUR_ACCESS_KEY

mvn archetype:generate -B -DarchetypeGroupId=com.browserstack -DarchetypeArtifactId=testng-archetype-integrate -DarchetypeVersion=1.2 -DgroupId=com.browserstack -DartifactId=testng-archetype-integrate -Dversion=1.2 -DBROWSERSTACK_USERNAME=YOUR_USERNAME -DBROWSERSTACK_ACCESS_KEY=YOUR_ACCESS_KEY

Create the specs files and update platform details

To integrate your test with BrowserStack Automated tests, you need to create a file DriveFactory.java and call it from your Gauge test case. In the following example, the DriveFactory.java file is called from a sample test script SearchSpec.java. Similarly, you need to call it from your test script.

SearchSpec.java
Copy icon Copy
package com.browserstack.gauge.pages;
import static org.junit.Assert.assertEquals;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import com.thoughtworks.gauge.Step;
public class SearchSpec {
    private final WebDriver driver;
    private WebElement element;
    public SearchSpec() {
        this.driver = DriverFactory.getDriver();
    }
    @Step("On the homepage")
    public void navigateToHomePage() {
        driver.get("https://www.google.com");
    }
    @Step("Search for term <term>")
    public void searchFor(String term) {
        element = driver.findElement(By.name("q"));
        element.sendKeys(term);
        element.submit();
    }
    @Step("Make sure the page title is <term>")
    public void checkPageTitle(String term) {
        assertEquals(term, driver.getTitle());
    }
}
DriverFactory.java
Copy icon Copy
package com.browserstack.gauge.pages;
import com.thoughtworks.gauge.AfterSpec;
import com.thoughtworks.gauge.BeforeSpec;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
public class DriverFactory {
    private static final String USERNAME = System.getenv("BROWSERSTACK_USERNAME");
    private static final String AUTOMATE_KEY = System.getenv("BROWSERSTACK_ACCESS_KEY");
    private static final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";
    private static WebDriver driver;
    public static WebDriver getDriver() {
        return driver;
    }
    @BeforeSpec
    public void setUp() {
        try {
            DesiredCapabilities caps = new DesiredCapabilities();
            // Capabilities from environment
            caps.setCapability("browser", System.getenv("BROWSER"));
            caps.setCapability("browser_version", System.getenv("BROWSER_VERSION"));
            caps.setCapability("name", "Bstack-[Gauge] Sample Test");
            caps.setCapability("build", System.getenv("BUILD"));
            caps.setCapability("os", System.getenv("OS"));
            caps.setCapability("os_version", System.getenv("OS_VERSION"));
            // Hardcoded capabilities
            caps.setCapability("browserstack.debug", "true");
            URL remoteURL = new URL(URL);
            driver = new RemoteWebDriver(remoteURL, caps);
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        } catch (MalformedURLException e) {
            System.out.println(e.toString());
        }
    }
    @AfterSpec
    public void tearDown() {
        driver.close();
        driver.quit();
    }
}


Modify the DriverFactory.java file to provide the platform details that you want to run your tests under. Note that Accessibility testing will only run on Desktops (Mac & Windows) with Chrome 95 & above on Automate.

Separate builds are created on the Accessibility dashboard for each device-browser-os combination in Gauge tests. This is different from other frameworks where multiple platforms are listed under the Platforms tab on the Accessibility dashboard.

Modify your browserStack.yml config file

Automated tests mandatorily needs the following configurations in the browserstack.yml file. Especially, ensure to set the accessibility flag as true at the end of the browserstack.yml file.

The projectName and buildName config must be static and not change across different runs of the same build. This is a deviation in approach as specified by BrowserStack Automate since Automated tests will automatically identify different build runs.

browserstack.yml
Copy icon Copy
userName: YOUR_USERNAME
accessKey: YOUR_ACCESS_KEY
framework: gauge
buildName: "Your static build/job name of CI goes here"
projectName: "Your static project name goes here"
...
browserstacklocal: false
browserstackautomation: false
accessibility: true
  • The OSs, devices, and browsers defined on the browserstack.yml file do not affect cross-browser testing for the Gauge framework. Instead, the platform details are obtained from what is defined in the DriverFactory.java file.

  • Accessibility testing runs only on Desktops (Mac & Windows) with Chrome 100 & above on Automate.

  • Window handle commands might cause instability to Automated Tests. If you face issues, consider removing window handle commands or contact support.

Run your test suite with Automated tests

Run the following command from the project’s root directory to run your test suite with BrowserStack.

Copy icon Copy
mvn test -P sample-test

You can check the Accessibility report for your build through the Automated tests page.



Visit Automated tests page

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle