Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
flap152 opened this issue Dec 26, 2024 · 3 comments
Open

Comments

@flap152
Copy link

flap152 commented Dec 26, 2024

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')
            ;
        });
    }
Copy link

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

@flap152
Copy link
Author

flap152 commented Dec 28, 2024

I submitted PR and made it ready for review. Hope I'm not too far off. 😰 🤞

@flap152
Copy link
Author

flap152 commented Jan 3, 2025

Hi @crynobone, the PR is closed/delayed for now and that's ok, but I'd really appreciate feedback on the issue (behavior with multiple elements), but also the submitted changes, comments and questions I made regarding the implementation and testing.
I think this would help make valuable contributions to dusk/laravel in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants