/** * @param array $groups * @return $this */ public function setGroups($groups = array()) { foreach ($groups as $group) { $this->groups->element($this->test->using('xpath')->value("div[label[normalize-space(text()) = '{$group}']]/input"))->click(); } return $this; }
public function tab($tab) { $this->test->moveto($this->tabs->element($this->test->using('xpath')->value("ul/li/a[normalize-space(.) = '{$tab}']"))); $this->tabs->element($this->test->using('xpath')->value("ul/li/a[normalize-space(.) = '{$tab}']"))->click(); $this->waitPageToLoad(); $this->waitForAjax(); $this->xpathMenu = "//div[@id = 'main-menu']/ul" . "/li[a[normalize-space(.) = '{$tab}']]"; return $this; }
/** * Retrieve relative xpath from context to element * * @param \PHPUnit_Extensions_Selenium2TestCase_Element $element * @param \PHPUnit_Extensions_Selenium2TestCase_Element $context * @param string $path * @param bool $includeLastIndex * @return null */ protected function getRelativeXpath(\PHPUnit_Extensions_Selenium2TestCase_Element $element, \PHPUnit_Extensions_Selenium2TestCase_Element $context, $path = '', $includeLastIndex = true) { if ($element->equals($context)) { return '.' . $path; } $parentLocator = new Locator('..', Locator::SELECTOR_XPATH); $parentElement = $element->element($this->getSearchCriteria($parentLocator)); $childrenLocator = new Locator('*', Locator::SELECTOR_XPATH); $index = 1; $tag = $element->name(); if (!$includeLastIndex) { return $this->getRelativeXpath($parentElement, $context, '/' . $tag); } foreach ($parentElement->elements($this->getSearchCriteria($childrenLocator)) as $child) { if ($child->equals($element)) { return $this->getRelativeXpath($parentElement, $context, '/' . $tag . '[' . $index . ']' . $path); } if ($child->name() == $tag) { ++$index; } } return null; }