在测试期间我需要做以下操作:
During test I need to do following:
单击按钮,从而导致Ajax请求,之后重定向 检查该用户已被重定向到正确的页面我的code:
$this->byId('reg_email')->value('test@example.com');
$this->byId('reg_password')->value('seecret');
// No form here, so i can't just call submit()
// This click invokes ajax request
$this->byId('reg_submit')->click();
// Check page content (this page should appear after redirect)
$msg = $this->byCssSelector('h1')->text();
$this->assertEquals('Welcome!', $msg);
问题
信息检查去点击之后,而不是之前Ajax请求和页面重定向解决方案,我不喜欢的:
Solution, I do not like:
添加睡眠(3);
内容前检查
Add sleep(3);
before content check.
我不喜欢它,因为:
这是愚蠢的 在案件的快速响应,我要抓紧时间,以防长要求我将Ajax请求结束前获得内容的检查。我不知道,有没有什么办法来跟踪Ajax请求+刷新和检查的内容只是在时间?
I wonder, is there any way to track ajax request+refresh and check for content just in time?
我的设置:
在PHP 5.4,5.5也可 在PHPUnit的3.8 硒区局整合PHPUnit的1.3.1 硒服务器独立2.33.0 在Windows 7的64 在JRE 7好了,有一种解决方案,我不喜欢它,但它是什么,而不是什么都没有。
Ok, there is a kind of solution, I am not really like it, but it is something instead of nothing.
我们的想法是使用更智能的睡眠,有一种方法最好推迟到()
这需要一个匿名函数
和暂停
以毫秒为单位。什么是呢 - 运行此传递函数中循环,直到超时命中或函数返回真
。所以,你可以运行的东西,等到环境被改变:
The idea is to use more smart "sleep", there is a method waitUntil()
which takes an anonymous function
and timeout
in milliseconds. What is does - runs this passed function in loop until timeout hits or your function return True
. So you can run something and wait until context is changed:
$this->waitUntil(function () {
if ($this->byCssSelector('h1')) {
return true;
}
return null;
}, 5000);
我还是会很高兴,如果有人提供更好的解决方案。
I still will be glad if somebody give better solution.