From 37642b3f1b3a97c1d2af411d8fdefd92da58fd2b Mon Sep 17 00:00:00 2001 From: Vincent Gao Date: Thu, 17 Jun 2021 14:06:27 +1000 Subject: [PATCH] update test bootstrap file --- tests/behat/bootstrap/TideCommonTrait.php | 81 ++++++++++++++++------- 1 file changed, 57 insertions(+), 24 deletions(-) diff --git a/tests/behat/bootstrap/TideCommonTrait.php b/tests/behat/bootstrap/TideCommonTrait.php index 3d919215..31dfc582 100644 --- a/tests/behat/bootstrap/TideCommonTrait.php +++ b/tests/behat/bootstrap/TideCommonTrait.php @@ -1,9 +1,9 @@ loggedInUser)) { $this->logout(); } @@ -58,22 +58,17 @@ public function waitForSeconds($sec) { */ public function iWaitForAjaxToFinish($timeout) { $condition = <<getSession()->wait($timeout * 1000, $condition); if (!$result) { @@ -85,16 +80,43 @@ 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 = <<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($href) { + public function clickOnLinkWithHref(string $href) { $page = $this->getSession()->getPage(); $link = $page->find('xpath', '//a[@href="' . $href . '"]'); if ($link === NULL) { @@ -105,8 +127,12 @@ public function clickOnLinkWithHref($href) { /** * @Then /^I click on the horizontal tab "([^"]*)"$/ + * @Then /^I click on the horizontal tab with text "([^"]*)"$/ + * + * @param string $text + * The text. */ - public function clickOnHorzTab($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) { @@ -117,12 +143,19 @@ public function clickOnHorzTab($text) { /** * @Then /^I click on the detail "([^"]*)"$/ + * @Then /^I click on the detail with text "([^"]*)"$/ + * + * @param string $text + * The text. */ - public function clickOnDetail($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) { - throw new \Exception('The detail with text "' . $text . '" not found.'); + $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(); }