Selenium Quickstart
Get up and running quickly with your first Selenium WebDriver automated test on the Sauce Labs cloud.
- Don't have Selenium tests, but want to try? Our examples below include sample project structures, Java tests, and working configuration specifications, so you can get up and running in less than 10 minutes using the instructions on this page!
- Already have Selenium tests to run? Take advantage of the Sauce Labs cloud to test on thousands of desktop and mobile browser/OS combinations and maximize your digital confidence.
The examples below are written in Java and run Selenium web tests on a Chrome browser. You can use a CLI terminal or an IDE, such as IntelliJ Community Edition or Visual Studio Code. IDEs incorporate all of the tools needed for developing and running code — text editor, terminal, debugging console, and more.
What You'll Need
- A Sauce Labs account (Log in or sign up for a free trial license).
- Your Sauce Labs Username and Access Key.
- Download Google Chrome.
- Have Git and GitHub set up.
Basic Selenium Test
This is a simple browser test that uses Selenium to navigate to our Sauce Labs demo site. The Selenium Quickstart Java Project contains all files and dependencies needed to execute a web app test.
Step 1: Clone Sample Project
- CLI
- VS Code
- IntelliJ
- Go to your machine's home directory.
cd ~
- Clone the Selenium Quickstart Java Project.
git clone https://github.com/saucelabs-training/quickstart-selenium-java.git
- Go to the project.
cd quickstart-selenium-java
- Open VS Code and click Clone Git Repository.
- Enter the Selenium Quickstart Java Project URL (https://github.com/saucelabs-training/quickstart-selenium-java.git) and click Clone from URL.
- Open IntelliJ and click Get from VCS.
- Enter the Selenium Quickstart Java Project URL (https://github.com/saucelabs-training/quickstart-selenium-java.git) and click Clone.
Step 2: Run Test
- CLI
- VS Code
- IntelliJ
Run the following code to execute your test.
mvn test
Right-click on the test file (SauceTest.java) and click Run Java.
Right-click on the test file (SauceTest.java) and click Run 'SauceTest'.
Step 3: View Test Results
- CLI
- VS Code
- IntelliJ
You should see a session confirmation message like this. Copy and paste the Test Job Link into your browser to see your test results on Sauce Labs.
Once you get to the Test Results page, click on your test to view its details.
You should see a session confirmation message like this. Click on the Test Job Link to see your test results on Sauce Labs.
Once you get to the Test Results page, click on your test to view its details.
You should see a session confirmation message like this. Click on the Test Job Link to go to your test results on Sauce Labs.
Once you get to the Test Results page, click on your test to view its details.
Selenium WebDriver Tests
In this Selenium test, you'll automate WebDriver to open and close a Chrome browser window. For this section, you'll need an IDE, such as IntelliJ or Visual Studio Code.
Step 1: Clone Project
- VS Code
- IntelliJ
- Open VS Code and click Clone Git Repository.
- Enter the Sauce Labs Advanced Selenium Training Project URL (https://github.com/saucelabs-training/advanced-selenium.git) and click Clone from URL.
- Open IntelliJ and click Get from VCS.
- Enter the Sauce Labs Advanced Selenium Training Project URL (https://github.com/saucelabs-training/advanced-selenium.git) and click Clone.
Step 2: Download Dependencies
This quickstart test utilizes the Java Development Kit (JDK) (download here), which is required to compile and execute Java code, and Selenium Java bindings (download here), which are required for Selenium-Java compatibility.
Step 3: Import Dependencies
If it's your first time ever opening a Java project, follow the steps below; if not, you can skip this.
- Your IDE will prompt you to set up your JDK. You'll need to click on the prompt.
- Provide the location where you downloaded the JDK. Some IDEs will detect and find the path for you, so all you have to do is select it.
If you're new to IDEs, here are some tips:
OpenJDK distributions

Extensions and plugins

Step 4: Run Test
Right-click and run the test file, SeleniumTest.java.
Step 5: View Test Results
You should see a Chrome browser window pop up and then quickly close. Your results will show a confirmation that ChromeDriver started successfully.
This concludes the test! If you're feeling ambitious, proceed to the next section to try out some additional common Selenium commands.
Extra Credit (Optional)
In this exercise, you'll be running the same SeleniumTest.java test, but with a few more actions this time. You'll automate WebDriver to open a Chrome browser window, navigate to our demo site, log in with a username and password, maximize the browser window, then close the browser window.
- Copy and paste the below code into the SeleniumTest.java test file, overwriting the previous test.
package com.saucelabs.advancedselenium.saucedemo.tests;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Hello {
public static void main(String[] args) {
// Lets WebDriverManager handle drivers
WebDriverManager.chromedriver().setup();
// Starts session (opens browser)
RemoteWebDriver driver = new ChromeDriver();
// Opens browser with desired URL
driver.get("https://www.saucedemo.com");
// Inputs standard_user in username field.
driver.findElement(By.id("user-name")).sendKeys("standard_user");
// Inputs secret_sauce in password field
driver.findElement(By.id("password")).sendKeys("secret_sauce");
// Clicks the Login button
driver.findElement(By.id("login-button")).click();
// maximizes browser window
driver.manage().window().maximize();
// Closes browser
driver.quit();
}
}
See Finder Methods to learn about locating id names and other webpage elements. 2. Save your changes. 3. Run revised test.
More Information
- Running Selenium on Sauce Labs: learn additional Selenium commands, strategies, and recommended best practices.
- Selenium on Sauce Labs: view Selenium snippets that use other browsers and programming languages
- Using Selenium 4 with Sauce Labs
- Viewing Your Test Results
- Sauce Training | W3C Code Examples
- Sauce Labs Language Bindings
- Java SE 8 Documentation