Source for file selenium.php

Documentation is available at selenium.php

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

Documentation generated on Thu, 01 Oct 2009 20:55:47 -0500 by phpDocumentor 1.4.2