1. <?php
  2.  
  3. class SessionHelper {
  4.     public static $first;
  5. }
  6. SessionHelper::$first = 0;
  7.  
  8.  
  9.  
  10. class S2p_GoogleTest extends PHPUnit_Extensions_Selenium2TestCase{
  11.  
  12.     function setUp(){
  13.       if (SessionHelper::$first == 0 )
  14.       {
  15.         $this->setBrowser("phantomjs");
  16.         $this->setBrowserUrl("https://www.google.com/");
  17.         $this->setHost("127.0.0.1");
  18.         $this->setPort(4444);
  19.         $this->shareSession(TRUE);
  20.         $this->prepareSession();
  21.         SessionHelper::$first = 1;
  22.       }
  23.     }
  24.    
  25.     public function onNotSuccessfulTest(Exception $e)
  26.     {
  27.         //$this->getStrategy()->notSuccessfulTest();
  28.         throw $e;
  29.     }
  30.    
  31.  
  32.     function testGoogle(){
  33.         $this->url('/');
  34.  
  35.         $this->waitUntil(function($testCase) {
  36.             try {
  37.                 $testCase->byCssSelector("form input[autocomplete=\"off\"]");
  38.                 return true;
  39.             } catch (PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) {}
  40.         }, 8000);
  41.  
  42.         $input = $this->byCssSelector("form input[autocomplete=\"off\"]");
  43.         $input->value("github");
  44.  
  45.         $input = $this->byCssSelector("form input[type=\"submit\"]");
  46.         $input->click();
  47.  
  48.         $this->waitUntil(function($testCase) {
  49.             try {
  50.                 $testCase->byId("res");
  51.                 return true;
  52.             } catch (PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) {}
  53.         }, 8000);
  54.  
  55.         $this->assertTrue((bool)(strpos($this->byTag('body')->text(), 'Build software better, together') !== false));
  56.     }
  57.    
  58.     function testGoogle2(){
  59.         $this->url('/');
  60.  
  61.         $this->waitUntil(function($testCase) {
  62.             try {
  63.                 $testCase->byCssSelector("form input[autocomplete=\"off\"]");
  64.                 return true;
  65.             } catch (PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) {}
  66.         }, 8000);
  67.  
  68.         $input = $this->byCssSelector("form input[autocomplete=\"off\"]");
  69.         $input->value("github");
  70.  
  71.         $input = $this->byCssSelector("form input[type=\"submit\"]");
  72.         $input->click();
  73.  
  74.         $this->waitUntil(function($testCase) {
  75.             try {
  76.                 $testCase->byId("res");
  77.                 return true;
  78.             } catch (PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) {}
  79.         }, 8000);
  80.  
  81.         $this->assertFalse((bool)(strpos($this->byTag('body')->text(), 'Build software better, together') !== false));
  82.     }
  83.    
  84.     function testGoogle3(){
  85.         $this->url('/');
  86.  
  87.         $this->waitUntil(function($testCase) {
  88.             try {
  89.                 $testCase->byCssSelector("form input[autocomplete=\"off\"]");
  90.                 return true;
  91.             } catch (PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) {}
  92.         }, 8000);
  93.  
  94.         $input = $this->byCssSelector("form input[autocomplete=\"off\"]");
  95.         $input->value("github");
  96.  
  97.         $input = $this->byCssSelector("form input[type=\"submit\"]");
  98.         $input->click();
  99.  
  100.         $this->waitUntil(function($testCase) {
  101.             try {
  102.                 $testCase->byId("res");
  103.                 return true;
  104.             } catch (PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) {}
  105.         }, 8000);
  106.  
  107.         $this->assertTrue((bool)(strpos($this->byTag('body')->text(), 'Build software better, together') !== false));
  108.     }
  109.  
  110. }