无法让硒等待 - 测试仅在手动踩踏时才有效

时间:2011-04-18 09:30:40

标签: selenium phpunit zend-studio

我有一个基本问题,即我的selenium phpunit测试都没有通过,除非我在调试视图中手动逐步执行它们,这显然有点不方便!我从以下jar文件运行本地selenium服务器并在Zend Studio 8中执行phpunit测试。

硒 - 服务器 - 独立-2.0b2.jar

我似乎无法在Google上找到任何相关内容或在此处搜索,所以我认为我一定做错了。这是我从大多数测试方法的开始调用以便登录的示例方法。

protected function login() {
    $this->open ( "/login.php" );

    try {
        $this->waitForPageToLoad ( "30000" );
        $this->type ( "username", self::MA_USERNAME );
        $this->type ( "password", self::MA_PASSWORD );
        $this->click ( "//input[@value=' Login ']" );
        $this->waitForPageToLoad ( "60000" );

        $this->assertFalse( $this->isTextPresent( "Login details supplied are invalid." ) );
    } catch ( PHPUnit_Framework_AssertionFailedError $e ) {
        array_push ( $this->verificationErrors, $e->toString () );
    }
}

如果我只是按'运行'然后让它去,那么它甚至没有填写字段或提交表单,所以我假设它没有等待加载页面尽管有waitForPageToLoad()呼叫。逐步完成手动操作。谁能建议如何解决这个问题?感谢。

1 个答案:

答案 0 :(得分:0)

似乎Selenium正在执行快速命令。我遇到了同样的问题 我解决问题的方法是使用函数 setSpeed($ timeInMilliSec)

在php中:

$this->setSpeed('120');

所以在你的函数中,试试这个:

protected function login() {
    $this->open ( "/login.php" );
    $this->setSpeed('120');

    try {
        $this->waitForPageToLoad ( "30000" );
        $this->type ( "username", self::MA_USERNAME );
        $this->type ( "password", self::MA_PASSWORD );
        $this->click ( "//input[@value=' Login ']" );
        $this->waitForPageToLoad ( "60000" );

        $this->assertFalse( $this->isTextPresent( "Login details supplied are invalid." ) );
    } catch ( PHPUnit_Framework_AssertionFailedError $e ) {
        array_push ( $this->verificationErrors, $e->toString () );
    }
}

希望这可以解决您的问题

相关问题