php-webdriver : wait for browser response after submitting form using click()

标签 php selenium phpunit selenium-webdriver

除了在我的测试中使用 sleep() 之外,我想知道是否有人知道在继续我的断言之前显式等待表单提交 (POST) 完成的更好策略。这是我的测试的一个非常精简的版本,同时使用 phpunit php-webdriver来自 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();
}

最佳答案

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';
})

关于php-webdriver : wait for browser response after submitting form using click(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14466993/

相关文章:

PHP MCRYPT 不断抛出 Module initialization failed Warning

java - Selenium 测试花费的时间异常长

php - 模拟当前测试类的内部函数调用

symfony - 正在尝试配置无法配置的方法 "first",因为它不存在、未指定、是最终的或静态的

Laravel 5.5 PHPunit测试- "A facade root has not been set."

php - 向 Laravel 样板用户模型添加新字段

php - 如何通过 PHP 中的路径信息传递 URL 来防止 SSRF?

php - 函数 getName 在 symfony 2 形式中做什么

php - 无法使用带有 php 的 Selenium 将 cookie 添加到页面

http - 在 Python 中将 Firefox WebDriver 与 Selenium 连接时出现问题