Exemplo n.º 1
0
 /**
  * Select value in dropdown which has option groups
  *
  * @param string $optionGroup
  * @param string $value
  * @return void
  */
 public function setOptionGroupValue($optionGroup, $value)
 {
     $optionLocator = ".//optgroup[@label='{$optionGroup}']/option[.=, '{$value}']";
     $criteria = new \PHPUnit_Extensions_Selenium2TestCase_ElementCriteria('xpath');
     $criteria->value($optionLocator);
     $this->_getWrappedElement()->selectOptionByCriteria($criteria);
 }
Exemplo n.º 2
0
 /**
  * Select value in dropdown which has option groups
  *
  * @param string $value
  * @return void
  */
 public function setValue($value)
 {
     $this->_eventManager->dispatchEvent(['set_value'], [__METHOD__, $this->getAbsoluteSelector()]);
     list($group, $option) = explode('/', $value);
     $optionLocator = ".//optgroup[@label='{$group}']/option[contains(text(), '{$option}')]";
     $criteria = new \PHPUnit_Extensions_Selenium2TestCase_ElementCriteria('xpath');
     $criteria->value($optionLocator);
     $this->_getWrappedElement(true)->selectOptionByCriteria($criteria);
 }
Exemplo n.º 3
0
 /**
  * Select Options by Label in Multiple Select
  *
  * @param string|array $values
  * @return void
  */
 public function setValue($values)
 {
     $this->_eventManager->dispatchEvent(['set_value'], [__METHOD__, $this->getAbsoluteSelector()]);
     $this->clearSelectedOptions();
     foreach ((array) $values as $label) {
         $criteria = new \PHPUnit_Extensions_Selenium2TestCase_ElementCriteria('xpath');
         $criteria->value('.//option[contains(text(), "' . $label . '")]');
         $this->_getWrappedElement()->selectOptionByCriteria($criteria);
     }
 }
Exemplo n.º 4
0
 private function postCommand($name, PHPUnit_Extensions_Selenium2TestCase_ElementCriteria $criteria)
 {
     $response = $this->driver->curl('POST', $this->url->addCommand($name), $criteria->getArrayCopy());
     return $response->getValue();
 }
Exemplo n.º 5
0
 /**
  * Return Wrapped Elements.
  * If element was not created before:
  * 1. Context is defined. If context was not passed to constructor - test case (all page) is taken as context
  * 2. Attempt to get selenium elements is performed in loop
  * that is terminated if elements is found or after timeout set in configuration
  *
  * @param bool $waitForElementPresent
  * @throws \PHPUnit_Extensions_Selenium2TestCase_Exception|\PHPUnit_Extensions_Selenium2TestCase_WebDriverException
  * @return \PHPUnit_Extensions_Selenium2TestCase_Element[]
  */
 protected function _getWrappedElements($waitForElementPresent = true)
 {
     if (!$this->_wrappedElements) {
         $context = $this->getContext($waitForElementPresent);
         $criteria = new \PHPUnit_Extensions_Selenium2TestCase_ElementCriteria($this->_locator['using']);
         $criteria->value($this->_locator['value']);
         if ($waitForElementPresent) {
             $wrappedElements = $this->_driver->waitUntil(function () use($context, $criteria) {
                 return $context->elements($criteria);
             });
         } else {
             $this->waitPageToLoad();
             $wrappedElements = $context->elements($criteria);
         }
         foreach ($wrappedElements as $wrappedElement) {
             $element = \Mtf\ObjectManager::getInstance()->create(get_class($this), ['locator' => $this->_locator, 'driver' => $this->_driver, 'context' => $this->_context]);
             $element->_wrappedElement = $wrappedElement;
             $this->_wrappedElements[] = $element;
         }
     }
     return $this->_wrappedElements;
 }
Exemplo n.º 6
0
 /**
  * Change the focus to a frame in the page by locator.
  * Changes focus to main page if locator is not passed
  *
  * @param Locator|null $locator
  * @return void
  */
 public function switchToFrame($locator = null)
 {
     if ($locator) {
         $this->_eventManager->dispatchEvent(['switch_to_frame'], [(string) $locator]);
         $criteria = new \PHPUnit_Extensions_Selenium2TestCase_ElementCriteria($locator['using']);
         $criteria->value($locator['value']);
         $element = $this->_driver->element($criteria);
     } else {
         $this->_eventManager->dispatchEvent(['switch_to_frame'], ['Switch to main window']);
         $element = null;
     }
     $this->_driver->frame($element);
 }
Exemplo n.º 7
0
 /**
  * Get search criteria
  *
  * @param Locator $locator
  * @return \PHPUnit_Extensions_Selenium2TestCase_ElementCriteria
  */
 public function getSearchCriteria(Locator $locator)
 {
     $criteria = new \PHPUnit_Extensions_Selenium2TestCase_ElementCriteria($locator['using']);
     $criteria->value($locator['value']);
     return $criteria;
 }
Exemplo n.º 8
0
 /**
  * Send a sequence of key strokes to the active element.
  *
  * @param array $keys
  * @return void
  */
 public function keys(array $keys)
 {
     $mSelect = $this->_getWrappedElement();
     $criteria = new \PHPUnit_Extensions_Selenium2TestCase_ElementCriteria(Locator::SELECTOR_TAG_NAME);
     $criteria->value('option');
     $mSelect->clearSelectedOptions();
     $options = $mSelect->elements($criteria);
     $pattern = '/^' . implode('', $keys) . '[a-z0-9A-Z-]*/';
     foreach ($options as $option) {
         preg_match($pattern, $option->text(), $matches);
         if ($matches) {
             $this->setValue($option->text());
             break;
         }
     }
 }