Inheritance: extends webdriver\AbstractWebDriver
Esempio n. 1
0
 /**
  * Create a new WebDriver session.
  *
  * @param  string $browser
  * @return Session
  */
 protected function newSession()
 {
     $host = 'http://localhost:4444/wd/hub';
     $this->webDriver = new WebDriver($host);
     $capabilities = [];
     return $this->session = $this->webDriver->session($this->getBrowserName(), $capabilities);
 }
Esempio n. 2
0
 /**
  * Starts driver.
  */
 public function start()
 {
     $this->wdSession = $this->webDriver->session($this->browserName, $this->desiredCapabilities);
     if (!$this->wdSession) {
         throw new DriverException('Could not connect to a Selenium 2 / WebDriver server');
     }
     $this->started = true;
 }
Esempio n. 3
0
 /**
  * Create a new WebDriver session.
  *
  * @param  string $browser
  * @return Session
  */
 protected function newSession()
 {
     $config = $this->getPackageConfig();
     $host = isset($config['selenium']['host']) ? $config['selenium']['host'] : 'http://localhost:4444/wd/hub';
     $this->webDriver = new WebDriver($host);
     $capabilities = [];
     return $this->session = $this->webDriver->session($this->getBrowserName(), $capabilities);
 }
 /**
  * {@inheritdoc}
  */
 public function start()
 {
     try {
         $this->wdSession = $this->webDriver->session($this->browserName, $this->desiredCapabilities);
         $this->applyTimeouts();
     } catch (\Exception $e) {
         throw new DriverException('Could not open connection: ' . $e->getMessage(), 0, $e);
     }
     if (!$this->wdSession) {
         throw new DriverException('Could not connect to a Selenium 2 / WebDriver server');
     }
     $this->started = true;
 }
Esempio n. 5
0
 /**
  * Run tests
  *
  * @param string $file File
  *
  * @return boolean True if success; false otherwise
  */
 public function runTests($file)
 {
     $webdriver = new WebDriver();
     $session = $webdriver->session();
     $classes = $this->getClasses($file);
     $success = true;
     /*
      * count the number of testable methods
      */
     $totalMethods = 0;
     foreach ($classes as $class) {
         $parents = class_parents($class, false);
         if ($parents && in_array('WebDriver\\WebTest\\Script', $parents)) {
             $reflectionClass = new \ReflectionClass($class);
             $reflectionMethods = $reflectionClass->getMethods();
             foreach ($reflectionMethods as $reflectionMethod) {
                 if ($this->isTestableMethod($class, $reflectionMethod)) {
                     $totalMethods++;
                 }
             }
         }
     }
     if ($totalMethods) {
         $i = 0;
         echo "1..{$totalMethods}\n";
         foreach ($classes as $class) {
             $parents = class_parents($class, false);
             if ($parents && in_array('WebDriver\\WebTest\\Script', $parents)) {
                 $class = '\\' . $class;
                 $objectUnderTest = new $class($session);
                 $reflectionClass = new \ReflectionClass($class);
                 $comment = $reflectionClass->getDocComment();
                 $this->dumpComment($comment);
                 $reflectionMethods = $reflectionClass->getMethods();
                 foreach ($reflectionMethods as $reflectionMethod) {
                     if (!$this->isTestableMethod($class, $reflectionMethod)) {
                         continue;
                     }
                     $comment = $reflectionMethod->getDocComment();
                     $this->dumpComment($comment);
                     $directive = $this->getDirective($comment);
                     $description = $method;
                     $reflectionParameters = $reflectionMethod->getParameters();
                     foreach ($reflectionParameters as $reflectionParameter) {
                         if ($reflectionParameter->getName() === 'description' && $reflectionParameter->isDefaultValueAvailable()) {
                             $defaultValue = $reflectionParameter->getDefaultValue();
                             if (is_string($defaultValue)) {
                                 $description = $defaultValue;
                                 break;
                             }
                         }
                     }
                     $diagnostic = null;
                     $rc = false;
                     $i++;
                     try {
                         $objectUnderTest->{$method}();
                         $rc = true;
                     } catch (WebDriverException\Curl $e) {
                         $success = false;
                         echo 'Bail out! ' . $e->getMessage() . "\n";
                         break 2;
                     } catch (\Exception $e) {
                         $success = false;
                         $diagnostic = $e->getMessage();
                         // @todo check driver capability for screenshot
                         $screenshot = $session->screenshot();
                         if (!empty($screenshot)) {
                             $imageName = basename($file) . ".{$i}.png";
                             file_put_contents($imageName, base64_decode($screenshot));
                         }
                     }
                     echo ($rc ? 'ok' : 'not ok') . " {$i} - {$description}" . ($directive ? " # {$directive}" : '') . "\n";
                     $this->dumpDiagnostic($diagnostic);
                 }
                 unset($objectUnderTest);
             }
         }
     } else {
         echo "0..0\n";
     }
     if ($session) {
         $session->close();
     }
     return $success;
 }
Esempio n. 6
0
 public function setUp()
 {
     $wd_host = 'http://localhost:4444/wd/hub';
     $web_driver = new WebDriver($wd_host);
     $this->session = $web_driver->session('firefox');
 }