Пример #1
0
 /**
  * @covers Mage_Selenium_Helper_Config::getArea
  */
 public function testGetArea()
 {
     $configHelper = new Mage_Selenium_Helper_Config($this->_config);
     $configHelper->setArea('frontend');
     $this->assertInternalType('string', $configHelper->getArea());
     $this->assertNotEmpty($configHelper->getArea());
     $this->assertEquals('frontend', $configHelper->getArea());
 }
Пример #2
0
 /**
  * Verifies values on the opened form
  *
  * @param array|string $data Array of data to verify or datasource name
  * @param string $tabId Defines a specific Tab on the page that contains the form to verify (by default = '')
  * @param array $skipElements Array of elements that will be skipped during verification <br>
  * (default = array('password'))
  *
  * @throws OutOfRangeException
  * @throws RuntimeException
  * @return bool
  */
 public function verifyForm($data, $tabId = '', $skipElements = array('password', 'password_confirmation'))
 {
     if (is_string($data)) {
         $elements = explode('/', $data);
         $fileName = count($elements) > 1 ? array_shift($elements) : '';
         $data = $this->loadDataSet($fileName, implode('/', $elements));
     }
     $formData = $this->getCurrentUimapPage()->getMainForm();
     if ($tabId && $formData->getTab($tabId)) {
         $fieldsets = $formData->getTab($tabId)->getAllFieldsets($this->_paramsHelper);
     } else {
         $fieldsets = $formData->getAllFieldsets($this->_paramsHelper);
     }
     // if we have got empty UIMap but not empty dataset
     if (empty($fieldsets)) {
         throw new OutOfRangeException("Can't find main form in UIMap array for page '" . $this->getCurrentPage() . "', area['" . $this->_configHelper->getArea() . "']");
     }
     if ($tabId) {
         $this->openTab($tabId);
     }
     foreach ($data as $key => $value) {
         if (in_array($key, $skipElements) || $value === '%noValue%') {
             unset($data[$key]);
         }
     }
     $formDataMap = $this->_getFormDataMap($fieldsets, $data);
     $resultFlag = true;
     foreach ($formDataMap as $formFieldName => $formField) {
         switch ($formField['type']) {
             case self::FIELD_TYPE_INPUT:
                 if ($this->isElementPresent($formField['path'])) {
                     $val = $this->getValue($formField['path']);
                     if ($val != $formField['value']) {
                         $this->addVerificationMessage($formFieldName . ": The stored value is not equal to specified: ('" . $formField['value'] . "' != '" . $val . "')");
                         $resultFlag = false;
                     }
                 } else {
                     $this->addVerificationMessage('Can not find field (xpath:' . $formField['path'] . ')');
                     $resultFlag = false;
                 }
                 break;
             case self::FIELD_TYPE_CHECKBOX:
             case self::FIELD_TYPE_RADIOBUTTON:
                 if ($this->isElementPresent($formField['path'])) {
                     $isChecked = $this->isChecked($formField['path']);
                     $expectedVal = strtolower($formField['value']);
                     if ($isChecked && $expectedVal != 'yes' || !$isChecked && !($expectedVal == 'no' || $expectedVal == '')) {
                         $printVal = $isChecked ? 'yes' : 'no';
                         $this->addVerificationMessage($formFieldName . ": The stored value is not equal to specified: ('" . $expectedVal . "' != '" . $printVal . "')");
                         $resultFlag = false;
                     }
                 } else {
                     $this->addVerificationMessage('Can not find field (xpath:' . $formField['path'] . ')');
                     $resultFlag = false;
                 }
                 break;
             case self::FIELD_TYPE_DROPDOWN:
                 if ($this->isElementPresent($formField['path'])) {
                     $label = $this->getSelectedLabel($formField['path']);
                     if ($formField['value'] != $label) {
                         $this->addVerificationMessage($formFieldName . ": The stored value is not equal to specified: ('" . $formField['value'] . "' != '" . $label . "')");
                         $resultFlag = false;
                     }
                 } else {
                     $this->addVerificationMessage('Can not find field (xpath:' . $formField['path'] . ')');
                     $resultFlag = false;
                 }
                 break;
             case self::FIELD_TYPE_MULTISELECT:
                 if ($this->isElementPresent($formField['path'])) {
                     $selectedLabels = array();
                     try {
                         $selectedLabels = $this->getSelectedLabels($formField['path']);
                         foreach ($selectedLabels as $key => $label) {
                             $selectedLabels[$key] = trim($label, chr(0xc2) . chr(0xa0));
                         }
                     } catch (RuntimeException $e) {
                         if (strpos($e->getMessage(), 'No option selected') === false) {
                             throw $e;
                         }
                     }
                     $expectedLabels = explode(',', $formField['value']);
                     $expectedLabels = array_map('trim', $expectedLabels);
                     $expectedLabels = array_diff($expectedLabels, array(''));
                     foreach ($expectedLabels as $value) {
                         if (!in_array($value, $selectedLabels)) {
                             $this->addVerificationMessage($formFieldName . ": The value '" . $value . "' is not selected. (Selected values are: '" . implode(', ', $selectedLabels) . "')");
                             $resultFlag = false;
                         }
                     }
                     if (count($selectedLabels) != count($expectedLabels)) {
                         $this->addVerificationMessage("Amounts of the expected options are not equal to selected: ('" . $formField['value'] . "' != '" . implode(', ', $selectedLabels) . "')");
                         $resultFlag = false;
                     }
                 } else {
                     $this->addVerificationMessage('Can not find field (xpath:' . $formField['path'] . ')');
                     $resultFlag = false;
                 }
                 break;
             case self::FIELD_TYPE_PAGEELEMENT:
                 if ($this->isElementPresent($formField['path'])) {
                     $val = trim($this->getText($formField['path']));
                     if ($val != $formField['value']) {
                         $this->addVerificationMessage($formFieldName . ": The stored value is not equal to specified: ('" . $formField['value'] . "' != '" . $val . "')");
                         $resultFlag = false;
                     }
                 } else {
                     $this->addVerificationMessage('Can not find pageelement (xpath:' . $formField['path'] . ')');
                     $resultFlag = false;
                 }
                 break;
             default:
                 $this->addVerificationMessage('Unsupported field type');
                 $resultFlag = false;
         }
     }
     return $resultFlag;
 }