Skip to content

assertSee() / assertSeeIn() doesn't support selectors to multiple elements  #1150

Open
@flap152

Description

@flap152

Dusk Version

8

Laravel Version

11.34

PHP Version

8.3

PHPUnit Version

11

Database Driver & Version

No response

Description

The current implementation of assertSee() / assertSeeIn() / assertDontSee / assertDontSeeIn() support selectors to multiple elements but assume only one element is selected while there are valid/legitimate selector that returns multiple elements.
For example, the content of the first column in a dataTable, ignoring content in other columns: #crudTable > tbody > tr > td:nth-child(1) > span.

I find only the first element is considered and assert on it if it exists.
The asserts do not provide feedback when multiple elements are returned and will be right or wrong depending if the target text is present in the first or in other elements.

After making a macro for additional asserts methods, I found the existing code could be extended to manage these cases relatively easily.

The contribution guide says a "draft" PR will not be reviewed, but I seek opinions on choices available in implementing the changes, I will link to my fork of dusk, or will a Draft PR be useful here since it is referenced in an issue?

flap152#1

Steps To Reproduce

Given this html content:

<!DOCTYPE html>
<html>
    <head>
        <title>Assert See In</title>
    </head>
    <body>
        <div id="app">
            <div>First</div>
            <div>Second</div>
            <div>Third</div>
            <div>Fourth</div>
            <h1>Hello World</h1>
        </div>
    </body>
</html>

the following asserts would fail with either a false negative or "element not found"

    public function test_it_handles_assert_see_in_with_multiple_selection()
    {
        $this->browse(function (Browser $browser) {
            $browser->visit('/tests/assert-see-in');
             $browser->assertSeeIn('#app > div:nth-child(3)', 'Third');
             $browser->assertDontSeeIn('#app > div:nth-child(3)', 'Second')
            ;
        });
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions