Skip to content

Conversation

@dunglas
Copy link
Member

@dunglas dunglas commented Jul 9, 2018

:contains is a proprietary jQuery selector, and has been explicitly removed from the CSS 3 spec: https://stackoverflow.com/questions/4781141/why-doesnt-the-selector-h3nth-child1containsa-work/4781167#4781167

Then, it doesn't work with Panthère (it's actually supported by Selenium, but not by WebDriver).

I propose to use Xpath instead.


$this->assertSame(200, $client->getResponse()->getStatusCode());
$this->assertSame(1, $crawler->filter('h1:contains("Hello World")')->count());
$this->assertCount(1, $crawler->filterXPath('//h1:[contains(text(), "Hello World")]'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about

$this->assertContains('Hello World', $crawler->filter('h1'));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be this though:

$this->assertContains('Hello World', $crawler->filter('h1')->text());

And this assumes that it is the only h1 on the page btw (or at least the first one), otherwise the test would fail

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right ;)

But anyway, this is boiler plate code, and it should be updated...
So I'm totally 👍 with stof's proposal

@weaverryan
Copy link
Member

I updated the selector to the simpler version, recommended by Stof, but still without the :contains. Thanks @dunglas!

@weaverryan weaverryan merged commit 7d580ea into symfony:master Aug 6, 2018
weaverryan added a commit that referenced this pull request Aug 6, 2018
…eaverryan)

This PR was merged into the 1.0-dev branch.

Discussion
----------

Don't use :contains in the functional test tpl

`:contains` is a proprietary jQuery selector, and has been explicitly removed from the CSS 3 spec: https://stackoverflow.com/questions/4781141/why-doesnt-the-selector-h3nth-child1containsa-work/4781167#4781167

Then, it doesn't work with Panthère (it's actually supported by Selenium, but not by WebDriver).

I propose to use Xpath instead.

Commits
-------

7d580ea Using simpler selector
622b49c Don't use :contains in the functional test tpl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants