Selenium Testing Library
Testing Library selectors available as Selenium locators for Kotlin/Java.
Why? When I use Selenium, I don't want to depend on ids, classes, and similar. I'm a fan of the Testing Library because it encourages "testing as a user":
The more your tests resemble the way your software is used, the more confidence they can give you.
These are just a few examples. There are unit tests that illustrate all the usages.
Core API
The core API contains the selectors which are mapped into Selenium locators:
driver.findElements(ByAltText("first name"))
driver.findElements(ByDisplayValue("/john/i", matchTextBy = REGEX))
val active = driver.findElements(ByLabelText("active"))
val input = driver.findElements(ByPlaceholderText("first name", exact = false))
val firstName = input.text
driver.findElements(ByRole("heading", name = "/as a user/i", matchTextBy = REGEX))
val panel = driver.findElements(ByTestId("test-id"))
panel.click()
driver.findElements(ByText("present", exact = false, selector = "span"))
driver.findElements(ByTitle("title 1"))
An alternative API that does not use Selenium locators:
val result1 = driver.queryBy(AltText, "alt 1", mapOf("exact" to false))
val result2 = driver.getBy(DisplayValue, "incredibles")
val result3 = driver.queryAllBy(LabelText, "label x")
val result4 = driver.getAllBy(Role, "listbox")
User Interactions
The Testing Library's user-event is also mapped:
driver.user.click(active)
driver.user.dblClick(panel)
driver.user.type(input, "foobar")
driver.user.selectOptions(driver.findElement(ByRole("listbox")), "C")