【问题标题】:PhpUnit Not waiting to load page after clicking submitPhpUnit 点击提交后不等待加载页面
【发布时间】:2014-09-18 14:29:36
【问题描述】:

我正在阅读一个教程,在 PHPUNIT 上我得到了很好的教程退出......并进行了一些登录 我自己..

但我进入网络加载页面并在实时页面上提交值

它工作正常......但我遇到的问题是在输入用户密钥后..它提交但它不会等待下一页

我在这里看到类似的问题,但没有一个适合我

谁能帮帮我。

这是我的代码

<?php
class TestLogin extends PHPUnit_Extensions_Selenium2TestCase {
public function setUp()
{
    $this->setHost('localhost');
    $this->setPort(4444);
    $this->setBrowser('firefox');
    $this->setBrowserUrl('http://localhost/tutor');
}

public function setSpeed($timeInMilliSec)
{
    $this->setSpeed('120');
}
 /*Function to locate website*/
public function testHasLoginForm()
{
    $this->url('http://www.jamb.org.ng/DirectEntry/');/*This is the site*/
    $username = $this->byId('ctl00_ContentPlaceHolder1_RegNumber');/*Search for a name*/
            ##ctl00_ContentPlaceHolder1_txtRegNumber
    $action = $this->byId('ctl00_ContentPlaceHolder1_Reprint')->attribute('action');
    $this->byId('ctl00_ContentPlaceHolder1_RegNumber')->value('49130518ED');/*value of the textbox*/
    $jump = $this->byId('ctl00_ContentPlaceHolder1_Reprint');
    $jump->submit();
}

}
?>

【问题讨论】:

  • setSpeed 是没用的方法。

标签: php selenium phpunit pear wampserver


【解决方案1】:

你可以使用

 $this->timeouts()->implicitWait(10000);//10 seconds

设置页面上搜索元素的超时时间。

https://github.com/sebastianbergmann/phpunit-selenium/blob/master/PHPUnit/Extensions/Selenium2TestCase/Session/Timeouts.php

【讨论】:

  • @user3803698 ,是的,我做到了。
  • @user3803698 , OK (1 test, 0 assertions) 无修改
  • 请退出对 selenium、phpunit、pear 和 rest 的了解,但我一直在努力学习教程....如果我建立一个页面....我在那个页面登录退出好了我的本地主机......但这次你想自动化一个网站......我一直在努力让别人提问。不知道我们是否可以联系...这是我的 Skype 美洲狮
  • @user3803698 ,你想达到什么目的?
  • 我想用值 49130518ED 登录到jamb.org.ng/DirectEntry 并访问此链接jamb.org.ng/DirectEntry/PrintSlip.aspx 并下载jamb.org.ng/DirectEntry/ImagePage.aspx 中的图片就是这样
【解决方案2】:

已解决。我只是改变了

 $jump->submit();

$this->byName('ctl00$ContentPlaceHolder1$Reprint')->click();

【讨论】:

  • 我只是被这个...我想在登录后下载整个页面。我得到了这个 Print Popout 的东西。我只想在登录和 teardown() 后将 jamb.org.ng/DirectEntry/ImagePage.aspx 保存到我的电脑中,你有什么办法可以做到吗??
【解决方案3】:

如果您想等待不同的元素甚至功能,我建议使用此pattern 这是示例等待元素。我建议在这里使用 byCssSelector 以获得更大的灵活性。

您可以轻松地使用此模式,例如等待元素可点击:

protected function waitForClickable($element, $wait=30) {
    for ($i=0; $i <= $wait; $i++) {
        try{
            $element->click();
            return true;
        }
        catch (Exception $e) {
            sleep(1);
        }
    }
    return false;
}

您甚至可以在将匿名函数作为参数传递的任何上下文中使用它:

protected function waitForAny($function, $args, $wait=30) {
    for ($i=0; $i <= $wait; $i++) {
        try{
            call_user_func_array($function, $args);
            return true;
        }
        catch (Exception $e) {
            sleep(1);
        }
    }
    return false;
}

用法:

$f = function($e){
    $e->click();
};
$this->waitForAny($f, array($element));

【讨论】:

    猜你喜欢
    • 2012-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-13
    • 1970-01-01
    相关资源
    最近更新 更多