Symfony2功能测试-单击具有jQuery交互的元素 [英] Symfony2 Functional Testing - Click on elements with jQuery interaction

查看:79
本文介绍了Symfony2功能测试-单击具有jQuery交互的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对使用Symfony2(2.1)完成的应用程序进行一些功能测试,但遇到了问题.

I'm doing some functional tests for an application done with Symfony2 (2.1) and I'm stuck with a problem.

我有网站的某些部分在用户单击链接或其他元素时加载,但是这些操作是使用jQuery和$ .post调用执行的.如何让Symfony2搜寻器执行这些调用?

I have some parts of the website that load when the user clicks a link or other element, but these actions are performed using jQuery and $.post calls. How can I get the Symfony2 crawler to do these calls?

当我做这样的事情时:

$link    = $crawler->filter('ul.line_menu a')->eq(1)->link();
$crawler = $client->click($link);

搜寻器获取"a"元素的"href"并启动它,但是"href"为空,并且"click()"函数与此元素相关联,从而防止了使用"preventDefault( )".

The crawler gets the "href" of the "a" element and launches it, but the "href" is empty, and a "click()" function is associated with this element, preventing the click action with "preventDefault()".

谢谢大家!! :)

推荐答案

Symfony功能测试通过直接调用Symfony内核来执行您的代码.它们不是通过网络浏览器运行的,因此不支持javascript(根本不会执行).

Symfony functional tests exercise your code by directly calling the Symfony kernel. They're not run through a web browser and therefore don't support javascript (which is simply not executed).

如果没有javascript无法运行您的应用程序,则必须使用其他工具进行功能测试.一种选择是将 Mink 与支持javascript的驱动程序之一一起使用(例如

If it's not possible to run your application without javascript, than you have to use another tool for functional testing. One of the options is to use Mink with one of the drivers supporting javascript (like Selenium2).

这篇关于Symfony2功能测试-单击具有jQuery交互的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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