Behat工作正常,但在尝试点击时,下拉菜单上的幻影失败[英] Behat works fine but PhantomJS fails on dropdown menu when trying to click

问题描述

gherkin在下面工作正常,但是当我使用phantomjs时,我在下面的When I follow "Profile"行上得到错误:

注意:该元素是来自Bootstrap的下拉菜单,以便在单击后切换.

错误:

Exception thrown by (//html/.//a[./@href][(((./@id = 'Profile' or contains(normalize-space(string(.)), 'Profile')) or contains(./@title, 'Profile') or contains(./@rel, 'Profile')) or .//img[contains(./@alt, 'Profile')])] | .//*[./@role = 'link'][((./@id = 'Profile' or contains(./@value, 'Profile')) or contains(./@title, 'Profile') or contains(normalize-space(string(.)), 'Profile'))])[1]
{"errorMessage":"Element is not currently visible and may not be manipulated","request":{"headers":{"Accept-Encoding":"gzip,deflate","Connection":"Keep-Alive","Content-Length":"27","Content-Type":"application/json; charset=utf-8","Host":"localhost:5140","User-Agent":"Apache-HttpClient/4.3.4 (java 1.5)"},"httpVersion":"1.1","method":"POST","post":"{\"id\":\":wdc:1412065547042\"}","url":"/click","urlParsed":{"anchor":"","query":"","file":"click","directory":"/","path":"/click","relative":"/click","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/click","queryKey":{},"chunks":["click"]},"urlOriginal":"/session/5b7c0830-487b-11e4-adc0-a162f25e4a98/element/%3Awdc%3A1412065547042/click"}}

gherkin:

When I follow "Profile"
And I follow "Edit"

html:

<ul class="nav navbar-nav navbar-right">
    <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Profile <span class="caret"></span></a>
        <ul class="dropdown-menu" role="menu">
            <li><a href="#">Show</a></li>
            <li><a href="#">Edit</a></li>
        </ul>
    </li>
</ul>

推荐答案

我发现为什么和用小修复器解决,如下所示.

使用引导时,菜单被压缩,只有一个图标表示相同的菜单,这是响应设计的正常行为.现在一切都很好,但是当普兰缪斯运行时,它找不到它正在寻找的文本.例如在我的情况下"配置文件"菜单.

菜单的原始状态,总是工作正常:

在此输入图像描述

压缩后的版本后导致幻影失败:

在此输入图像描述

解决方案:

只是将窗口大小设置为更大的东西,以便在测试时菜单不会被压缩.您可以根据需要将屏幕大小从1024x768更改为其他内容.

#symfony/src/Site/CommonBundle/Features/Context/FeatureContext.php

/**
 * @BeforeStep
 */
public function beforeStep()
{
    $this->getSession()->resizeWindow(1024, 768, 'current');
}

本文地址:https://www.itbaoku.cn/post/1740201.html

相关标签/搜索