top of page
Search

How to run Selenium tests in SauceLabs

  • Writer: Dev Raj Sinha
    Dev Raj Sinha
  • Nov 3, 2023
  • 2 min read

Running Selenium tests on Sauce Labs involves configuring your tests to use Sauce Labs as the Selenium Grid. Here's a step-by-step guide to running Selenium tests on Sauce Labs:


Prerequisites:


1. Sauce Labs Account: You need a Sauce Labs account. If you don't have one, you can sign up for a free trial on their website.

2. Selenium WebDriver Tests: You should have your Selenium WebDriver tests ready.


Step 1: Update Your WebDriver Configuration


Update your WebDriver configuration to use Sauce Labs as the remote WebDriver grid. You will need to set the `remote` URL, desired capabilities, and authentication details (username and access key).


Example for Java (using TestNG):


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.net.URL;

public class SauceLabsExample {

    private WebDriver driver;

    @BeforeMethod
    public void setUp() throws Exception {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("username", "your_sauce_labs_username");
        capabilities.setCapability("accessKey", "your_sauce_labs_access_key");
        capabilities.setCapability("browserName", "chrome"); // or "firefox", "safari", etc.
        capabilities.setCapability("platform", "Windows 10"); // or "macOS 10.15", "Linux", etc.

        driver = new RemoteWebDriver(new URL("https://ondemand.saucelabs.com:443/wd/hub"), capabilities);
    }

    @Test
    public void testExample() {
        driver.get("https://www.example.com");
        // Your test code here
    }

    @AfterMethod
    public void tearDown() {
        if (driver != null) {
            driver.quit();
        }
    }
}

Step 2: Run Your Tests


After updating your test code, you can run your tests. If you are using TestNG, you can use the TestNG XML file or run the tests directly from your IDE.


Step 3: View Test Results in Sauce Labs Dashboard


Once your tests are executed, you can view the results, screenshots, and other details on the Sauce Labs dashboard.


Remember to replace `"your_sauce_labs_username"` and `"your_sauce_labs_access_key"` with your actual Sauce Labs credentials.


Please note that Sauce Labs provides various options for configuring your tests, including different operating systems, browsers, and versions. Make sure to customize your desired capabilities based on your testing requirements. You can find more information on Sauce Labs' official documentation and their platform configurator tool.

 
 
 

Recent Posts

See All

Comentarios


Never Miss a Post. Subscribe Now!

Find new exciting ways to dominate the IT Automation industry

Thanks for submitting!

bottom of page