我在网站上有一个可扩展的div.我想用Behat / Mink创建一个测试用例,断言当用户到达页面时,框不会被展开.
<a class="expand" data-reactid=".r[37uxa].[1]" href="#">Click to expand</a> <div class="expandable" data-reactid=".r[37uxa].[2]" style="height: 0px;">
之后当用户点击“点击展开”时,style =“height”的值会发生变化:
<a class="expand" data-reactid=".r[37uxa].[1]" href="#">Click to expand</a> <div class="expandable" data-reactid=".r[37uxa].[2]" style="height: 157px;">
这意味着它现在已经扩展.
我想知道是否有办法或者我是否可以实现步骤定义来检查/获取style属性的值.谢谢.
解决方法
您可以使用
NodeElement::isVisible()
来检查元素的可见性.
$session = $this->getSession(); // assume extends RawMinkContext $page = $session->getPage(); $expandable = $page->find('css','.expandable'); if (null === $expandable) { throw new \LogicException('Could not find the element'); } if ($expandable->isVisible()) { throw new \LogicException('Element is visible...'); }
或者自己检查样式attribute:
$style = $expandable->getAttribute('style');