From 68bf26924979132de9ac5f8f6c98c24b4fccb9e4 Mon Sep 17 00:00:00 2001 From: Mohammad Saddam Hossain Date: Thu, 27 Aug 2026 07:28:28 +0530 Subject: [PATCH] test(sample): make the first test people read show the locator API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SampleTest is the file a newcomer opens first, and it was two identical copies of getDriver().get("https://google.com"); assertEquals(getDriver().getTitle(), "Google"); plus a block of commented-out dead code. It ignored baseUrl and open(), navigated off the demo app to a site that blocks automation, and demonstrated nothing the framework does. The shop window showed the opposite of the pitch — while LocatorApiDemoTest and SemanticLocatorDemoTest, which do show it, sit deeper in the tree where nobody looks first. Now: two tests against the demo app using getByLabel, getByRole, getByTestId and web-first assertions, with a class comment stating exactly what is absent (driver setup, WebDriverWait, CSS/XPath) and pointing at LocatorApiDemoTest for the rest. Verified: 2/2 green against panjatan.netlify.app in real Chrome via xvfb, and the surrounding suite stayed green (11/11 in the same run). Co-Authored-By: Claude Opus 5 (1M context) --- src/test/java/com/saddy/tests/SampleTest.java | 50 ++++++++++++------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/src/test/java/com/saddy/tests/SampleTest.java b/src/test/java/com/saddy/tests/SampleTest.java index 9fe5270..a8ccde3 100644 --- a/src/test/java/com/saddy/tests/SampleTest.java +++ b/src/test/java/com/saddy/tests/SampleTest.java @@ -1,29 +1,41 @@ package com.saddy.tests; -import com.seleniumboot.listeners.Retryable; +import com.seleniumboot.locator.Role; import com.seleniumboot.test.BaseTest; import org.testng.annotations.Test; -import static org.testng.Assert.assertEquals; - +/** + * The first test most people read. It is deliberately the smallest useful example of + * what Selenium Boot actually gives you over plain Selenium: + * + * + * + *

Raw Selenium is never hidden: {@code getDriver()} is always there when you need it. + * See {@code LocatorApiDemoTest} for the full locator surface. + */ public class SampleTest extends BaseTest { - @Test - public void testSampleDemo() { - getDriver().get("https://google.com"); - assertEquals(getDriver().getTitle(), "Google"); - } - @Test - public void testScreenshotOnFailure() { - getDriver().get("https://google.com"); - assertEquals(getDriver().getTitle(), "Google"); + @Test(description = "Find and fill a form without a single CSS selector") + public void signsInUsingAccessibleLocators() { + open(); + + getByLabel("Username").type("admin"); + getByLabel("Password").type("password"); + + assertThat(getByLabel("Username")).hasValue("admin"); + assertThat(getByRole(Role.BUTTON, "Login")).isVisible(); } -// @Retryable -// @Test(description = "This is a flaky Test") -// public void flakyTest() { -// if (Math.random() < 0.7) { -// throw new RuntimeException("Random failure"); -// } -// } + @Test(description = "Locate by test id — survives any CSS or DOM refactor") + public void findsElementsByTestId() { + open(); + + assertThat(getByTestId("login-submit-btn")).isVisible(); + assertThat(getByTestId("remember-checkbox")).isVisible(); + } }