public function execute() { $this->testCase->byText('{{Add Tracking Number}}')->click(); $this->testCase->sleep('1s'); // Give the UI time to update $count = 0; do { $count++; } while ($this->webDriver->elementExists($this->theme->getShippingCarrierXpath($count), WebDriver::BY_XPATH)); $count--; // $count was the last one that DOESN'T exist. Go back one. if ($this->carrier) { $select = new WebDriverSelect($this->webDriver->byXpath($this->theme->getShippingCarrierXpath($count))); if (strpos($this->carrier, 'label=') === 0) { $carrier = substr($this->carrier, strlen('label=')); $select->selectByVisibleText($carrier); } else { $select->selectByValue($this->carrier); } } if ($this->title) { $element = $this->webDriver->byXpath($this->theme->getShippingTitleXpath($count)); $element->clear(); $element->sendKeys($this->title); } if ($this->number) { $element = $this->webDriver->byXpath($this->theme->getShippingTrackingNumberXpath($count)); $element->clear(); $element->sendKeys($this->number); } }
private function checkTestField($field, $value = NULL) { $field = strtolower($field); if ($value === NULL) { $value = TestFixtures::$tests['test-1']->{"get" . ucfirst($field)}(); } if ($field === "expectation") { $select = new WebDriverSelect($this->getTestField('expectation')); $this->assertEquals($value, $select->getFirstSelectedOption()->getText()); return; } $this->assertEquals($value, $this->getTestField($field)->getAttribute('value')); }
public function test_DefaultConfigPage() { $drv = $this->getDriver()->get($this->getSiteUrl() . '/config'); $cfg = json_decode(Configuration::DEFAULT_CONFIG_JSON, true); $SUPPORTED_VALUES = Configuration::SUPPORTED_VALUES; //PDT 3.4 fails to understand const array support. TODO: bug report $this->assertEquals('MyLibrary ~ Configuration', $drv->getTitle()); // === SELECTS === // //-- system_language $el = new Select($drv->findElement(By::xpath("//select[@name='system_language']"))); $this->assertEquals($cfg['system']['language'], $el->getFirstSelectedOption()->getAttribute('value')); //def value $this->assertEquals($SUPPORTED_VALUES['system_language'][$cfg['system']['language']], $el->getFirstSelectedOption()->getText()); //def txt // all options TODO: as function foreach ($SUPPORTED_VALUES['system_language'] as $k => $v) { $found = false; foreach ($el->getOptions() as $opt) { if ($opt->getAttribute('value') == $k) { if ($opt->getText() != $v) { $this->fail("value '{$k}' mached, but visible config text '{$v}' does not match on page '" . $opt->getText() . "'"); } $found = true; break; } } if (!$found) { $this->fail("value {$k} was not generated on page"); } } // //-- system_theme $el = new Select($drv->findElement(By::xpath("//select[@name='system_theme']"))); $this->assertEquals($cfg['system']['theme'], $el->getFirstSelectedOption()->getAttribute('value')); //def value $this->assertEquals($cfg['system']['theme'], $el->getFirstSelectedOption()->getText()); //def txt, equals to value // //-- system_timezone $el = new Select($drv->findElement(By::xpath("//select[@name='system_timezone']"))); $this->assertEquals($cfg['system']['timezone'], $el->getFirstSelectedOption()->getAttribute('value')); //def value $this->assertEquals($cfg['system']['timezone'], $el->getFirstSelectedOption()->getText()); //def txt, equals to value }
public function pay($requirePayment) { if ($requirePayment) { $this->testCase->assertElementExists($this->getId()); } if (!$this->webDriver->elementDisplayed('authorizenet_cc_number')) { $element = $this->webDriver->byId($this->getId()); $this->webDriver->getMouse()->click($element->getCoordinates()); } $this->webDriver->byId('authorizenet_cc_number')->clear()->sendKeys($this->paymentInformation->getCreditCardNumber()); $expirationMonthSelect = new WebDriverSelect($this->webDriver->byId('authorizenet_expiration')); $expirationMonthSelect->selectByValue($this->paymentInformation->getExpiryMonth()); $expirationYearSelect = new WebDriverSelect($this->webDriver->byId('authorizenet_expiration_yr')); $expirationYearSelect->selectByValue($this->paymentInformation->getExpiryYear()); $typeSelect = new WebDriverSelect($this->webDriver->byId('authorizenet_cc_type')); $typeSelect->selectByValue($this->paymentInformation->getType()); }
protected function setSelect(WebDriverElement $element, $value) { $select = new WebDriverSelect($element); if ($select->isMultiple()) { $select->deselectAll(); } if (!is_array($value)) { $value = [$value]; } foreach ($value as $v) { if (strpos($v, 'value:') === 0) { $select->selectByValue(substr($value, 6)); } else { $select->selectByVisibleText($v); } } }
public function testCategoryTreeExtractorWithNewProductCategories() { $this->getAction(Login::ACTION)->execute(); $this->getNavigator(AdminMenu::NAVIGATOR)->navigateTo('Catalog/Manage Products'); $this->byText('Add Product')->click(); $extractor = $this->getExtractor(Attribute::EXTRACTOR); /* @var $extractor Attribute */ $attributeSet = new WebDriverSelect($extractor->getElementByLabel('Attribute Set')); $attributeSet->selectByVisibleText('Default'); $attributeSet = new WebDriverSelect($extractor->getElementByLabel('Product Type')); $attributeSet->selectByVisibleText('Simple Product'); $this->byText('Continue')->click(); // Add it to a category $this->getNavigator(Tab::NAVIGATOR)->navigateTo('Categories::Product Categories'); $extractor = $this->getExtractor(CategoryTreeNode::EXTRACTOR); /* @var $extractor CategoryTreeNode */ $element = $extractor->getNode('Men/Shirts'); $this->assertWebDriverElement($element); }
public function pay($requirePayment) { if ($requirePayment) { $this->testCase->assertElementExists('ccsave_cc_owner'); } if ($this->webDriver->elementDisplayed('p_method_ccsave')) { $this->webDriver->byId('p_method_ccsave')->click(); } $this->assertion->assert(); $this->webDriver->byId('ccsave_cc_owner')->clear(); $this->webDriver->byId('ccsave_cc_owner')->sendKeys($this->customer->getBillingFirstName() . ' ' . $this->customer->getBillingLastName()); $select = new WebDriverSelect($this->webDriver->byId('ccsave_cc_type')); $select->selectByValue($this->paymentInformation->getType()); $this->webDriver->byId('ccsave_cc_number')->clear(); $this->webDriver->byId('ccsave_cc_number')->sendKeys($this->paymentInformation->getCreditCardNumber()); $select = new WebDriverSelect($this->webDriver->byId('ccsave_expiration')); $select->selectByValue($this->paymentInformation->getExpiryMonth()); $select = new WebDriverSelect($this->webDriver->byId('ccsave_expiration_yr')); $select->selectByValue($this->paymentInformation->getExpiryYear()); }
public function pay($requirePayment) { if ($requirePayment) { $this->testCase->assertElementExists($this->getId()); } if (!$this->webDriver->elementDisplayed('sagepaydirectpro_cc_owner')) { $this->webDriver->getMouse()->click($this->webDriver->byId($this->getId())->getCoordinates()); } $this->assertion->assert(); $select = new WebDriverSelect($this->webDriver->byId('sagepaydirectpro_cc_type')); $select->selectByValue($this->paymentInformation->getType()); $this->webDriver->byId('sagepaydirectpro_cc_number')->clear(); $this->webDriver->byId('sagepaydirectpro_cc_number')->sendKeys($this->paymentInformation->getCreditCardNumber()); $select = new WebDriverSelect($this->webDriver->byId('sagepaydirectpro_expiration')); $select->selectByValue($this->paymentInformation->getExpiryMonth()); $select = new WebDriverSelect($this->webDriver->byId('sagepaydirectpro_expiration_yr')); $select->selectByValue($this->paymentInformation->getExpiryYear()); $this->webDriver->byId('sagepaydirectpro_cc_cid')->clear(); $this->webDriver->byId('sagepaydirectpro_cc_cid')->sendKeys($this->paymentInformation->getCvv()); $this->webDriver->byId('sagepaydirectpro_cc_owner')->clear(); $this->webDriver->byId('sagepaydirectpro_cc_owner')->sendKeys($this->customer->getBillingFirstName() . ' ' . $this->customer->getBillingLastName()); }
/** * Append the given text to the given element. * Can also add a selection to a select box. * * ``` php * <?php * $I->appendField('#mySelectbox', 'SelectValue'); * $I->appendField('#myTextField', 'appended'); * ?> * ``` * * @param string $field * @param string $value * @throws \Codeception\Exception\ElementNotFound */ public function appendField($field, $value) { $el = $this->findField($field); switch ($el->getTagName()) { //Multiple select case "select": $matched = false; $wdSelect = new WebDriverSelect($el); try { $wdSelect->selectByVisibleText($value); $matched = true; } catch (NoSuchElementException $e) { } try { $wdSelect->selectByValue($value); $matched = true; } catch (NoSuchElementException $e) { } if ($matched) { return; } throw new ElementNotFound(json_encode($value), "Option inside {$field} matched by name or value"); break; case "textarea": $el->sendKeys($value); return; break; case "div": //allows for content editable divs $el->sendKeys(WebDriverKeys::END); $el->sendKeys($value); return; break; //Text, Checkbox, Radio //Text, Checkbox, Radio case "input": $type = $el->getAttribute('type'); if ($type == 'checkbox') { //Find by value or css,id,xpath $field = $this->findCheckable($this->webDriver, $value, true); if (!$field) { throw new ElementNotFound($value, "Checkbox or Radio by Label or CSS or XPath"); } if ($field->isSelected()) { return; } $field->click(); return; } elseif ($type == 'radio') { $this->selectOption($field, $value); return; } else { $el->sendKeys($value); return; } break; default: } throw new ElementNotFound($field, "Field by name, label, CSS or XPath"); }
public function execute($save = true) { $this->save = $save; try { $this->clickActionButton->click($this->translator->translate('Add New Condition')); } catch (NoSuchElementException $e) { // Don't worry about it. Perhaps we're not on the main terms page. } $element = $this->attribute->getElementByLabel($this->translator->translate('Condition Name')); $this->setValue($element, $this->name); if ($this->contentAs) { $select = new WebDriverSelect($this->attribute->getElementByLabel($this->translator->translate('Show Content as'))); $select->selectByVisibleText($this->contentAs); } if ($this->status) { $select = new WebDriverSelect($this->attribute->getElementByLabel($this->translator->translate('Status'))); $select->selectByVisibleText($this->status); } if ($this->storeView) { $storeViewElement = $this->attribute->getElementByLabel($this->translator->translate('Store View')); $xpath = sprintf('//option[.="%s"]', $this->storeView); $element = $storeViewElement->findElement(WebDriverBy::xpath($xpath)); $element->click(); } $element = $this->attribute->getElementByLabel($this->translator->translate('Checkbox Text')); $this->setValue($element, $this->checkboxText); $element = $this->attribute->getElementByLabel($this->translator->translate('Content')); $this->setValue($element, $this->content); $element = $this->attribute->getElementByLabel($this->translator->translate('Content Height (css)')); $this->setValue($element, $this->contentHeight); $this->preSave(); if ($this->save) { $this->webDriver->executeScript('window.scrollTo(0, 0);'); $this->clickActionButton->click($this->translator->translate('Save Condition')); } }
/** * Registration form industry field test * * @throws \Facebook\WebDriver\Exception\NoSuchElementException */ public function testIndustryField() { // Go to registration page $this->webDriver->get($this->registrationPageUrl); // Fill in the registration form with dummy data $this->webDriver->findElement(WebDriverBy::id('name'))->sendKeys('Andrei Troskov'); $this->webDriver->findElement(WebDriverBy::id('company_name'))->sendKeys('Google'); $this->webDriver->findElement(WebDriverBy::id('email'))->sendKeys('*****@*****.**'); // Fill in the password field with valid password $passwordElement = $this->webDriver->findElement(WebDriverBy::id('password')); $passwordElement->sendKeys('password'); // Submit form $submitButton = $this->webDriver->findElement(WebDriverBy::id('register_button')); $submitButton->click(); // Company industry error field should be with error message $industryStatus = $this->webDriver->findElement(WebDriverBy::xpath('//*[@id="register_form"]/div[6]/div[2]')); $this->assertEquals('The Company industry field is required.', $industryStatus->getText()); // Fill in the password field with invalid data (less than 8 symbols), so the form won't be sent $passwordElement = $this->webDriver->findElement(WebDriverBy::id('password')); $passwordElement->clear(); $passwordElement->sendKeys('1'); // Select valid company industry $companyIndustrySelect = new WebDriverSelect($this->webDriver->findElement(WebDriverBy::cssSelector('select[name="company_industry"]'))); $companyIndustrySelect->selectByValue('IT Services'); // Submit the form $submitButton = $this->webDriver->findElement(WebDriverBy::id('register_button')); $submitButton->click(); // Company industry error field should be empty $industryErrorNotFound = count($this->webDriver->findElements(WebDriverBy::xpath('//*[@id="register_form"]/div[6]/div[2]'))) === 0; $this->assertTrue($industryErrorNotFound); }
/** * @param WebDriverSelect $select * @param string|string[] $value * @throws \Exception */ protected function _setFieldSelect(WebDriverSelect $select, $value) { $valueList = (array) $value; if ($select->isMultiple()) { $select->deselectAll(); } $matched = false; foreach ($valueList as $value) { try { $select->selectByVisibleText($value); $matched = true; } catch (NoSuchElementException $e) { } } if ($matched) { return; } foreach ($valueList as $value) { try { $select->selectByValue($value); $matched = true; } catch (NoSuchElementException $e) { } } if (false === $matched) { throw new \Exception("Cannot select option `{$value}`"); } }