You are here

public function TestSubContext::clickNthLink in Panopoly 8.2

Same name and namespace in other branches
  1. 7 modules/panopoly/panopoly_test/behat/steps/panopoly_test.behat.inc \TestSubContext::clickNthLink()

Click the nth link in a region.

@When /^I click the (?P<count>\d+)(?:st|nd|rd|th) "(?P<link>[^"]*)" in the "(?P<region>[^"]*)" region$/

File

modules/panopoly/panopoly_test/behat/steps/panopoly_test.behat.inc, line 1120
Provide Behat step-definitions for generic Panopoly tests.

Class

TestSubContext
Behat sub-context for Panopoly.

Code

public function clickNthLink($count, $link, $region) {
  $session = $this
    ->getSession();
  $region = $session
    ->getPage()
    ->find('region', $region);

  // We index from zero, rather than one.
  $index = $count - 1;
  foreach ($region
    ->findAll('xpath', '//a[text()="' . $link . '"]') as $element) {
    if ($index == 0) {
      $element
        ->click();
      return;
    }
    elseif ($index < 0) {
      break;
    }
    else {
      $index--;
    }
  }
  throw new \Exception(sprintf("Cannot find link with text '%s' and index %d", $link, $count));
}