diff --git a/src/Drupal/DrupalExtension/Context/MinkContext.php b/src/Drupal/DrupalExtension/Context/MinkContext.php index 8be3c5b7..6dd49894 100644 --- a/src/Drupal/DrupalExtension/Context/MinkContext.php +++ b/src/Drupal/DrupalExtension/Context/MinkContext.php @@ -611,6 +611,27 @@ public function assertSelectRadioById($label, $id = '') $radiobutton->selectOption($value, false); } + /** + * Expand a
element by . + * + * @Given I expand details labelled :summary + */ + public function iExpandDetailsByLabel($summary) + { + $page = $this->getSession()->getPage(); + $element = $page->find('xpath', "//details/summary[@aria-expanded='false'][text()][contains(., '$summary')]"); + if (empty($element)) { + throw new \Exception("Unable to find details element containing text $summary"); + } + try { + $element->click(); + usleep(100000); + } catch (UnsupportedDriverActionException $exception) { + // Goutte etc only supports clicking link, submit, button; + // for non-JS drivers this won't impact test. + } + } + /** * @} End of defgroup "mink extensions" */