但是尝试单击时PhantomJS在下拉菜单上失败

但是尝试单击时PhantomJS在下拉菜单上失败

本文介绍了Behat正常运行,但是尝试单击时PhantomJS在下拉菜单上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的小黄瓜可以在behat上正常工作,但是当我使用PhantomJS时,下面的When I follow "Profile"行会出现错误:

Gherkin below works fine with behat but when I use PhantomJS I get error on When I follow "Profile" line below:

注意:该元素是引导程序的下拉菜单,因此单击后即可切换.

Note: The element is a dropdown menu from bootstrap so it toggles after click.

错误:

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"}}

小黄瓜:

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>

推荐答案

我已经找到原因,并通过如下所示的小解决方案进行了解决.

I've discovered why and solved with a small fix as shown below.

使用Bootstrap时,菜单会被压缩,只有一个图标出现,代表相同的菜单,这是响应式设计的正常行为.目前一切正常,但是运行PhantomJS时,找不到所需的文本.例如就我而言,个人资料"菜单.

When using Bootstrap, the menus get squashed down and only an icon appears to represent the same menu which is the normal behaviour for responsive design. All fine for now but when PhantomJS is run, it cannot find the text it is looking for. e.g. "Profile" menu in my case.

菜单的原始状态,始终可以正常工作:

压缩版本后导致PhantomJS失败:

解决方案:

只需将窗口大小设置为更大,以便在测试时不会缩小菜单.您可以根据需要将屏幕尺寸从1024X768更改为其他尺寸.

Just set the window size to something bigger so that the menu doesn't get squashed down when testing. You can change the screen size from 1024X768 to something else as you wish.

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

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

这篇关于Behat正常运行,但是尝试单击时PhantomJS在下拉菜单上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 09:23