2013-06-24 3 views
0

SimpleTest PHP 프레임 워크의 일부인 SimpleBrowser를 사용하고 있습니다.SimpleBrowser가 빈 html을 반환합니다.

아이디어는 웹 사이트와 사용자 상호 작용을 모방하고 추가 비교를 위해 반환 된 HTML 코드를 파일에 기록하는 것입니다. 빈 HTML이 때때로 반환되기 때문에 무언가가 잘못되었습니다.

getTransportError() returns Nothing fetched 

완전히 임의의 위치에서 발생하며 대부분의 페이지가 양식을 제출하기 때문에 back() 기능을 사용할 수 없습니다.

require_once ('simpletest/browser.php');

class TesterBrowser extends SimpleBrowser 
{ 

    /** 
    * Test the page against the reference. If reference is missing, is it created 
    * Uses md5 checksum to check if files are identical 
    * 
    * @param string $forcename Optional. Substitude autogenerated filename. 
    * @param boolean $forceRef Optional. Force file to be saved as the reference 
    * 
    * @access public 
    * 
    * @return void 
    */ 
    public function testPage($forcename = "") 
    { 
     //who called me? 
     //$callers=debug_backtrace(); 
     //$whocalledme = $callers[1]['function']; 
     //get the current source 
     $html = $this->getContent(); 
     //generate filename 
     $filename = empty($forcename) ? preg_replace('/[^\w\-'. ''. ']+/u', '-', $this->getUrl()) : $forcename; 
     $filename .= ".html"; 
     //is there a gauge? 
     if(file_exists("ref/".$filename) && filesize(dirname(__FILE__)."/ref/".$filename) > 0) 
     { 
      //is there a difference 
      file_put_contents(dirname(__FILE__)."/actual/".$filename, $html); 
      if(filesize(dirname(__FILE__)."/actual/".$filename) == 0) 
      { 
       return false; 
      } 
      if(md5_file(dirname(__FILE__)."/actual/".$filename) != md5_file(dirname(__FILE__)."/ref/".$filename)) 
      { 
       echo $this->getUrl() . " (" . $filename . ") has changed \r\n"; 
      } 
     } 
     else 
     { 
      file_put_contents(dirname(__FILE__)."/ref/".$filename, $html); 
      if(filesize(dirname(__FILE__)."/ref/".$filename) == 0) 
      { 
       return false; 
      } 
     } 
     return true; 
    } 

    /** 
    * Output the string to the terminal 
    * 
    * @param mixed $string String to output 
    * 
    * @access public 
    * 
    * @return void 
    */ 
    public function output($string) 
    { 
     echo date("d-m-Y H:i:s") . " - $string... \r\n"; 
     //update date so that it will be the same on every page 
     exec('date -s "24 JUN 2013 10:00:00"'); 
    } 

    /** 
    * Restore the server date using external NTP server 
    * 
    * @access public 
    * 
    * @return void 
    */ 
    public function restoreDate(){ 
     $this->output("Restoring the date&time from NTP server"); 
     exec("ntpdate 0.uk.pool.ntp.org"); 
     exec("hwclock -systohc"); 
    } 

} 

는 그리고 방법의 테스트는 수행됩니다

class Tester 
{ 
    public $browser = null; 
    const BASEURL = "http://ticketing/"; 

    function __construct(){ 
     $this->browser = new TesterBrowser(); 
     $this->browser->setConnectionTimeout(180); 

     //get the list of class method to be run 
     $methods = array(); 

     foreach(get_class_methods($this) as $var) 
     { 
      if(0 === strpos($var, 'test')) //they all start with test 
      { 
       $methods[] = $var; 
      } 
     } 

     $methods[] = "cleanUp"; 

     //now we need to run these methods 
     foreach($methods as $m){ 
      while($this->$m() == false){ 
       $this->browser->output("Empty page, trying again"); 
       sleep(5); 
      } 
     } 
    } 

    //index page 
    function testGetIndexPage() 
    { 
     $this->browser->output("Getting index page"); 
     $this->browser->get(self::BASEURL); 
     return $this->browser->testPage(); 
    } 

    //try to enter wrong password 
    function testWrongPassword() 
    { 
     $this->browser->output("Entering wrong credentials"); 
     $this->browser->setField("username", "wrong"); 
     $this->browser->setField("password", "wrong"); 
     $this->browser->clickSubmitByName("submit"); 
     return $this->browser->testPage("wrong-credentials");   
    } 
     //Delete ticket though admin 
    function testDeleteTicketThroughAdmin() 
    { 
     $this->browser->output("Deleting the ticket through admin page"); 
     $this->browser->setField("bulk[]", "375341"); 
     $this->browser->setField("bulkaction", "delete"); 
     $this->browser->clickSubmit("Do Action"); 
     return $this->browser->testPage("deleted-ticket-admin");   
    } 

    //Restore the date 
    function cleanUp() 
    { 
     $this->browser->restoreDate(); 
     return true; 
    } 

} 

$tester = new Tester(); 

은 물론 더 많은 테스트가 수행이 박탈 버전이 있습니다. 나는이 문제에 관해 많은 것을 봤다. 적절한 문서가없는 것 같다.

답변

0

해결되었습니다. 어떤 이유로 든 적절한 오류 메시지가 구현되지 않았지만 시간 초과 문제였습니다.

$this->browser->setConnectionTimeout(180);