Skip to content

Commit

Permalink
Added more behat test steps to common test trait. (#49)
Browse files Browse the repository at this point in the history
* Added more behat test steps to common test trait and  Fixed clicking on details in Common trait.

On-behalf-of: @salsadigitalauorg <[email protected]>
  • Loading branch information
sonnykt authored May 28, 2021
1 parent c5ae124 commit c8ab981
Showing 1 changed file with 75 additions and 1 deletion.
76 changes: 75 additions & 1 deletion tests/behat/bootstrap/TideCommonTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,84 @@ function isAjaxing(instance) {
* @Given no :type content type
*/
public function removeContentType($type) {
$content_type_entity = \Drupal::entityManager()->getStorage('node_type')->load($type);
$content_type_entity = \Drupal::entityTypeManager()->getStorage('node_type')->load($type);
if ($content_type_entity) {
$content_type_entity->delete();
}
}

/**
* @When I scroll :selector into view
* @When I scroll selector :selector into view
*
* @param string $selector
* Allowed selectors: #id, .className, //xpath.
*
* @throws \Exception
*/
public function scrollIntoView($selector) {
$function = <<<JS
(function() {
jQuery("$selector").get(0).scrollIntoView(false);
}());
JS;
try {
$this->getSession()->executeScript($function);
}
catch (Exception $e) {
throw new \Exception(__METHOD__ . ' failed');
}
}

/**
* @Then /^I click on link with href "([^"]*)"$/
* @Then /^I click on link with href value "([^"]*)"$/
*
* @param string $href
* The href value.
*/
public function clickOnLinkWithHref(string $href) {
$page = $this->getSession()->getPage();
$link = $page->find('xpath', '//a[@href="' . $href . '"]');
if ($link === NULL) {
throw new \Exception('Link with href "' . $href . '" not found.');
}
$link->click();
}

/**
* @Then /^I click on the horizontal tab "([^"]*)"$/
* @Then /^I click on the horizontal tab with text "([^"]*)"$/
*
* @param string $text
* The text.
*/
public function clickOnHorzTab(string $text) {
$page = $this->getSession()->getPage();
$link = $page->find('xpath', '//ul[contains(@class, "horizontal-tabs-list")]/li[contains(@class, "horizontal-tab-button")]/a/strong[text()="' . $text . '"]');
if ($link === NULL) {
throw new \Exception('The horizontal tab with text "' . $text . '" not found.');
}
$link->click();
}

/**
* @Then /^I click on the detail "([^"]*)"$/
* @Then /^I click on the detail with text "([^"]*)"$/
*
* @param string $text
* The text.
*/
public function clickOnDetail(string $text) {
$page = $this->getSession()->getPage();
$link = $page->find('xpath', '//div[contains(@class, "details-wrapper")]/details/summary[text()="' . $text . '"]');
if ($link === NULL) {
$link = $page->find('xpath', '//div[contains(@class, "details-wrapper")]/details/summary/span[text()="' . $text . '"]');
if ($link === NULL) {
throw new \Exception('The detail with text "' . $text . '" not found.');
}
}
$link->click();
}

}

0 comments on commit c8ab981

Please sign in to comment.