Beispiel #1
0
 /**
  * Finds elements using given criteria.
  *
  * Similar to {@see BrowserSession::element()}, only this returns all matched
  * elements as an array. Also, this doesn't throw an exception if no
  * element was found.
  *
  * @param \PHPUnit_Extensions_Selenium2TestCase_ElementCriteria $criteria
  * @return Element[] array of instances of Se34\Element
  */
 public function elements(\PHPUnit_Extensions_Selenium2TestCase_ElementCriteria $criteria)
 {
     $values = $this->postCommand('elements', $criteria);
     $elements = array();
     foreach ($values as $value) {
         $elements[] = Element::fromResponseValue($value, $this->url->descend('element'), $this->driver);
     }
     return $elements;
 }
Beispiel #2
0
 /**
  * Checks identity of two DOM elements.
  *
  * @param Element $element
  * @param Element $other
  */
 public function assertElementEquals(Element $element, Element $other)
 {
     if (!$element->equals($other)) {
         $message = __FUNCTION__ . ': Element id=' . $element->getId() . ' (tag = "' . $element->name() . '"' . (($htmlId = $element->attribute('id')) !== '' ? ", html id=\"{$htmlId}\"" : '') . ')' . ' does not equal to element id=' . $other->getId() . ' (tag = "' . $other->name() . '"' . (($htmlId = $other->attribute('id')) !== '' ? ", html id=\"{$htmlId}\"" : '') . ')' . '.';
         $this->fail($message);
     } else {
         $this->assertTrue(TRUE);
     }
 }
Beispiel #3
0
 /**
  * Checks element name and attributes.
  *
  * @param Element $element Element to examine.
  * @param string $shortcutId Name of the shortcut (needed for the eventual error message).
  * @param string|NULL $expectedTagName Expected tag name.
  * @param array|NULL $expectedAttribs Expected values of attributes.
  * @throws ViewStateException
  */
 private function checkTagNameAndAttributes(Element $element, $shortcutId, $expectedTagName, $expectedAttribs)
 {
     $actualTagName = $element->name();
     if (isset($expectedTagName) && $actualTagName !== $expectedTagName) {
         throw new ViewStateException(__METHOD__ . ": Element '{$shortcutId}' is expected to be a tag '{$expectedTagName}', but is '{$actualTagName}'.");
     }
     if (isset($expectedAttribs) && is_array($expectedAttribs)) {
         foreach ($expectedAttribs as $attribName => $expectedValue) {
             $actualValue = $element->attribute($attribName);
             if ($actualValue !== $expectedValue) {
                 throw new ViewStateException(__METHOD__ . ": Expected value of '{$attribName}' is '{$expectedValue}' on element '{$shortcutId}', actual value is '{$actualValue}'.");
             }
         }
     }
 }