php-webdriver:使用click()提交表单后,等待浏览器响应 [英] php-webdriver: wait for browser response after submitting form using click()
本文介绍了php-webdriver:使用click()提交表单后,等待浏览器响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
除了在测试中使用sleep()
外,我想知道是否有人知道有更好的策略来明确地等待表单提交(POST),然后再继续我的断言.这是我的测试的简明版本,与Facebook一起使用phpunit php-webdriver ).
Aside from using sleep()
in my test, I'm wondering if anyone knows of a better strategy to explicitly wait for a form submission (POST) to complete before continuing with my assertions. Here's a very condensed version of what my test looks like, using phpunit together php-webdriver from Facebook).
function test_form_submission()
{
// setup
$web_driver = new WebDriver();
$session = $web_driver->session();
$session->open('http://example.com/login');
// enter data
$session->element('css selector', 'input[name=email]')->value(array('value' => str_split('test@example.com')));
$session->element('css selector', 'input[name=password]')->value(array('value' => str_split('testpassword')));
// click button to submit form
$session->element('css selector', 'button[name=submit]')->click();
// How do I wait here until the click() above submits the form
// so I can check that we correctly arrives at the destination below
// without resorting to sleep()?
// Confirm that login was successful because we landed on account page
$this->assertSame('http://example.com/account', $session->url());
// teardown
$session->close();
}
来自Facebook的
推荐答案
php-webdriver 已被重写在2013年6月.您可以像这样轻松地等待网址.
php-webdriver from Facebook has been rewritten in June 2013. You can wait for the URL easily like this.
// wait for at most 10 seconds until the URL is 'http://example.com/account'.
// check again 500ms after the previous attempt.
$driver->wait(10, 500)->until(function ($driver) {
return $driver->getCurrentURL() === 'http://example.com/account';
})
这篇关于php-webdriver:使用click()提交表单后,等待浏览器响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文