除了使用sleep()
在我的测试中,我想知道是否有人知道更好的策略,可以在继续我的断言之前显式等待表单提交(POST)完成。这是我的测试的一个非常浓缩的版本,结合使用 phpunitphp-webdriver https://github.com/facebook/php-webdriver/来自脸书)。
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('[email protected] /cdn-cgi/l/email-protection')));
$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();
}
php-webdriver https://github.com/facebook/php-webdriver/来自Facebook的已于2013年6月重写。您可以像这样轻松等待URL。
// 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';
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)