Esempio n. 1
1
 /**
  * Sub class of RemoteWebDriver. Overloading its findElement method
  * to make use of RefreshingWebDriverElement.
  */
 public function findElement(WebDriverBy $by)
 {
     // This method is similar to RemoteWebDriver::findElement() but
     // returns an instance of RefreshingWebElement.
     $params = array('using' => $by->getMechanism(), 'value' => $by->getValue());
     $raw_element = $this->execute(DriverCommand::FIND_ELEMENT, $params);
     // Create a RefreshingWebElement and set resources needed to let the
     // element refresh in the future.
     $element = new RefreshingWebElement($this->getExecuteMethod(), $raw_element['ELEMENT']);
     $element->setLocator($by);
     $element->setWebDriver($this);
     return $element;
 }
Esempio n. 2
0
 /**
  * Find all WebDriverElements within the current page using the given
  * mechanism.
  *
  * @param WebDriverBy $by
  * @return RemoteWebElement[] A list of all WebDriverElements, or an empty
  *    array if nothing matches
  * @see WebDriverBy
  */
 public function findElements(WebDriverBy $by)
 {
     $params = array('using' => $by->getMechanism(), 'value' => $by->getValue());
     $raw_elements = $this->execute(DriverCommand::FIND_ELEMENTS, $params);
     $elements = array();
     foreach ($raw_elements as $raw_element) {
         $elements[] = $this->newElement($raw_element['ELEMENT']);
     }
     return $elements;
 }
 /**
  * Main method to handle waits. All public accessible methods in this trait delegates to this method
  * to handle the waiting process with the same algorithm. When the timeout is reached an error gets handled
  * automatically. After the waiting process, the test case will continue.
  *
  * @param string      $type        Whether displayed, enabled or selected.
  * @param WebDriverBy $by          WebDriverBy instance to locate the expected element.
  * @param int         $timeOut     Timeout to wait, when the amount (in seconds) is reached, the test case fails.
  * @param int         $interval    Interval of repeating the waiting condition.
  * @param bool        $expectation Possibility to negate the wait condition.
  *
  * @return $this Same instance for chained method calls.
  */
 private function _waitUntil($type, WebDriverBy $by, $timeOut = 30, $interval = 250, $expectation = true)
 {
     if ($this->isFailed()) {
         return $this;
     }
     if ($type !== 'displayed' && $type !== 'enabled' && $type !== 'selected') {
         throw new \InvalidArgumentException('the $type argument has to be whether "displayed", "enabled" or ' . '"selected"');
     }
     $this->output('Wait ' . $timeOut . ' seconds until an element with ' . $by->getMechanism() . ' "' . $by->getValue() . '" is ' . $type);
     $expectMethod = 'expectsToBe' . ucfirst($type);
     try {
         $this->getWebDriver()->wait($timeOut, $interval)->until(function () use($by, $expectMethod, $expectation) {
             return call_user_func([$this, $expectMethod], $by) === $expectation;
         });
     } catch (TimeOutException $e) {
         $msg = $by->getMechanism() . ' "' . $by->getValue() . '" not found in ' . $timeOut . ' seconds.';
         $this->output($msg);
         $this->exceptionError($msg, $e);
     }
     return $this;
 }
Esempio n. 4
0
 /**
  * @param WebDriverBy $by
  * @return \Facebook\WebDriver\Remote\RemoteWebElement
  */
 public function findElement(WebDriverBy $by)
 {
     $this->logFind($by->getMechanism(), $by->getValue());
     $element = parent::findElement($by);
     $this->logElement($element);
     return $element;
 }