Getting Started with Selenide: Java UI Testing Made Simple

Getting Started with Selenide: Java UI Testing Made Simple

Selenide is a Java framework built on top of Selenium WebDriver that removes the boilerplate. No more WebDriverWait, no manual driver downloads, no Thread.sleep() calls scattered through your tests. You write what the test should do, and Selenide handles the plumbing.

Why Selenide Over Raw Selenium

Raw Selenium gives you a low-level browser automation API. Selenide wraps it with:

  • Automatic waiting — every action retries until the element is ready or times out
  • Concise API$(selector).click() instead of driver.findElement(By.cssSelector(selector)).click()
  • Auto driver management — no chromedriver downloads or PATH configuration
  • Built-in assertionsshould(Condition.visible), shouldHave(text("Hello")) with readable failure messages

The result is tests that are shorter, more readable, and far less brittle.

Setup

Maven

Add to pom.xml:

<dependency>
    <groupId>com.codeborne</groupId>
    <artifactId>selenide</artifactId>
    <version>7.2.2</version>
    <scope>test</scope>
</dependency>

Gradle

testImplementation 'com.codeborne:selenide:7.2.2'

No additional WebDriver dependency needed. Selenide uses WebDriverManager under the hood to download and configure the correct driver binary automatically.

Your First Test

import com.codeborne.selenide.Selenide;
import org.junit.jupiter.api.Test;

import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.open;
import static com.codeborne.selenide.Condition.*;

public class LoginTest {

    @Test
    void userCanLogin() {
        open("https://example.com/login");

        $("#email").setValue("user@example.com");
        $("#password").setValue("secret");
        $("button[type=submit]").click();

        $(".dashboard-header").shouldBe(visible);
        $(".user-name").shouldHave(text("John Doe"));
    }
}

Run it with Maven:

mvn test

Selenide opens Chrome by default. No configuration needed for a first run.

Browser Configuration

Control the browser via Configuration class or system properties:

import com.codeborne.selenide.Configuration;

// Before tests run (e.g. in @BeforeAll)
Configuration.browser = "firefox";   // chrome, firefox, edge, safari
Configuration.headless = true;
Configuration.baseUrl = "https://staging.example.com";
Configuration.timeout = 6000;         // milliseconds, default 4000
Configuration.browserSize = "1920x1080";

Or via system properties when running Maven:

mvn test -Dselenide.browser=firefox -Dselenide.headless=true

Selectors

Selenide accepts any Selenium By locator plus CSS shorthand:

// CSS (most common)
$("input[name=email]")
$(".submit-btn")
$("#user-profile")

// By text content
$x("//button[text()='Submit']")       // XPath
$(byText("Submit"))                    // exact text
$(withText("Subm"))                    // partial text

// By attribute
$(byAttribute("data-testid", "login-btn"))

// nth element
$$(".item").get(2)                     // zero-indexed
$$(".item").first()
$$(".item").last()

The $ method returns a SelenideElement. The $$ method returns ElementsCollection for working with multiple elements.

Automatic Waiting

Every interaction waits automatically. Selenide polls the DOM until the condition is met or the timeout expires:

// These all wait automatically:
$(".loading-spinner").shouldNotBe(visible);   // waits for spinner to disappear
$(".result-count").shouldHave(text("42"));    // waits for text to appear
$("form").shouldBe(enabled);                  // waits until form is not disabled

Default timeout is 4 seconds. Override globally via Configuration.timeout or per-assertion:

$(".slow-element").shouldBe(visible, Duration.ofSeconds(15));

Taking Screenshots

Selenide takes screenshots automatically on test failure. They land in build/reports/tests/ (Maven) or target/ depending on your build tool.

Take manual screenshots:

import static com.codeborne.selenide.Selenide.screenshot;

String path = screenshot("my-test-state");

Running Headless in CI

mvn test -Dselenide.headless=true -Dselenide.browser=chrome

Most CI environments (GitHub Actions, GitLab CI, Jenkins) have Chrome available. Add the actions/setup-java step and Selenide handles the rest.

What's Next

This covers the basics. For production test suites you'll want to understand Selenide's fluent assertion API in depth, how to structure page objects, and how to run tests in parallel — all covered in the follow-up guides.

Read more

Start now free