Beispiel #1
0
 /**
  * Executes JavaScript and waits for it to return true or for the timeout.
  *
  * In this example we will wait for all jQuery ajax requests are finished or 60 secs otherwise.
  *
  * ``` php
  * <?php
  * $I->waitForJS("return $.active == 0;", 60);
  * ?>
  * ```
  *
  * @param string $script
  * @param int $timeout seconds
  */
 public function waitForJS($script, $timeout = 5)
 {
     $condition = function ($wd) use($script) {
         return $wd->executeScript($script);
     };
     $this->webDriver->wait($timeout)->until($condition);
 }
Beispiel #2
0
 /**
  * @param int $timeout
  * @return \WebDriverWait
  */
 private function _wait($timeout = null)
 {
     if ($timeout === null) {
         $timeout = 30;
     }
     return $this->_driver->wait($timeout);
 }
Beispiel #3
0
 public function checkFooterLoads()
 {
     global $lookFor;
     $lookFor = "<!-- EndOfPage --></body>\n</html>";
     $this->webDriver->wait(30, 300)->until(function ($webDriver) {
         global $lookFor;
         return strpos($webDriver->getPageSource(), $lookFor) !== null;
     });
     $this->assertNotNull(strpos($this->webDriver->getPageSource(), $lookFor));
 }
 /**
  * @param $start_time
  *  The timestamp on the user ID we are modifying the program for
  * @param $time_change
  *  $time parameter passed to strtotime
  */
 public function adminChangeProgramVUD($start_time, $time_change)
 {
     $this->webDriver->get($this->url . '/admin/structure/entity-type/checklist/accredited');
     Automation::grabElementByCssSelector($this->webDriver, '.pager-last > a:nth-child(1)')->click();
     // Page to last page
     // And then all of this to wait for the list to refresh...
     $this->webDriver->wait(3, 500)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::cssSelector('.pager-first')));
     $link = $this->webDriver->findElement(WebDriverBy::linkText("Checklist Accredited | Webdriver Program {$start_time}"));
     $link->click();
     $edit_url = $this->webDriver->getCurrentURL() . '/edit';
     $this->webDriver->get($edit_url);
     $vud_box = Automation::grabElementByCssSelector($this->webDriver, '#edit-field-accreditation-valid-until-und-0-value-date');
     $vud = $vud_box->getAttribute('value');
     $vud_date = strtotime($vud);
     $minus1year = strtotime($time_change, $vud_date);
     $minus1year_text = date('M d Y', $minus1year);
     $vud_box->clear();
     $vud_box->sendKeys($minus1year_text);
     $submit = Automation::grabElementByCssSelector($this->webDriver, '#edit-submit');
     $submit->click();
 }
 public static function grabElementByCssSelector(RemoteWebDriver $webDriver, $cssSelector)
 {
     $webDriver->wait(10, 1500)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::cssSelector($cssSelector)));
     $element = $webDriver->findElement(WebDriverBy::cssSelector($cssSelector));
     return $element;
 }
<?php

// An example of using php-webdriver.
require_once 'php_webdriver/__init__.php';
// start Firefox
$host = 'http://172.31.17.231:8910/';
// this is the default
$capabilities = array(WebDriverCapabilityType::BROWSER_NAME => 'phantomjs', WebDriverCapabilityType::ACCEPT_SSL_CERTS => true, WebDriverCapabilityType::JAVASCRIPT_ENABLED => true);
$driver = new RemoteWebDriver($host, $capabilities);
// navigate to 'http://docs.seleniumhq.org/'
$session = $driver->get('http://booking.tigerair.com/Search.aspx');
// Search 'php' in the search box
$from = $driver->findElement(WebDriverBy::cssSelector('select[name="ControlGroupSearchView_AvailabilitySearchInputSearchVieworiginStation1"] option[value="SUB"]'));
$from->click();
$type = $driver->findElement(WebDriverBy::id('ControlGroupSearchView_AvailabilitySearchInputSearchView_OneWay'));
$type->click();
$destination = $driver->findElement(WebDriverBy::cssSelector('select[name="ControlGroupSearchView_AvailabilitySearchInputSearchViewdestinationStation1"] option[value="CGK"]'));
$destination->click();
$tgl = $driver->findElement(WebDriverBy::cssSelector('select[name="ControlGroupSearchView$AvailabilitySearchInputSearchView$DropDownListMarketDay1"] option[value="31"]'));
$tgl->sendKeys('31');
$driver->findElement(WebDriverBy::id('ControlGroupSearchView_ButtonSubmit'))->click();
// wait at most 10 seconds until at least one result is shown
$result = $driver->wait(10)->until(WebDriverExpectedCondition::presenceOfAllElementsLocatedBy(WebDriverBy::className('altRowItem')));
$countresult = count($result);
$arr = array();
for ($i = 0; $i < $countresult; $i++) {
    $arr[$i] = $result[$i]->getText();
}
echo json_encode(array('jadwal' => $arr));
// close the Firefox
$driver->quit();