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);
     }
 }
 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());
 }
Exemple #3
0
 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 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());
 }
Exemple #5
0
 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());
 }
Exemple #6
0
 /**
  * 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");
 }
 /**
  * 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}`");
     }
 }