我可以让Behat/ZombieJS/Mink模拟对“非链接"点击的点击吗?元素,触发JS侦听器? [英] Can I make Behat/ZombieJS/Mink simulate a click on a "non-link" element, to fire JS listeners?

查看:128
本文介绍了我可以让Behat/ZombieJS/Mink模拟对“非链接"点击的点击吗?元素,触发JS侦听器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 Behat 用于测试, zombie.labnotes.org/"rel =" noreferrer> ZombieJS 驱动程序,到目前为止一切工作都很好,但是有一件事困扰着我,我似乎无法弄清楚如何获得Behat模拟非链接元素上的点击.我想这是因为Mink是跨浏览器"驱动程序,因此单击非链接元素实际上没有任何意义.不过,对于我的用例,我需要它,因为页面上有几个附加了javascript事件监听器的元素,并且我想测试这些功能.

I am using Behat for testing, with the ZombieJS driver, and everything is working very well so far, but there is one thing that bothers me, I can't seem to figure out how to get Behat to simulate a click on a non-link element. I guess this comes from Mink being a "cross-browser" driver, and it doesn't really make sense to click on non-link elements. For my use case though, I need it, because there are several elements on the page that have javascript event listeners attached to them, and I want to test these functionalities.

我尝试使用

Then I follow "div.sa"

但是它失败,并出现预期的错误:

But it fails with the expected error:

01. Link with id|title|alt|text "div.sa" not found.

由于它不是链接元素. Behat中有类似的步骤:

Since it's not a link element. There is a similar step in Behat:

我按下"button.class"

I press "button.class"

但这仅用于按钮.

有没有办法让Behat单击非标记元素?

Is there a way I could get Behat click on elements that are not tags?

推荐答案

是的,我相信,但是您需要编写一个自定义步骤,并遵循以下原则(如果您使用的是MinkContext的子类.

Yes I believe so, but you'll need to write a custom step, something along these lines (if you're using a subclass of MinkContext.

/**
 * @When /^I click the something$/
 */
public function iClickTheSomething() 
{
    $something = $this->getSession()
                      ->getPage()
                      ->find("css", "div.sa")
                      ->click();
}

这篇关于我可以让Behat/ZombieJS/Mink模拟对“非链接"点击的点击吗?元素,触发JS侦听器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆