/** * @param RemoteWebElement $fieldContext * @param array $testValues An array of arrays that contains the values to validate. * * First value is the input value * * second value is the value that is expected after the validation * * optional third value is the "internal" value like required for date fields (value is internally * represented by a timestamp). If this value is not defined the second value will be used. * Example for field with alpha validation: [['foo', 'foo'], ['bar1'], ['bar']] * Example for field with date validation: [['29-01-2016', '29-01-2016', '1454025600']] */ public function fillSeeDeleteInputField(RemoteWebElement $fieldContext, array $testValues) { $I = $this->tester; $I->wantTo('Fill field, check the fieldvalue after evaluation and delete the value.'); $inputField = $fieldContext->findElement(\WebDriverBy::xpath('.//*/input[@data-formengine-input-name]')); $internalInputField = $fieldContext->findElement(\WebDriverBy::xpath('.//*/input[@name="' . $inputField->getAttribute('data-formengine-input-name') . '"]')); foreach ($testValues as $comment => $testValue) { if (!empty($comment)) { $I->comment($comment); } $I->comment('Fill the field and switch focus to trigger validation.'); $I->fillField($inputField, $testValue[0]); // change the focus to trigger validation $fieldContext->sendKeys("\n"); $I->comment('Test value of "visible" field'); $I->canSeeInField($inputField, $testValue[1]); $I->comment('Test value of the internal field'); $I->canSeeInField($internalInputField, isset($testValue[2]) ? $testValue[2] : $testValue[1]); } $inputField->findElement(\WebDriverBy::xpath('parent::*/button[@class="close"]'))->click(); // change the context from the field $fieldContext->sendKeys("\n"); $I->canSeeInField($inputField, ''); $I->canSeeInField($internalInputField, ''); }
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); }
public function testShouldPersistNoSizes() { $elements = self::$driver->findElements(WebDriverBy::xpath('//input[@type="checkbox" and starts-with(@name, "tinypng_sizes") and @checked="checked"]')); foreach ($elements as $element) { $element->click(); } self::$driver->findElement(WebDriverBy::tagName('form'))->submit(); $elements = self::$driver->findElements(WebDriverBy::xpath('//input[@type="checkbox" and starts-with(@name, "tinypng_sizes") and @checked="checked"]')); $this->assertEquals(0, count(array_map('elementName', $elements))); }
public function testShouldPersistSizes() { $element = self::$driver->findElement(WebDriverBy::id('tinypng_sizes_medium')); $element->click(); self::$driver->findElement(WebDriverBy::tagName('form'))->submit(); $elements = self::$driver->findElements(WebDriverBy::xpath('//input[@type="checkbox" and starts-with(@name, "tinypng_sizes") and @checked="checked"]')); $size_ids = array_map('elementName', $elements); $this->assertContains('tinypng_sizes[thumbnail]', $size_ids); $this->assertNotContains('tinypng_sizes[medium]', $size_ids); $this->assertContains('tinypng_sizes[large]', $size_ids); }
/** * Checks the contents of the session table and compares it against an expected * result. * * @param array $expectedSessions list of all the expected sessions. * * @return void */ private function _validateSessionTableContents($expectedSessions) { $sessionTable = $this->webDriver->findElements(WebDriverBy::ClassName('dynamictable')); $actualSessions = $sessionTable[1]->findElements(WebDriverBy::xpath('.//tbody//tr')); $this->assertEquals(count($actualSessions), count($expectedSessions), "Number of visits should be " . count($expectedSessions) . ", not " . count($actualSessions)); for ($i = 0; $i < count($actualSessions); $i++) { $elements = $actualSessions[$i]->findElements(WebDriverBy::xpath('.//td')); $actualSession = array(); foreach ($elements as $e) { $actualSession[] = $e->getText(); } $this->assertEquals($expectedSessions[$i], $actualSession, "Sessions at row {$i} differ"); } }
public function testSearch() { $this->webDriver->get($this->url); // find search field by its id $search = $this->webDriver->findElement(WebDriverBy::xpath('html/body/div[1]/div[1]/div/div[2]/form/label')); $search->click(); // typing into field $this->webDriver->getKeyboard()->sendKeys('php-webdriver'); // pressing "Enter" $this->webDriver->getKeyboard()->pressKey(WebDriverKeys::ENTER); $firstResult = $this->webDriver->findElement(WebDriverBy::cssSelector('li.repo-list-item:nth-child(1) > h3:nth-child(2) > a:nth-child(1)')); $firstResult->click(); // we expect that facebook/php-webdriver was the first result $this->assertContains("php-webdriver", $this->webDriver->getTitle()); $this->assertEquals('https://github.com/facebook/php-webdriver', $this->webDriver->getCurrentURL()); $this->assertElementNotFound(WebDriverBy::className('avatar')); }
protected function enable_compression_sizes($sizes) { self::$driver->get(wordpress('/wp-admin/options-media.php')); $elements = self::$driver->findElements(WebDriverBy::xpath('//input[starts-with(@id, "tinypng_sizes_")]')); foreach ($elements as $element) { $size = str_replace('tinypng_sizes_', '', $element->getAttribute('id')); if (in_array($size, $sizes)) { if (!$element->getAttribute('checked')) { $element->click(); } } else { if ($element->getAttribute('checked')) { $element->click(); } } } self::$driver->findElement(WebDriverBy::tagName('form'))->submit(); }
public function testCalendarEntryEditTest() { //edit date $row = self::$webDriver->findElement(WebDriverBy::xpath("//tr[contains(text(), " . "CalendarTestBooking" . ")]/td[8]")); $row->findElement(WebDriverBy::linkText('Bearbeiten'))->click(); self::$webDriver->findElement(WebDriverBy::id('from[date]_d'))->sendKeys(date('d') + 1); self::$webDriver->findElement(WebDriverBy::id('from[date]_m'))->sendKeys(date('m')); self::$webDriver->findElement(WebDriverBy::id('from[date]_y'))->sendKeys(date('Y')); self::$webDriver->findElement(WebDriverBy::id('from[time]_h'))->sendKeys("14"); self::$webDriver->findElement(WebDriverBy::id('from[time]_m'))->sendKeys("00"); self::$webDriver->findElement(WebDriverBy::id('to[date]_d'))->sendKeys(date('d') + 1); self::$webDriver->findElement(WebDriverBy::id('to[date]_m'))->sendKeys(date('m')); self::$webDriver->findElement(WebDriverBy::id('to[date]_y'))->sendKeys(date('Y')); self::$webDriver->findElement(WebDriverBy::id('to[time]_h'))->sendKeys("15"); self::$webDriver->findElement(WebDriverBy::id('to[time]_m'))->sendKeys("10"); self::$webDriver->findElement(WebDriverBy::name('cmd[saveEditBooking]'))->click(); $this->assertContains("Buchung erfolgreich bearbeitet", self::$helper->getSuccMessage()); self::$webDriver->findElement(WebDriverBy::linkText('Zurück zu den Buchungen'))->click(); // check calendar for booking self::$webDriver->findElement(WebDriverBy::linkText(self::$helper->getCurrentMonth() . ' ' . date('Y')))->click(); $this->assertContains("14:00 CalendarTestBooking", self::$webDriver->findElement(webDriverBy::cssSelector("div.ilTabContentOuter.ilTabsTableCell"))->getText()); // go back to bookings self::$webDriver->findElement(WebDriverBy::linkText('Termine'))->click(); }
/** * @param $page * @param $selector * @return array */ protected function match($page, $selector) { $nodes = array(); if (Locator::isID($selector)) { $nodes = $page->findElements(\WebDriverBy::id(substr($selector, 1))); } if (!empty($nodes)) { return $nodes; } if (Locator::isCSS($selector)) { $nodes = $page->findElements(\WebDriverBy::cssSelector($selector)); } if (!empty($nodes)) { return $nodes; } if (Locator::isXPath($selector)) { $nodes = $page->findElements(\WebDriverBy::xpath($selector)); } return $nodes; }
function activate_plugin($driver) { $driver->get(wordpress('/wp-admin/plugins.php')); $activate_links = $driver->findElements(WebDriverBy::xpath('//a[starts-with(@href, "plugins.php?action=activate&plugin=tinypng-image-compression")]')); $deactivate_links = $driver->findElements(WebDriverBy::xpath('//a[starts-with(@href, "plugins.php?action=deactivate&plugin=tinypng-image-compression")]')); if (count($activate_links) > 0) { $activate_links[0]->click(); } elseif (count($deactivate_links) > 0) { print "Plugin already activated.\n"; } else { var_dump($driver->getPageSource()); throw new UnexpectedValueException('Activating plugin failed.'); } }
public function annualReportCompleteProgramEvaluation() { $prog_eval_cont_imp_link = Automation::grabElementByCssSelector($this->webDriver, '.entity-field-collection-item > div:nth-child(1) > table:nth-child(2) > tbody:nth-child(2) > tr:nth-child(7) > td:nth-child(4) > a:nth-child(1) > span:nth-child(1)'); $prog_eval_cont_imp_link->click(); $first_select_box = $this->webDriver->findElement(WebDriverBy::xpath('//*/select')); $id = $first_select_box->getAttribute('id'); print $id; $id_array = explode('-', $id); $webform_ident = $id_array[3]; Automation::grabElementByCssSelector($this->webDriver, "#edit-submitted-criterion-{$webform_ident}-criterion-{$webform_ident}-response-{$webform_ident}-meets-standard-1")->click(); $one_year_ago = strtotime('-1 year', time()); $month = date('n', $one_year_ago); $day = intval(date('d', $one_year_ago)); $year = date('Y', $one_year_ago); $select = new WebDriverSelect(Automation::grabElementByCssSelector($this->webDriver, "#edit-submitted-criterion-{$webform_ident}-criterion-{$webform_ident}-response-criterion-{$webform_ident}-last-program-evaluation-month")); $select->selectByValue($month); $select = new WebDriverSelect(Automation::grabElementByCssSelector($this->webDriver, "#edit-submitted-criterion-{$webform_ident}-criterion-{$webform_ident}-response-criterion-{$webform_ident}-last-program-evaluation-day")); $select->selectByValue($day); $select = new WebDriverSelect(Automation::grabElementByCssSelector($this->webDriver, "#edit-submitted-criterion-{$webform_ident}-criterion-{$webform_ident}-response-criterion-{$webform_ident}-last-program-evaluation-year")); $select->selectByValue($year); Automation::grabElementByCssSelector($this->webDriver, "#edit-submitted-criterion-{$webform_ident}-criterion-{$webform_ident}-response-criterion-{$webform_ident}-evidence-forms-surveys-select-1")->click(); $select = new WebDriverSelect(Automation::grabElementByCssSelector($this->webDriver, "#edit-submitted-criterion-{$webform_ident}-criterion-{$webform_ident}-response-criterion-{$webform_ident}-question-4-when-month")); $select->selectByValue($month); $select = new WebDriverSelect(Automation::grabElementByCssSelector($this->webDriver, "#edit-submitted-criterion-{$webform_ident}-criterion-{$webform_ident}-response-criterion-{$webform_ident}-question-4-when-day")); $select->selectByValue($day); $select = new WebDriverSelect(Automation::grabElementByCssSelector($this->webDriver, "#edit-submitted-criterion-{$webform_ident}-criterion-{$webform_ident}-response-criterion-{$webform_ident}-question-4-when-year")); $select->selectByValue($year); Automation::grabElementByCssSelector($this->webDriver, "#edit-submitted-criterion-{$webform_ident}-criterion-{$webform_ident}-response-criterion-{$webform_ident}-question-4-how-select-1")->click(); Automation::grabElementByCssSelector($this->webDriver, "#edit-submitted-criterion-10f03-criterion-10f03-response-criterion-10f03-program-meets-standard-1")->click(); Automation::grabElementByCssSelector($this->webDriver, "#edit-submitted-criterion-10f03-criterion-10f03-response-criterion-10f03-two-program-improvement-goals")->sendKeys('1234'); Automation::grabElementByCssSelector($this->webDriver, "#edit-submitted-criterion-10f03-criterion-10f03-response-criterion-10f03-professional-development-activity")->sendKeys('4321'); Automation::grabElementByCssSelector($this->webDriver, '.webform-submit')->click(); }
/** * Assert if the given menu is selected. * @param $text */ public function assertMenuIsSelected($text) { $elt = $this->driver->findElement(WebDriverBy::xpath("//div[@id = 'js_menu']//a[text()='{$text}']/..")); $this->assertElementHasClass($elt, 'selected'); }
/** * Find all elements by a XPath selector * @param $text * @return mixed * @throws NoSuchElementException */ public function findAllByXpath($xpath) { return $this->driver->findElements(WebDriverBy::xpath($xpath)); }
public function testWebDriverByLocators() { $this->module->amOnPage('/login'); $this->module->seeElement(WebDriverBy::id('submit-label')); $this->module->seeElement(WebDriverBy::name('password')); $this->module->seeElement(WebDriverBy::className('optional')); $this->module->seeElement(WebDriverBy::cssSelector('form.global_form_box')); $this->module->seeElement(WebDriverBy::xpath(\Codeception\Util\Locator::tabIndex(4))); $this->module->fillField(WebDriverBy::name('password'), '123456'); $this->module->amOnPage('/form/select'); $this->module->selectOption(WebDriverBy::name('age'), 'child'); $this->module->amOnPage('/form/checkbox'); $this->module->checkOption(WebDriverBy::name('terms')); $this->module->amOnPage('/'); $this->module->seeElement(WebDriverBy::linkText('Test')); $this->module->click(WebDriverBy::linkText('Test')); $this->module->seeCurrentUrlEquals('/form/hidden'); }
/** * Tests the effects of changing a floorplan which is assigend to a room * @test */ public function testAssignmentEffectsOfFloorplans() { self::$webDriver->findElement(WebDriverBy::linkText('Gebäudeplan'))->click(); self::$helper->createFloorPlan('Test_A', self::$test_file_absolut_path . 'sucess.jpg', 'Test'); //#1 Use a new floorplan by creating a room with it self::$helper->createRoom('123', '1', '20', "TEST", "Test_A", array()); self::$webDriver->findElement(WebDriverBy::linkText(' Zurück zu allen Räumen '))->click(); self::$webDriver->findElement(WebDriverBy::linkText('123'))->click(); $text = self::$webDriver->findElement(WebDriverBy::xpath("//option[text()='Test_A']"))->getAttribute('selected'); $this->assertEquals(false, empty($text), '#1 Using a new floorplan on a room has failed!'); //#2 Change a floorplan which is assigend to a room self::$webDriver->findElement(WebDriverBy::linkText('Gebäudeplan'))->click(); $menu = self::$webDriver->findElement(WebDriverBy::xpath("//div[@id='il_center_col']/div[4]/table/tbody/tr[2]/td[4]")); $menu->findElement(WebDriverBy::linkText('Aktionen'))->click(); $menu->findElement(WebDriverBy::linkText('Bearbeiten'))->click(); self::$webDriver->findElement(WebDriverBy::id('title'))->clear(); self::$webDriver->findElement(WebDriverBy::id('title'))->sendKeys('Test_B'); self::$webDriver->findElement(WebDriverBy::id('file_mode_replace'))->click(); self::$webDriver->findElement(WebDriverBy::id('upload_file'))->sendKeys(self::$test_file_absolut_path . 'sucess.jpg'); self::$webDriver->findElement(WebDriverBy::name('cmd[update]'))->click(); self::$webDriver->findElement(WebDriverBy::linkText('Räume'))->click(); self::$webDriver->findElement(WebDriverBy::linkText('123'))->click(); $text = self::$webDriver->findElement(WebDriverBy::xpath("//option[text()='Test_B']"))->getAttribute('selected'); $this->assertEquals(false, empty($text), '#2 Changing an assigend floorplan has failed!'); //#3 Delete an assigned floorplan self::$webDriver->findElement(WebDriverBy::linkText('Gebäudeplan'))->click(); self::$helper->deleteAllFloorPlans(); self::$webDriver->findElement(WebDriverBy::linkText('Räume'))->click(); self::$webDriver->findElement(WebDriverBy::linkText('123'))->click(); $text = self::$webDriver->findElement(WebDriverBy::xpath("//option[text()=' - Keine Zuordnung - ']"))->getAttribute('selected'); $this->assertEquals(false, empty($text), '#3 Deleting an assigend floorplan has failed!'); self::$helper->deleteAllRooms(); }
/** * Precondition: No priviledge classes * Postcondition: No priviledge classes * @test */ public function createAndDeleteClassesTest() { //#1 Test Cancel of a creation self::$webDriver->findElement(WebDriverBy::linkText('Privilegien'))->click(); self::$webDriver->findElement(WebDriverBy::linkText(' Neue Klasse anlegen '))->click(); self::$webDriver->findElement(WebDriverBy::name('cmd[showPrivileges]'))->click(); try { self::$webDriver->findElement(WebDriverBy::linkText(' Neue Klasse anlegen ')); } catch (Exception $ex) { $this->fail("#1: Cancel of a new privilege class does not link to pivilege class overview: " . $ex); } //#2 Create a Privilege Class self::$helper->createPrivilegClass("Test_A", "Test_A", "User", 1); try { self::$webDriver->findElement(WebDriverBy::linkText("Test_A ⇒ User")); } catch (Exception $ex) { $this->fail("#2.1: Creation of a new privilege class with ILIAS-role does not work: " . $ex); } self::$helper->createPrivilegClass("Test_C", "Test_C", "Keine", 5); try { self::$webDriver->findElement(WebDriverBy::linkText("Test_C")); } catch (Exception $ex) { $this->fail("#2.2: Creation of a new privilege class without ILIAS-role does not work: " . $ex); } self::$helper->deletePrivilegClass("Test_C"); //#3 Create an existing privilege class self::$helper->createPrivilegClass("Test_A", "Test_A", "User", 1); try { self::$webDriver->findElement(WebDriverBy::className("ilFailureMessage")); } catch (Exception $ex) { $this->fail("#3: Creation of an existing privilege class with ILIAS-role works: " . $ex); } //#4 Create a privilege class that gets user-rolls from the same role as another already existing class. self::$webDriver->findElement(WebDriverBy::name('cmd[showPrivileges]'))->click(); self::$helper->createPrivilegClass("Test_B", "Test_B", "User", 0); try { self::$webDriver->findElement(WebDriverBy::linkText("Test_B ⇒ User")); } catch (Exception $ex) { $this->fail("#4: Creation of a new privilege class with same ILIAS-role as another does not work: " . $ex); } self::$helper->deletePrivilegClass("Test_B ⇒ User"); //#5 Create an empty privileges class self::$helper->createPrivilegClass("", "Test_C", "Guest", 2); try { self::$webDriver->findElement(WebDriverBy::className("ilFailureMessage")); } catch (Exception $ex) { $this->fail("#5: Creation of a no-name privilege class seems to be allowed: " . $ex); } self::$webDriver->findElement(WebDriverBy::name("cmd[showPrivileges]"))->click(); //#6 Delete Test_A class, none should be left self::$webDriver->findElement(WebDriverBy::linkText("Test_A ⇒ User"))->click(); self::$webDriver->findElement(WebDriverBy::linkText(' Klasse löschen '))->click(); self::$webDriver->findElement(WebDriverBy::name('cmd[renderEditClassForm]'))->click(); try { self::$webDriver->findElement(WebDriverBy::linkText(' Klasse löschen '))->click(); } catch (Exception $ex) { $this->fail("#6.1: Click cancel in the delete confirmation does not redirect to edit of the class " . $ex); } self::$webDriver->findElement(WebDriverBy::linkText('Zurück zu den Klasseneigenschaften'))->click(); try { self::$webDriver->findElement(WebDriverBy::linkText(' Klasse löschen '))->click(); } catch (Exception $ex) { $this->fail("#6.2: Click backtab in the delete confirmation does not redirect to edit of the class " . $ex); } self::$webDriver->findElement(WebDriverBy::name('cmd[deleteClass]'))->click(); try { self::$webDriver->findElement(WebDriverBy::xpath("//td[text()='Keine Klassen vorhanden']"))->click(); } catch (Exception $ex) { $this->fail("#6.3: Deleting a privileges class does not delete it " . $ex); } }
/** * @test */ public function testBookingattributeManagement() { //#1 Create a new booking attribute self::$helper->createBookingAttribute("Book_A"); try { self::$webDriver->findElement(WebDriverBy::id('radio_action_mode_rename_attribute'))->click(); self::$webDriver->findElement(WebDriverBy::xpath("//option[text()='Book_A']")); } catch (Exception $ex) { $this->fail("#1 Creation of a new booking attribute has failed" . $ex); } //#2 Create an empty booking attribute self::$helper->createBookingAttribute(""); try { self::$webDriver->findElement(WebDriverBy::className("ilFailureMessage")); } catch (Exception $ex) { $this->fail("#3 Creation of an empty booking attribute has succeded" . $ex); } //#3 Create an existing booking attribute self::$helper->createBookingAttribute("Book_A"); try { self::$webDriver->findElement(WebDriverBy::className("ilFailureMessage")); } catch (Exception $ex) { $this->fail("#3 Creation of an existing booking attribute has succeded" . $ex); } //#4 Create a new booking attribute with html tags self::$helper->createBookingAttribute("<b><u>Book_B</u></b>"); try { self::$webDriver->findElement(WebDriverBy::id('radio_action_mode_rename_attribute'))->click(); self::$webDriver->findElement(WebDriverBy::xpath("//option[text()='Book_B']")); } catch (Exception $ex) { $this->fail("#5 Creation of a new booking attribute with HTML has failed" . $ex); } self::$helper->changeBookingAttribute('Book_B', 'Book_B'); //#5 Check if creation bookings GUI has the new attributes self::$helper->createRoom('123', 1, 20, "TEST", " - Keine Zuordnung - ", array()); self::$helper->searchForRoomByAll("123", "", "", "", date('Y') + 1, '23', '50', '23', '55', array()); self::$webDriver->findElement(WebDriverBy::linkText("Buchen"))->click(); try { self::$webDriver->findElement(WebDriverBy::xpath("//label[text()='Book_A']")); self::$webDriver->findElement(WebDriverBy::xpath("//label[text()='Book_B']")); } catch (Exception $ex) { $this->fail("#5 Creation booking GUI does not have created attributes" . $ex); } self::$helper->doABooking('TEST', "", "", "", "", "", "", "", "", "", "", false, "", false, array(), array('Book_A' => 'TEST A', 'Book_B' => 'TEST B')); //#6 Change name of a booking attribute into a new self::$helper->changeBookingAttribute('Book_A', 'Book_C'); try { self::$webDriver->findElement(WebDriverBy::id('radio_action_mode_rename_attribute'))->click(); self::$webDriver->findElement(WebDriverBy::xpath("//option[text()='Book_C']")); } catch (Exception $ex) { $this->fail("#6 Renaming a booking attribute has failed" . $ex); } //#7 Change name of a booking attribute into nothing self::$helper->changeBookingAttribute('Book_C', ''); try { self::$webDriver->findElement(WebDriverBy::className("ilFailureMessage")); } catch (Exception $ex) { $this->fail("#7 Changing a booking attribute to no name has succeded" . $ex); } //#8 Change name of a booking attribute into existing one self::$helper->changeBookingAttribute('Book_C', 'Book_B'); try { self::$webDriver->findElement(WebDriverBy::className("ilFailureMessage")); } catch (Exception $ex) { $this->fail("#8 Changing a booking attribute to an existing name has succeded " . $ex); } //#9 Change name of a booking attribute into the same self::$helper->changeBookingAttribute('Book_C', 'Book_C'); try { self::$webDriver->findElement(WebDriverBy::id('radio_action_mode_rename_attribute'))->click(); self::$webDriver->findElement(WebDriverBy::xpath("//option[text()='Book_C']")); } catch (Exception $ex) { $this->fail("#9 Renaming a booking attribute to his old name has failed " . $ex); } //#10 Check if changes did not effect the bookings self::$webDriver->findElement(WebDriverBy::linkText('Termine'))->click(); self::$webDriver->findElement(WebDriverBy::id('ilChkboxListAnchorText_tbl_roomobj'))->click(); try { self::$webDriver->findElement(WebDriverBy::xpath("//td[text()='Book_C']")); self::$webDriver->findElement(WebDriverBy::xpath("//td[text()='Book_B']")); $attr_inputs = self::$webDriver->findElements(WebDriverBy::name("tblfsroomobj[]")); foreach ($attr_inputs as $input) { if (empty($input->getAttribute('checked'))) { $input->click(); } } self::$webDriver->findElement(WebDriverBy::name("cmd[showBookings]"))->click(); self::$webDriver->findElement(WebDriverBy::xpath("//td[contains(text(),'TEST A')]")); self::$webDriver->findElement(WebDriverBy::xpath("//td[contains(text(),'TEST B')]")); } catch (Exception $ex) { $this->fail("#10 Changes of a booking attribute does effect bookings"); } //#11 Delete booking attribute self::$helper->deleteBookingAttribute("Book_C"); $el = false; try { self::$webDriver->findElement(WebDriverBy::id('radio_action_mode_rename_attribute'))->click(); $el = self::$webDriver->findElement(WebDriverBy::xpath("//option[text()='Book_C']")); } catch (Exception $unused) { } if ($el) { $this->fail("#11 Deleting a booking attribute has failed"); } self::$helper->deleteBookingAttribute("Book_B"); //#12 Change none booking attribute to a new name self::$helper->changeBookingAttribute('', 'Book_B'); try { self::$webDriver->findElement(WebDriverBy::className("ilFailureMessage")); } catch (Exception $ex) { $this->fail("#12 Changing a none existing booking attribute to an none existing name has succeded" . $ex); } //#13 Delete none booking attribute self::$helper->deleteBookingAttribute(''); try { self::$webDriver->findElement(WebDriverBy::className("ilFailureMessage")); } catch (Exception $ex) { $this->fail("#13 Deleting a none existing booking attribute has succeded" . $ex); } //#14 Check if deletion did effect the bookings self::$webDriver->findElement(WebDriverBy::linkText('Termine'))->click(); try { self::$webDriver->findElement(WebDriverBy::id('ilChkboxListAnchorText_tbl_roomobj'))->click(); $this->fail("#14 Deletion of a booking attribute does not effect bookings"); } catch (Exception $unused) { } self::$helper->deleteAllRooms(); }
public function testShouldShowCorrectNoImageSizesInfo() { $elements = self::$driver->findElements(WebDriverBy::xpath('//input[@type="checkbox" and starts-with(@name, "tinypng_sizes") and @checked="checked"]')); foreach ($elements as $element) { $element->click(); } self::$driver->wait(2)->until(WebDriverExpectedCondition::textToBePresentInElement(WebDriverBy::cssSelector('#tiny-image-sizes-notice'), 'Each selected size counts as a compression. With these settings no images will be compressed.')); // Not really necessary anymore to assert this. $elements = self::$driver->findElement(WebDriverBy::id('tiny-image-sizes-notice'))->findElements(WebDriverBy::tagName('p')); $statuses = array_map('innerText', $elements); $this->assertContains('Each selected size counts as a compression. With these settings no images will be compressed.', $statuses); }
/** * Wait for element that matches an XPath expression. * * @param string $xpath * @param bool $mustBeVisible Pass true to check if element is also visible. False only checks presence in DOM. * @return \RemoteWebElement */ public function waitForXpath($xpath, $mustBeVisible = false) { return $this->waitForElement(\WebDriverBy::xpath($xpath), $mustBeVisible); }
/** * @param $selector * @return \WebDriverBy * @throws \Exception */ protected function getLocator($selector) { if ($selector instanceof \WebDriverBy) { return $selector; } if (is_array($selector)) { return $this->getStrictLocator($selector); } if (Locator::isID($selector)) { return \WebDriverBy::id(substr($selector, 1)); } if (Locator::isCSS($selector)) { return \WebDriverBy::cssSelector($selector); } if (Locator::isXPath($selector)) { return \WebDriverBy::xpath($selector); } throw new \Exception("Only CSS or XPath allowed"); }
/** * 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"); } } }
/** * Deselect all options that display text matching the argument. That is, when * given "Bar" this would select an option like: * * <option value="foo">Bar</option>; * * @param string $text The visible text to match against. * @return void */ public function deselectByVisibleText($text) { $xpath = './/option[normalize-space(.) = ' . $this->escapeQuotes($text) . ']'; $options = $this->element->findElements(WebDriverBy::xpath($xpath)); foreach ($options as $option) { if ($option->isSelected()) { $option->click(); } } }
protected function getWebDriverLocator(array $by) { $type = key($by); $locator = $by[$type]; switch ($type) { case 'id': return \WebDriverBy::id($locator); case 'name': return \WebDriverBy::name($locator); case 'css': return \WebDriverBy::cssSelector($locator); case 'xpath': return \WebDriverBy::xpath($locator); case 'link': return \WebDriverBy::linkText($locator); case 'class': return \WebDriverBy::className($locator); default: throw new TestRuntime("Locator type '{$by}' is not defined. Use either: xpath, css, id, link, class, name"); } }
protected function view_edit_image($image_title = 'input-large') { $url = wordpress('/wp-admin/upload.php'); if (self::$driver->getCurrentUrl() != $url) { self::$driver->get($url); } if (wordpress_version() >= 43) { $selector = "//span[text()='" . $image_title . "']"; } else { $selector = "//a[contains(text(),'" . $image_title . "')]"; } self::$driver->findElement(WebDriverBy::xpath($selector))->click(); }
public function testInvalidCredentialsShouldStillUploadImage() { $this->set_api_key('1234'); $this->upload_image(dirname(__FILE__) . '/../fixtures/input-example.png'); $this->assertContains('input-example', self::$driver->findElement(WebDriverBy::xpath('//img[contains(@src, "input-example")]'))->getAttribute('src')); }
/** * Compares the content of the candidate table with an expected content. * * @param string $className class name of the HTML table. * @param string $expectedRows array of candidates that the table should contain. * * @return void */ private function _assertUserTableContents($className, $expectedRows) { $dataTable = $this->safeFindElement(WebDriverBy::ClassName($className)); if (is_null($expectedRows)) { $this->assertContains('No users found', $dataTable->getText()); } else { $actualRows = $dataTable->findElements(WebDriverBy::xpath('.//tbody//tr')); $this->assertEquals(count($actualRows), count($expectedRows), "Number of users returned should be " . count($expectedRows) . ", not " . count($actualRows)); for ($i = 1; $i <= count($actualRows); $i++) { $elements = $actualRows[$i - 1]->findElements(WebDriverBy::xpath('.//td')); $actualColumns = array(); foreach ($elements as $e) { $actualColumns[] = $e->getText(); } $expectedColumns = $expectedRows[$i - 1]; array_unshift($expectedColumns, "{$i}"); $this->assertEquals($actualColumns, $expectedColumns, "Users at row {$i} differ"); } } }
public function testGetByXpath() { $this->driver->get($this->getTestPath('index.html')); self::assertEquals('Test Value', $this->driver->findElement(WebDriverBy::xpath('//input[@name="test_name"]'))->getAttribute('value')); }
public function testNewReceiveInventory() { $this->driver->get($this->getTestPath('index.html')); sleep(5); $this->driver->findElement(WebDriverBy::name('Username'))->sendKeys('lnguyen'); $this->driver->findElement(WebDriverBy::name('Password'))->sendKeys('password'); $this->driver->findElement(WebDriverBy::linkText('Login'))->click(); sleep(5); $this->driver->findElement(WebDriverBy::linkText('Receiving'))->click(); for ($i = 0; $i < 10; $i++) { $this->driver->findElement(WebDriverBy::xpath("//span[text()='Receive New']"))->click(); sleep(5); $this->driver->findElement(WebDriverBy::name('Fromlocid'))->click(); $this->driver->findElement(WebDriverBy::xpath("//li[text()='SJRECVING']"))->click(); $this->driver->findElement(WebDriverBy::name('Recvtypeid'))->click(); $this->driver->findElement(WebDriverBy::xpath("//li[text()='NEW INVENTORY']"))->click(); $input = array("CCINTEG", "SMOOTHIE", "NASUNI", "CYPHORT", "LOADDYNAMIX", "PROOFPOINT", "NSCALED", "OPENWAVE", "QUORUM", "NEVRO", "VAULTIZE", "MICROSOFT", "ARISTOCRAT", "CYAN", "BIOTEAM", "VALVE", "UNTANGLE", "BSWITCH", "EGNYTE", "VERASONICS", "VPICORP", "ZEACOM", "NORSE", "TUMBLW", "AXWAY", "ICANN", "NORSE-FEDERAL", "FORTINET", "STRONGVIEW", "NOCTION", "DISCOVERY", "NOMINUM", "ECLSLA"); for ($k = 0; $k < 100; $k++) { $this->driver->findElement(WebDriverBy::name('Partnerid'))->click(); if ($k % 2 == 0) { $this->driver->findElement(WebDriverBy::xpath("//li[text()='QUORUM']"))->click(); } elseif ($k > 50) { $this->driver->findElement(WebDriverBy::xpath("//li[text()='CCINTEG']"))->click(); } else { $this->driver->findElement(WebDriverBy::xpath("//li[text()='NASUNI']"))->click(); } sleep(2); } $this->driver->findElement(WebDriverBy::name('Tolocid'))->click(); $this->driver->findElement(WebDriverBy::xpath("//div[text()='[QUOR-RAWMAT] QUOR-RAWMAT']"))->click(); $this->driver->findElement(WebDriverBy::name('Refpo'))->sendKeys('Refpo'); $this->driver->findElement(WebDriverBy::name('Custpo'))->sendKeys('Custpo'); $this->driver->findElement(WebDriverBy::name('Comment'))->sendKeys('Comment by Luu'); $this->driver->findElement(WebDriverBy::xpath("//span[text()='Enter Items']"))->click(); sleep(1); $this->driver->findElement(WebDriverBy::name('addOrderDetail'))->sendKeys(WebDriverKeys::ENTER); $this->driver->findElement(WebDriverBy::xpath("//li[text()='ONQ-280-16']"))->click(); for ($j = 0; $j < 3; $j++) { $arr = str_split('ABCDEFGHIJKLMNOP'); // get all the characters into an array shuffle($arr); // randomize the array $arr2 = array_slice($arr, 0, 6); // get the first six (random) characters out $str = implode('', $arr2); // smush them back into a string $this->driver->findElement(WebDriverBy::name('Ssn'))->sendKeys($str); $this->driver->findElement(WebDriverBy::name('Ssn'))->sendKeys(WebDriverKeys::ENTER); sleep(2); } sleep(2); $this->driver->findElement(WebDriverBy::xpath("//span[text()='Complete']"))->click(); $this->driver->findElement(WebDriverBy::xpath("//span[text()='Save']"))->click(); sleep(2); $this->driver->findElement(WebDriverBy::xpath("//span[text()='OK']"))->click(); $this->driver->findElement(WebDriverBy::xpath("//span[text()='Post Batch']"))->click(); $this->driver->findElement(WebDriverBy::xpath("//span[text()='OK']"))->click(); sleep(10); $this->driver->findElement(WebDriverBy::xpath("//span[text()='Close']"))->click(); sleep(2); } }
public function testSeeElementMalformedWdLocator() { $this->setExpectedException('Codeception\\Exception\\MalformedLocator'); $this->module->amOnPage('/'); $this->module->seeElement(WebDriverBy::xpath('H---EY!')); }
public function testEditComment() { //edit comment $row = self::$webDriver->findElement(WebDriverBy::xpath("//tr[contains(text(), " . "TestEditBooking" . ")]/td[8]")); $row->findElement(WebDriverBy::linkText('Bearbeiten'))->click(); self::$webDriver->findElement(WebDriverBy::id('comment'))->sendKeys("aComment"); self::$webDriver->findElement(WebDriverBy::name('cmd[saveEditBooking]'))->click(); $this->assertContains("Buchung erfolgreich bearbeitet", self::$helper->getSuccMessage()); self::$webDriver->findElement(WebDriverBy::linkText('Zurück zu den Buchungen'))->click(); }