Source for file selenium.php

Documentation is available at selenium.php

  1. <?php
  2.  
  3. require_once dirname(__FILE__'/../unit_tester.php';
  4. require_once dirname(__FILE__'/selenium/remote-control.php';
  5.  
  6. {
  7.     /**#@+
  8.      * Selenium instantiation variables
  9.      */
  10.     protected $browser = '';
  11.     protected $browserUrl = '';
  12.     protected $host = 'localhost';
  13.     protected $port = '4444';
  14.     protected $timeout = 30000;
  15.     /**#@-*/
  16.  
  17.     protected $selenium = null;
  18.     protected $newInstanceEachTest = true;
  19.  
  20.     public function __construct($name 'Selenium Test Case'{
  21.         parent::UnitTestCase($name);
  22.  
  23.         if (empty($this->browser)) {
  24.             trigger_error('browser property must be set in ' get_class($this));
  25.             exit;
  26.         }
  27.  
  28.         if (empty($this->browserUrl)) {
  29.             trigger_error('browserUrl property must be set in ' get_class($this));
  30.             exit;
  31.         }
  32.     }
  33.  
  34.     public function setUp({
  35.         parent::setUp();
  36.  
  37.         if (is_null($this->selenium)) {
  38.             $this->selenium = new SimpleSeleniumRemoteControl(
  39.                 $this->browser,
  40.                 $this->browserUrl,
  41.                 $this->host,
  42.                 $this->port,
  43.                 $this->timeout
  44.             );
  45.             $this->selenium->start();
  46.         }
  47.     }
  48.  
  49.     public function tearDown({
  50.         parent::tearDown();
  51.  
  52.         if ($this->newInstanceEachTest{
  53.             $this->selenium->stop();
  54.             $this->selenium = null;
  55.         }
  56.     }
  57.  
  58.     public function __call($method$arguments{
  59.         if (substr($method06== 'verify'{
  60.             return $this->assertTrue(
  61.                 call_user_func_array(
  62.                     array($this->selenium$method),
  63.                     $arguments
  64.                 ),
  65.                 sprintf('%s failed'$method)
  66.             );
  67.         }
  68.                     
  69.         return call_user_func_array(
  70.             array($this->selenium$method),
  71.             $arguments
  72.         );
  73.     }
  74.  
  75.     public function verifyText($text{
  76.         return $this->assertTrue(
  77.             $this->selenium->verifyText($text),
  78.             sprintf(
  79.                 'verifyText failed when on [%s]',
  80.                 $text
  81.             )
  82.         );
  83.     }
  84.  
  85.     public function verifyTextPresent($text{
  86.         return $this->assertTrue(
  87.             $this->selenium->verifyTextPresent($text),
  88.             sprintf(
  89.                 'verifyTextPresent failed when on [%s]',
  90.                 $text
  91.             )
  92.         );
  93.     }
  94.  
  95.     public function verifyTextNotPresent($text{
  96.         return $this->assertTrue(
  97.             $this->selenium->verifyTextNotPresent($text),
  98.             sprintf(
  99.                 'verifyTextNotPresent failed on [%s]',
  100.                 $text
  101.             )
  102.         );
  103.     }
  104.  
  105.     public function verifyValue($selector$value{
  106.         return $this->assertTrue(
  107.             $this->selenium->verifyValue($selector$value),
  108.             sprintf(
  109.                 'verifyValue failed on [%s] == [%s]',
  110.                 $selector,
  111.                 $value
  112.             )
  113.         );
  114.     }
  115.  
  116.     public function verifyTitle($pattern{
  117.         return $this->assertTrue(
  118.             $this->selenium->verifyTitle($pattern),
  119.             sprintf(
  120.                 'verifyTitle failed on [%s]',
  121.                 $pattern
  122.             )
  123.         );
  124.     }
  125. }

Documentation generated on Sun, 04 May 2008 09:22:06 -0500 by phpDocumentor 1.3.0