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

Unexpected behaviour for assertSeeIn() #112

Open
benr77 opened this issue Nov 29, 2022 · 6 comments
Open

Unexpected behaviour for assertSeeIn() #112

benr77 opened this issue Nov 29, 2022 · 6 comments

Comments

@benr77
Copy link
Contributor

benr77 commented Nov 29, 2022

I keep getting annoyed when using assertSeeIn() as the CSS selection often does not do what I expect.

Say I have a table in my page:

<tr>
    <td>Foo</td>
    <td>Bar</td>
</tr>

If I want to check that Bar is present, I would expect to be able to use:

$this->assertSeeIn('td', 'Bar').

This will work for Foo as it's the first td that the crawler will encounter, but to match Bar I have to use:

$this->assertSeeIn('tr td:last-child', 'Bar')

I expect assertSeeIn to find a string in ANY element that matches the $selector.

Is this the expected/desired behaviour? If so then something in the docs about it would be good, but personally I don't think it's the right behaviour - I don't want to couple my tests so tightly to the exact HTML - in this case I just want to check the Bar is shown somewhere in the table, I don't care about its exact position.

Any thoughts?

Cheers

@kbond
Copy link
Member

kbond commented Nov 29, 2022

Yes, I've been burned by this before as well. I agree with your conclusion on how it should work.

@benr77
Copy link
Contributor Author

benr77 commented Nov 30, 2022

Is this just how behat/mink normally works? I guess you can't really change this behaviour now as it would break a lot of people's existing tests...

@kbond
Copy link
Member

kbond commented Nov 30, 2022

Is this just how behat/mink normally works?

Yes

I guess you can't really change this behaviour now as it would break a lot of people's existing tests...

That's my concern. Maybe a new method?

@nikophil
Copy link
Member

assertSeeInAny()?

@benr77
Copy link
Contributor Author

benr77 commented Dec 1, 2022

I was also thinking of assertSeeInAny() but I think the issue is more the underlying use of behat/mink than the method name. I don't know Mink at all - maybe it also has another method that mirrors our requirement here...

@kbond
Copy link
Member

kbond commented Dec 1, 2022

I don't recall mink having such a method but we should be able to add this behaviour manually (find all the elements via the dom crawler, get their text, then assert if the expected text is contained within)

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

No branches or pull requests

3 participants