testbench
testbench copied to clipboard
first() is fundamentally broken
The expression $(ButtonWrapper.class).first()
should fundamentally not be used in a test: it promotes creation of flaky tests. If there are multiple Buttons on the web page, TestBench selects an arbitrary one and then the test may (or may not) fail later on, after the button is clicked and the outcome is something else than the test intended.
Instead, there should be a get()
function which asserts that there's exactly one Button, failing if there are multiple matching Buttons. That's exactly what Playwright is doing: at https://playwright.dev/java/docs/writing-tests the page.getByRole(xyz)
will fail if there are multiple matching elements.
first()
should be deprecated and replaced by get()
(which selects one), or get(int)
which returns a list of elements and asserts that it's of that particular size.