It brings the Testing Library selectors as Selenium locators. Why? When I use Selenium, I want to be independent of 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.
Use the library's latest version:
implementation("com.luissoares:selenium-testing-library:4.1")These are just a few examples. Check the tests that illustrate all the usages (there are examples in Java).
The core API contains the selectors which are mapped into Selenium locators:
driver.findElements(altText("first name"))
driver.findElement(displayValue("c => c.startsWith('selen')".asJsExpression()))
driver.findElements(labelText("active"))
driver.findElements(placeholderText("first name", exact = false))
driver.findElements(role(Heading, nameAsFunction = "c => c.startsWith('something')".asJsExpression()))
driver.findElements(role(Button, nameAsRegex = Pattern.compile("confirm")))
driver.findElements(testId("test-id"))
driver.findElements(text("present", exact = false, selector = "span"))
driver.findElement(title("title 1"))
driver.findElement(title(Pattern.compile("FOO")))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(letterSelector, driver.findElement(ByRole(ListBox, name = "C")))fireEvent is also available:
input.fireEvent(Change, mapOf(Target to mapOf("value" to "2020-05-24")))jest-dom matchers are available with a similar API, although it makes more sense to use the corresponding utilities and assert with JUnit (or an assertion library):
// API similar to the original version:
expect(button.toHaveAccessibleDescription("Register"))
expect(checkboxMarketing).toBeChecked()
assertEquals(setOf("btn", "btn-danger", "extra"), deleteButton.classes)
expect(element).not.toBePartiallyChecked()
// utilities that can be used on their own:
val formValues = registrationForm.formValues
val userAgrees = checkboxMarketing.isChecked
val name = element.accessibleName
val displayedValue = element.displayValueℹ️ Read more.