示例#1
1
文件: test.php 项目: luka8088/phops
 function synchronize()
 {
     $t = microtime(true);
     $waiter = new WebDriverWait($this->driver);
     $self = $this;
     $waiter->until(function () use($self) {
         return $self->execute('return typeof(waitForBrowser) == \'undefined\' || !waitForBrowser;');
     }, 'Browser synchronization timeout');
 }
 /**
  * Поиск продукта по названию и переход на страницу
  * @param  String $link_text
  * @return Page_Product
  */
 public function click_product_by_link_text($link_text)
 {
     $wait = new WebDriverWait($this->web_driver, 30);
     $wait->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::linkText($link_text)));
     $this->web_driver->findElement(WebDriverBy::linkText($link_text))->click();
     return new Page_Product($this->web_driver);
 }
 /**
  * @param  RemoteWebDriver $web_driver
  */
 function __construct(RemoteWebDriver $web_driver)
 {
     $this->web_driver = $web_driver;
     // Дожидаемся загрузки первого елемента(кнопка Add to cart)
     $wait = new WebDriverWait($this->web_driver, 30);
     $wait->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::id('MainContent_btn_addToCart')));
     $this->colors = $this->init_select();
     $this->sizes = $this->init_select_sizes();
 }
 /**
  * @param  RemoteWebDriver $web_driver
  */
 function __construct(RemoteWebDriver $web_driver)
 {
     $this->web_driver = $web_driver;
     // Дожидаемся загрузки первого елемента
     $wait = new WebDriverWait($this->web_driver, 30);
     $wait->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::id('MainContent_Email')));
     $this->email = $this->web_driver->findElement(WebDriverBy::id('MainContent_Email'));
     $this->password = $this->web_driver->findElement(WebDriverBy::id('MainContent_Password'));
     $this->remember = $this->web_driver->findElement(WebDriverBy::id('MainContent_RememberMe'));
     $this->submit = $this->web_driver->findElement(WebDriverBy::name('ctl00$MainContent$ctl05'));
 }
示例#5
0
 /**
  * Compares the content of the candidate table with an expected content.
  *
  * @param string $tableName    name of the HTML table.
  * @param string $expectedRows array of candidates that the table should contain.
  *
  * @return void
  */
 private function _assertCandidateTableContents($tableName, $expectedRows)
 {
     if (is_null($expectedRows)) {
         $wait = new WebDriverWait($this->webDriver, 15);
         $wait->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::ClassName('no-result-found-panel')));
         $element = $this->webDriver->findElement(WebDriverBy::ClassName('no-result-found-panel'));
         $this->assertContains('No result found', $element->getText());
     } else {
         $wait = new WebDriverWait($this->webDriver, 15);
         $wait->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::Id('dynamictable')));
         $dataTable = $this->webDriver->findElement(WebDriverBy::Id('dynamictable'));
         $actualRows = $dataTable->findElements(WebDriverBy::xpath('.//tbody//tr'));
         $this->assertEquals(count($actualRows), count($expectedRows), "Number of candidates returned should be " . count($expectedRows) . ", not " . count($actualRows));
         for ($i = 0; $i < count($actualRows); $i++) {
             $elements = $actualRows[$i]->findElements(WebDriverBy::xpath('.//td'));
             $actualColumns = array();
             foreach ($elements as $e) {
                 $actualColumns[] = $e->getText();
             }
             $expectedColumns = $expectedRows[$i];
             $this->assertEquals($actualColumns, $expectedColumns, "Candidates at row {$i} differ");
         }
     }
 }
 /**
  * Wait until current element's text equals specified
  * @param By $locator
  * @param String $targetText
  * @param Integer $timeOutSeconds
  * @throws Nearsoft\SeleniumClient\Exceptions\WebDriverWaitTimeout
  * @return Nearsoft\SeleniumClient\WebElement
  */
 public function waitForElementUntilIsPresentWithSpecificText(By $locator, $targetText, $timeOutSeconds = 5)
 {
     $dynamicElement = null;
     $wait = true;
     $attempts = $timeOutSeconds;
     while ($wait) {
         $currentText = null;
         $webDriverWait = new WebDriverWait($timeOutSeconds);
         $dynamicElement = $webDriverWait->until($this, "findElement", array($locator, true));
         try {
             $currentText = $dynamicElement->getText();
         } catch (SeleniumStaleElementReferenceException $ex) {
             //echo "\nError The Objet Disappear, Wait For Element Until Is Present With Specific Text\n";
         }
         if ($currentText == $targetText) {
             $wait = false;
         } else {
             if ($attempts <= 0) {
                 throw new Exceptions\WebDriverWaitTimeout("Timeout for waitForElementUntilIsPresentAndTextIsChange.");
             }
         }
         sleep(1);
         $attempts = $attempts - 1;
     }
     return $dynamicElement;
 }