Skip to content

Commit

Permalink
Merge pull request #106 from davidferlay/behatfeaturecontext
Browse files Browse the repository at this point in the history
Adding useful behat step definitions based on last project cases
  • Loading branch information
ilyano authored Jul 5, 2019
2 parents cebb954 + f11ca5f commit 81f5e23
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,24 @@ public function iSelectTheFirstElement($selector) {
throw new Exception("Unable to find a non empty value.");
}

/**
* @Given I select in combobox ":arg1" value ":arg2"
*/
public function iSelectCombobox($field_wrapper_selector, $value) {
$page = $this->getSession()->getPage();
$element = $page->find('css', $field_wrapper_selector);
$combo = $element->getParent()->find('css', 'span');
$combo->click();

// Caught this case on RA instance, its chrome can not draw selectlist so
// fast.
$this->iWaitSeconds(3);
$option = $page->find('xpath', "//li [@class='ui-menu-item']/div [text () ='$value']");
$option->mouseOver();
$option->getParent()->getParent()->click();
$this->iWaitSeconds(1);
}

/**
* Click some text
*
Expand Down Expand Up @@ -242,4 +260,73 @@ public function waitForThePageToBeLoaded()
$this->getSession()->wait(10000, "document.readyState === 'complete'");
}

/**
* @Then I wait :arg1 seconds until element :arg2 appears
*/
public function waitSecondsUntilElementAppears($seconds, $selector) {
$startTime = time();
do {
try {
$element = $this->getSession()->getPage()->findAll('css', $selector);
if (count($element) > 0) {
return TRUE;
}
} catch (ExpectationException $e) {
/* Intentionally left blank */
}
} while (time() - $startTime < $seconds);
throw new ResponseTextException(
sprintf('Cannot find the element %s after %s seconds', $selector, $seconds),
$this->getSession()
);
}

/**
* @Then I should see the pin with title :arg1 on the map :arg2
*/
public function iShouldSeeThePinWithTitleOnTheMap($pin, $map_selector) {
if ($map = $this->getSession()->getPage()->find('css', $map_selector)) {
if ($pin = $map->find('css', 'area[title="' . $pin . '"]')) {
return $pin;
}
else {
throw new \Exception(sprintf("The map '%s' does not contain pin with title '%s'", $map_selector, $pin));
}
}
else {
throw new \Exception(sprintf("The page does not contain the map with selector '%s'", $map_selector));
}
}

/**
* @When I click on the pin with title :arg1 on the map :arg2
*/
public function iClickThePinWithTitleOnTheMap($pin, $map_selector) {
$element = $this->iShouldSeeThePinWithTitleOnTheMap($pin, $map_selector);
if (empty($element)) {
throw new \Exception(sprintf("The map '%s' does not contain pin with title '%s'", $map_selector, $pin));
}
$element->click();
}

/**
* Switch to the another tab.
* Example: I switch to "2" tab
* Example: I switch to "main" tab
*
* @Given I switch to ":arg1" tab
*/
public function switchToNextTab($tab) {
if ($tab == 'main') {
$tab = 1;
}
$windowNames = $this->getSession()->getWindowNames();
if(isset($windowNames[$tab])) {
$this->getSession()->switchToWindow($windowNames[$tab]);
}
else {
throw new Exception('There is not a tab to switch.');
}
}

}

0 comments on commit 81f5e23

Please sign in to comment.