【发布时间】:2017-07-25 08:02:12
【问题描述】:
我有一个像这样的 Behat 步骤,它断言 URL 中有一个指向带有 /videos/ 的东西的链接:
And I must see at least 1 "*[href~=/videos/]"
实现如下:
/**
* 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() . '.'
);
}
例外是:
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
为什么我不能在步骤中添加斜线?
【问题讨论】:
-
你有没有尝试像“*[href~=\/videos\/]”这样逃避你的选择器???
-
是的,试着像圣骑士说的那样逃跑
-
@Paladin 然后它不会抛出错误,但它没有找到匹配的元素(当我将选择器放在浏览器的控制台中时找到它们
$("a[href*='\/artikel\/']"))。
标签: php symfony exception behat mink