Change record status: 
Project: 
Introduced in branch: 
8.x-1.x
Introduced in version: 
8.0-ALPHA13
Description: 

Drupal's WebTestBase now includes a ::cssSelect method. This method leverages the Symfony CSS-selector component which translates CSS selectors into xpath.

Previously writing web-tests required the developer to use xpath to find and select elements on the page. Xpath is quite difficult to learn and hence created a barrier to writing tests for new contributors.

Most developers are familiar with CSS selectors so by adding Symfony's CssSelector component to core, it is hoped that the barrier to writing tests has been lowered.

To use the new functionality use the cssSelect method on your web-test.

Before

$elements = $this->xpath('//div[contains(concat(" ", normalize-space(@class), " "), :field_class)]/li[@data-id=:data_id and ./h2[contains(., :text)]]', array(
  ':field_class' => 'tours',
  ':data_id' => 'tour-test-1',
   ':text' => 'The first tip',
));

After

$elements = $this->cssSelect("div.tours > li[data-id=tour-test-1] h2:contains('The first tip')");
Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done

Comments

cordoval’s picture

i thought this dependency already came with behat and mink

i mean because symfony has coupled components in -dev mode, this could come via https://github.com/Behat/MinkBrowserKitDriver/blob/master/composer.json#L21

https://packagist.org/packages/symfony/dom-crawler and Requires

Requires (Dev)
symfony/css-selector: ~2.0

no?