public function testProcessOrder() { $this->driver->get($this->getTestPath('/admin')); $this->driver->findElement(WebDriverBy::id('username'))->sendKeys('admin'); $this->driver->findElement(WebDriverBy::id('login'))->sendKeys('P@ssw0rd'); $this->driver->findElement(WebDriverBy::className('form-button'))->click(); $this->driver->findElement(WebDriverBy::xpath("//span[text()='Sales']"))->click(); $this->driver->findElement(WebDriverBy::xpath("//span[text()='Orders']"))->click(); $this->driver->wait()->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::id('sales_order_grid_filter_real_order_id'))); $this->driver->findElement(WebDriverBy::id('sales_order_grid_filter_real_order_id'))->sendKeys('ICANN-D10000014'); $this->driver->findElement(WebDriverBy::id('sales_order_grid_filter_real_order_id'))->sendKeys(WebDriverKeys::ENTER); sleep(3); $this->driver->findElement(WebDriverBy::xpath("//html/body/div[1]/div[2]/div/div[3]/div/div[2]/div/table/tbody/tr[1]/td[2]"))->click(); $this->driver->findElement(WebDriverBy::xpath("//span[text()='Invoice']"))->click(); $this->driver->findElement(WebDriverBy::xpath("//span[text()='Submit Invoice']"))->click(); $this->driver->findElement(WebDriverBy::xpath("//span[text()='Ship']"))->click(); $this->driver->findElement(WebDriverBy::xpath("//span[text()='Add Tracking Number']"))->click(); $this->driver->findElement(WebDriverBy::id("trackingC1"))->click(); $this->driver->findElement(WebDriverBy::xpath("//select[@id='trackingC1']/option[@value='fedex']"))->click(); $this->driver->findElement(WebDriverBy::id("trackingT1"))->sendKeys('FEDEX'); $this->driver->findElement(WebDriverBy::id("trackingN1"))->sendKeys('Tracking0001'); $this->driver->findElement(WebDriverBy::id("send_email"))->click(); $this->driver->findElement(WebDriverBy::xpath("//span[text()='Submit Shipment']"))->click(); sleep(5); }
/** * Set value of Select2 element * @param string $originalId ID of original select/input element * @param string $value Value to be selected * @param bool $multiSelect OPTIONAL Is the select multiselect? * @todo Support multiple values for multiselects */ public function setSelect2Value($originalId, $value, $multiSelect = false) { $select2selector = '#s2id_' . $originalId; // Wait for select2 to appear $select2link = $this->tc->wd->wait()->until(\WebDriverExpectedCondition::presenceOfElementLocated(\WebDriverBy::cssSelector($select2selector . ' ' . ($multiSelect ? 'input' : 'a')))); // Click on element to open dropdown - to copy users behavior $select2link->click(); $this->log('Sending keys to select2: %s', $value); // Insert searched term into s2 generated input $this->tc->wd->findElement(\WebDriverBy::cssSelector($multiSelect ? $select2selector . ' input' : '#select2-drop input'))->sendKeys($value); // Wait until result are rendered (or maybe loaded with ajax) $firstResult = $this->tc->wd->wait()->until(\WebDriverExpectedCondition::presenceOfElementLocated(\WebDriverBy::cssSelector('.select2-drop .select2-result.select2-highlighted'))); $this->log('Dropdown detected, selecting the first result: %s', $firstResult->getText()); // Select first item in results $firstResult->click(); }
public function testNavBar() { $this->driver->get('http://localhost:80/index.php'); $menu = $this->driver->findElement(WebDriverBy::id('navcontent'))->findElement(WebDriverBy::tagName('ul')); //assert that we are not in mobile mode when maximized $this->driver->manage()->window()->maximize(); $this->assertFalse(strpos($menu->getAttribute("class"), "mobilemenu")); //assert that we are in mobile mode with a small window $this->driver->manage()->window()->setSize(new WebDriverDimension(450, 600)); $this->driver->wait(2, 250)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::className("mobilemenu"))); $this->assertContains("mobilemenu", $menu->getAttribute("class")); //assert that reverting back clears mobile mode $this->driver->manage()->window()->maximize(); //$this->driver->wait(2, 250)->until(WebDriverExpectedCondition::not(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::className("mobilemenu")))); sleep(1); $this->assertFalse(strpos($menu->getAttribute("class"), "mobilemenu")); }
function testDataDictSearchKeywordFilters() { $this->webDriver->get($this->url . "/datadict/"); $this->webDriver->wait(120, 1000)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::Name("keyword"))); $searchKey = $this->webDriver->findElements(WebDriverBy::Name("keyword")); switch (count($searchKey)) { case 1: break; case 0: $this->fail("Could not find search keyword field"); return; default: $this->fail("Too many search keyword fields."); return; } $searchKey[0]->sendKeys("NotRealMAGICNUMBER335"); $searchButton = $this->webDriver->findElement(WebDriverBy::Name("filter")); $searchButton->click(); $this->markTestSkipped("Data Dict test not yet updated for React"); /* try { while (true) { $oldBody->isDisplayed(); } } catch(Exception $e) { $this->webDriver->executescript("document.documentElement.outerHTML"); } */ $rows = $this->webDriver->findElements(WebDriverBy::cssSelector("table tbody tr")); $this->assertTrue(count($rows) == 1, "Incorrect number of rows returned when filtering for keyword on datadict" . print_r($rows, true)); $cols = $this->webDriver->findElements(WebDriverBy::cssSelector("table tbody tr td")); // Rownumber $this->assertEquals($cols[0]->getText(), "1"); // SourceFrom $this->assertEquals($cols[1]->getText(), "nowhere"); // Name $this->assertEquals($cols[2]->getText(), "TestParameterNotRealMAGICNUMBER335"); // SourceField $this->assertEquals($cols[3]->getText(), "imaginary"); // Description $this->assertEquals($cols[4]->getText(), "I am a fake description used only for testing you should not see me. MAGICNUMBER335"); }
protected function upload_image($path) { self::$driver->get(wordpress('/wp-admin/media-new.php?browser-uploader&flash=0')); $links = self::$driver->findElements(WebDriverBy::xpath('//a[text()="browser uploader"]')); if (count($links) > 0) { $link = $links[0]; if ($link->isDisplayed()) { $link->click(); } } self::$driver->wait(2)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::name('async-upload'))); $file_input = self::$driver->findElement(WebDriverBy::name('async-upload')); $file_input->setFileDetector(new LocalFileDetector()); $file_input->sendKeys($path); self::$driver->findElement(WebDriverBy::xpath('//input[@value="Upload"]'))->click(); $path_elements = explode('/', $path); $file_name = array_pop($path_elements); $image_elements = explode('.', $file_name); $image_name = $image_elements[0]; self::$driver->wait(2)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::xpath('//img[contains(@src, "' . $image_name . '")]'))); }
/** * Waits for element to appear on page for $timeout seconds to pass. * If element not appears, timeout exception is thrown. * * ``` php * <?php * $I->waitForElement('#agree_button', 30); // secs * $I->click('#agree_button'); * ?> * ``` * * @param $element * @param int $timeout seconds * @throws \Exception */ public function waitForElement($element, $timeout = 10) { $condition = null; if (Locator::isID($element)) { $condition = \WebDriverExpectedCondition::presenceOfElementLocated(\WebDriverBy::id(substr($element, 1))); } if (!$condition and Locator::isCSS($element)) { $condition = \WebDriverExpectedCondition::presenceOfElementLocated(\WebDriverBy::cssSelector($element)); } if (Locator::isXPath($element)) { $condition = \WebDriverExpectedCondition::presenceOfElementLocated(\WebDriverBy::xpath($element)); } if (!$condition) { throw new \Exception("Only CSS or XPath allowed"); } $this->webDriver->wait($timeout)->until($condition); }
/** * 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"); } } }
/** * Waits up to $timeout seconds for an element to appear on the page. * If the element doesn't appear, a timeout exception is thrown. * * ``` php * <?php * $I->waitForElement('#agree_button', 30); // secs * $I->click('#agree_button'); * ?> * ``` * * @param $element * @param int $timeout seconds * @throws \Exception */ public function waitForElement($element, $timeout = 10) { $condition = \WebDriverExpectedCondition::presenceOfElementLocated($this->getLocator($element)); $this->webDriver->wait($timeout)->until($condition); }
/** * @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; }
public function testStatusPresenseFail() { $this->set_api_key('INVALID123'); self::$driver->wait(2)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::cssSelector('#tiny-compress-status p'))); $elements = self::$driver->findElement(WebDriverBy::id('tiny-compress-status'))->findElements(WebDriverBy::tagName('p')); $statuses = array_map('innerText', $elements); $this->assertContains('API connection unsuccessful', $statuses); }
/** * Pause for a given number of seconds * * @param int $timeout_in_second * @return $this * @throws NoSuchElementException * @author Ronan Chilvers <*****@*****.**> */ public function waitForSelector($selector, $timeout_in_second = 30, $interval_in_millisecond = 250) { $by = $this->getWebDriverBy($selector); $this->wait($timeout_in_second, $interval_in_millisecond)->until(\WebDriverExpectedCondition::presenceOfElementLocated($by)); return $this; }
public function testShouldShowSavings() { reset_webservice(); $this->set_api_key('PNG123'); $this->upload_image(dirname(__FILE__) . '/../fixtures/input-example.png'); self::$driver->get(wordpress('/wp-admin/options-media.php')); self::$driver->wait(2)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::cssSelector('#tiny-compress-savings p'))); $elements = self::$driver->findElement(WebDriverBy::id('tiny-compress-savings'))->findElements(WebDriverBy::tagName('p')); $statuses = array_map('innerText', $elements); $this->assertContains('You have saved a total of 53.0 kB on images!', $statuses); }