public function testSelector()
 {
     if (!class_exists('Symfony\\Component\\CssSelector\\CssSelector')) {
         $this->markTestSkipped('Symfony2 CssSelector component not installed');
     }
     $selector = new CssSelector();
     $this->assertEquals('descendant-or-self::h3', $selector->translateToXPath('h3'));
     $this->assertEquals('descendant-or-self::h3/span', $selector->translateToXPath('h3 > span'));
     $this->assertEquals("descendant-or-self::h3/*[contains(concat(' ', normalize-space(@class), ' '), ' my_div ')]", $selector->translateToXPath('h3 > .my_div'));
 }
Beispiel #2
0
 /**
  * Clicks on a link which has $identifier as its id|alt|title.
  * 
  * @param string $identifier 
  */
 public function click($identifier)
 {
     $session = $this->tester->getSession();
     $selector = new CssSelector();
     try {
         $xpath = $selector->translateToXPath($identifier);
         $session->getDriver()->click($xpath);
     } catch (\Exception $e) {
         $session->getPage()->clickLink($identifier);
     }
 }
 public function testSelector()
 {
     if (!class_exists('Symfony\\Component\\CssSelector\\CssSelector')) {
         $this->markTestSkipped('Symfony2 CssSelector component not installed');
     }
     $selector = new CssSelector();
     $this->assertEquals('descendant-or-self::h3', $selector->translateToXPath('h3'));
     $this->assertEquals('descendant-or-self::h3/span', $selector->translateToXPath('h3 > span'));
     if (interface_exists('Symfony\\Component\\CssSelector\\XPath\\TranslatorInterface')) {
         // The rewritten component of Symfony 2.3 checks for attribute existence first for the class.
         $expectation = "descendant-or-self::h3/*[@class and contains(concat(' ', normalize-space(@class), ' '), ' my_div ')]";
     } else {
         $expectation = "descendant-or-self::h3/*[contains(concat(' ', normalize-space(@class), ' '), ' my_div ')]";
     }
     $this->assertEquals($expectation, $selector->translateToXPath('h3 > .my_div'));
 }
Beispiel #4
0
 /**
  * Translates provided locator into XPath.
  *
  * @param mixed $locator Current selector locator.
  *
  * @return string
  * @throws ElementException When used selector is broken or not implemented.
  */
 public function translateToXPath($locator)
 {
     if (!$locator || !is_array($locator)) {
         throw new ElementException('Incorrect Selenium selector format', ElementException::TYPE_INCORRECT_SELECTOR);
     }
     list($selector, $locator) = each($locator);
     $locator = trim($locator);
     if ($selector == How::CLASS_NAME) {
         $locator = $this->_xpathEscaper->escapeLiteral(' ' . $locator . ' ');
         return "descendant-or-self::*[@class and contains(concat(' ', normalize-space(@class), ' '), " . $locator . ')]';
     } elseif ($selector == How::CSS) {
         return $this->_cssSelector->translateToXPath($locator);
     } elseif ($selector == How::ID) {
         return 'descendant-or-self::*[@id = ' . $this->_xpathEscaper->escapeLiteral($locator) . ']';
     } elseif ($selector == How::NAME) {
         return 'descendant-or-self::*[@name = ' . $this->_xpathEscaper->escapeLiteral($locator) . ']';
     } elseif ($selector == How::ID_OR_NAME) {
         $locator = $this->_xpathEscaper->escapeLiteral($locator);
         return 'descendant-or-self::*[@id = ' . $locator . ' or @name = ' . $locator . ']';
     } elseif ($selector == How::TAG_NAME) {
         return 'descendant-or-self::' . $locator;
     } elseif ($selector == How::LINK_TEXT) {
         $locator = $this->_xpathEscaper->escapeLiteral($locator);
         return 'descendant-or-self::a[./@href][normalize-space(string(.)) = ' . $locator . ']';
     } elseif ($selector == How::LABEL) {
         $locator = $this->_xpathEscaper->escapeLiteral($locator);
         $xpath_pieces = array();
         $xpath_pieces[] = 'descendant-or-self::*[@id = (//label[normalize-space(string(.)) = ' . $locator . ']/@for)]';
         $xpath_pieces[] = 'descendant-or-self::label[normalize-space(string(.)) = ' . $locator . ']//input';
         return implode('|', $xpath_pieces);
     } elseif ($selector == How::PARTIAL_LINK_TEXT) {
         $locator = $this->_xpathEscaper->escapeLiteral($locator);
         return 'descendant-or-self::a[./@href][contains(normalize-space(string(.)), ' . $locator . ')]';
     } elseif ($selector == How::XPATH) {
         return $locator;
     }
     /*case How::LINK_TEXT:
     		case How::PARTIAL_LINK_TEXT:*/
     throw new ElementException(sprintf('Selector type "%s" not yet implemented', $selector), ElementException::TYPE_UNKNOWN_SELECTOR);
 }
Beispiel #5
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testThrowsForArrayLocator()
 {
     $selector = new CssSelector();
     $selector->translateToXPath(array('h3'));
 }