Example #1
4
/**
 * @param $web
 * @param $input_id
 * @param $value
 * @return mixed
 */
function write_in_input(RemoteWebDriver $web, $input_id, $value)
{
    $input = $web->findElement(WebDriverBy::id($input_id));
    $input->click();
    $web->getKeyboard()->sendKeys($value);
    return $input;
}
Example #2
0
 /**
  * @param $selector WebDriverElement|string
  *
  * @return WebDriverElement
  */
 protected function el($selector)
 {
     if (is_string($selector)) {
         return $this->driver->findElement(WebDriverBy::cssSelector($selector));
     }
     return $selector;
 }
Example #3
0
 /**
  * Get custom window size
  */
 public function testGetCustomWindowSize()
 {
     $capabilities = [WebDriverCapabilityType::BROWSER_NAME => 'firefox'];
     $this->webDriver = RemoteWebDriver::create('http://' . self::HOST . '/wd/hub', $capabilities);
     $this->webDriver->manage()->window()->setSize(new WebDriverDimension(640, 900));
     $this->webDriver->get('http://whatsmy.browsersize.com/');
     $foundWidth = $this->webDriver->findElement(WebDriverBy::id('info_ww'))->getText();
     self::assertTrue($foundWidth == 640 || $foundWidth == 632, $foundWidth);
     $this->webDriver->quit();
 }
Example #4
0
 public function testSearch()
 {
     $this->webDriver->get($this->url);
     $input = $this->webDriver->findElement(WebDriverBy::cssSelector('#lst-ib'));
     $input->sendKeys('yiiframework');
     $this->webDriver->getKeyboard()->pressKey(WebDriverKeys::ENTER);
     // waiting for google load ajax complete.
     sleep(2);
     $response = $this->webDriver->findElement(WebDriverBy::cssSelector('#ires div.srg div.g div.rc h3.r a'))->getText();
     sleep(3);
     $this->assertContains('Yii PHP Framework', $response);
 }
Example #5
0
 public function testSearch()
 {
     $this->webDriver->get($this->url);
     $form = $this->webDriver->findElement(WebDriverBy::cssSelector('form.js-site-search-form'));
     $input = $form->findElement(WebDriverBy::cssSelector('input[type=text].js-site-search-focus'));
     $input->sendKeys('yii 1.1');
     $form->submit();
     $link = $this->webDriver->findElement(WebDriverBy::cssSelector('ul.repo-list li.repo-list-item h3.repo-list-name a'));
     $link->click();
     $repositoryMeta = $this->webDriver->findElement(WebDriverBy::cssSelector('span.repository-meta-content'))->getText();
     sleep(3);
     $this->assertContains('Yii PHP Framework 1.1', $repositoryMeta);
 }
Example #6
0
 /**
  * Find the position and proportion of a DOM element, specified by it's ID.
  * The method inject the
  * JQuery Framework and uses the "noConflict"-mode to get the width, height and offset params.
  *
  * @param string $selector DOM ID/class of the element, which should be screenshotted
  * @return array coordinates of the element
  * @throws \Codeception\Exception\ElementNotFound
  */
 private function getCoordinates($selector = 'body')
 {
     try {
         $this->webDriverModule->waitForElementVisible($selector, 10);
         /** @var WebDriverElement|null $element */
         $element = $this->remoteWebDriver->findElement(WebDriverBy::cssSelector($selector));
     } catch (\Exception $e) {
         throw new ElementNotFound('Element ' . $selector . ' could not be located by WebDriver');
     }
     $elementSize = $element->getSize();
     $elementLocation = $element->getLocation();
     $imageCoords['x'] = $elementLocation->getX();
     $imageCoords['y'] = $elementLocation->getY();
     $imageCoords['width'] = $elementSize->getWidth();
     $imageCoords['height'] = $elementSize->getHeight();
     return $imageCoords;
 }
Example #7
0
 /**
  * Execute debugging
  *
  * @param callback|null $callback
  * @param int $timeout Timeout between checks
  */
 public function execute(callable $callback = null, $timeout = 500000)
 {
     $this->originWindow = $this->driver->getWindowHandle();
     $this->showPopup();
     do {
         $isDebugging = true;
         try {
             $this->processDebugActions($callback);
         } catch (WebDriver\Exception\WebDriverException $e) {
             $isDebugging = false;
         }
         if ((bool) $this->executeScriptFunction('isCheckRequested()')) {
             $this->executeScriptFunction('unmarkCheckRequest()');
             $placeholders = $this->executeScriptFunction('getPlaceholders()');
             $this->driver->switchTo()->window($this->originWindow);
             $this->revertHighlighting();
             $missedLocators = array();
             $isSingleChecker = $this->executeScriptFunction('isSingleChecker()');
             foreach ($this->getDebuggingLocators($placeholders) as $key => $locator) {
                 try {
                     if (count($this->driver->findElements($locator))) {
                         $elements = $isSingleChecker ? array($this->driver->findElement($locator)) : $this->driver->findElements($locator);
                         foreach ($elements as $element) {
                             $this->addHighlightingElement($key, $locator, $element);
                         }
                     } else {
                         $missedLocators[] = $key;
                     }
                 } catch (WebDriver\Exception\WebDriverException $e) {
                     $missedLocators[] = $key;
                 }
             }
             $this->highlightElements();
             $this->executeScriptFunction('highlightLocators(' . json_encode($missedLocators) . ')');
         }
         usleep($timeout);
         $isDebugging = $isDebugging && ($this->isPopupFocused() || self::WINDOW_NAME == (string) $this->driver->executeScript('return window.' . self::WINDOW_VARIABLE . '.name'));
     } while ($isDebugging);
 }
Example #8
0
 public function getHeaderText()
 {
     return $this->webDriver->findElement(WebDriverBy::cssSelector("#page h1"))->getText();
 }
Example #9
0
 public function findElement(WebDriverBy $by)
 {
     return $this->webDriver->findElement($by);
 }
Example #10
0
 public static function find_element($type, $value)
 {
     return self::$webDriver->findElement(WebDriverBy::$type($value));
 }
Example #11
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;
 }