2014-07-27 35 views
1

我正在經歷的教程後,載入頁面,在PHPUnit的我得到了教程退出以及...和做一些登錄 我自己..的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(); 
} 

} 
?> 
+0

'setSpeed'是無用的方法。 – sectus

回答

0

Resolved.i只是改變

$jump->submit(); 

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

yeah..yeah ... tahnsk – pumamammal

+0

我只是放了這個...我想在登錄後下載整個這個頁面。我得到這個打印Popout的東西。我只是想在登錄和teardown()之後將jamb.org.ng/DirectEntry/ImagePage.aspx保存到我的計算機中,我有辦法做到這一點嗎? – pumamammal

0

如果你想等待不同勢的元素,甚至能力,我建議使用此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));