liveBook · Manning

Selenium

As explained in Testing Spring Boot Applications

Selenium is a suite of tools and APIs for automating web browsers and testing web applications through browser interactions.

Selenium provides APIs and tooling for automating a real web browser and testing web applications through browser interactions. It works with WebDriver, which exposes a standard HTTP interface for sending commands to browser-specific drivers and reading browser state. Unlike HtmlUnit, Selenium handles modern JavaScript well, but requires a network-accessible test application, a running web server, and a full browser. section 4.5 section 4.6

A Spring Boot Selenium test commonly starts the application with @SpringBootTest(webEnvironment = RANDOM_PORT), creates a browser driver in @BeforeAll, and shuts it down in @AfterAll. Reusing one browser avoids startup cost but shares cookies and other local state across tests; delete cookies explicitly when isolation requires it. ChromeDriverService is replaceable with services for Firefox, Edge, or Safari, while Selenium can discover matching browser and driver executables or accept explicit paths. section 4.5.1

Testing an auto-complete field

Navigate to the application using the random port, locate the city search field with By.id("citySearch"), and send "jak" with sendKeys(). Locate the result container, collect child elements with a CSS selector, and assert the displayed cities and their order. An implicit wait lets Selenium retry element lookup for up to one second while the JavaScript-driven results appear. section 4.5.2

Listing 4.20 Selenium testing dependencies
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <scope>test</scope>
</dependency>

Use the dependency declaration as the minimal Maven starting point for adding Selenium to test scope. section 4.5

Prefer Selenium when HTML or JavaScript behavior needs a real browser, especially for JavaScript-heavy applications. Use lighter mock-stack or client-based approaches for most API tests, and reserve Selenium for the browser capabilities those approaches cannot represent. section 4.6

How Testing Spring Boot Applications covers it

How deep it goes
Explains WebDriver, lifecycle setup, browser discovery, waits, selectors, interactions, and assertions, but not driver protocol internals.
Examples
Uses a headless Chrome setup and an auto-complete search test that checks three dynamically displayed cities.
What it assumes
Assumes a network-accessible test application, running web server, installed browser, matching driver, and basic JUnit and Spring Boot testing.
What you can do after
Apply it via Selenium WebDriver to exercise browser interactions and verify JavaScript-driven web behavior.
How it connects
Connects Selenium with WebDriver, Spring Boot, JUnit, HtmlUnit, MockMvcTester, RestTestClient, and WebTestClient.

Also explained in

Compare how 3 books explain Selenium →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Testing Spring Boot Applications. The section links point to the parts of the book it draws on.