I have a Behat step like this, which asserts there is a link pointing to something with /videos/
in the URL:
And I must see at least 1 "*[href~=/videos/]"
The implementation is as follows:
/**
* Asserts that at least X amount of Y exist
*
* @Then /^I must see at least (?P<amount>\d+) "([^"]*)"$/
*/
public function iMustSeeAtLeast($amount, $selector)
{
$session = $this->getSession();
$container = $this->getContainer() ?: $session->getPage();
$elements = $container->findAll('css', $selector);
$actual = count($elements);
AssertionAbstract::assertGreaterThanOrEqual(
(int)$amount,
(int)$actual,
'Expected at least ' . $amount . ' of ' . $selector . ', found only ' . $actual . ' on ' . $session->getCurrentUrl() . '.'
);
}
The exception is:
Exception 'Symfony\Component\CssSelector\Exception\SyntaxErrorException'
with message 'Expected string or identifier, but <delimiter "/" at 8> found.'
in vendor/symfony/css-selector/Exception/SyntaxErrorException.php:34
Why I can't put a slash in the step?
You don't need the *
in the front, findAll
will find all the elements for the given selector.
Format your selector(s) like this:
[href~='/videos/']
a[href*='/artikel/']
As described in the Exception you are getting, it does't like the /
, you need to add it in single/double quotes.
You can also try something like:
a[href*=artikel]