Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Drupal/DrupalExtension/Context/MinkContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,27 @@ public function assertSelectRadioById($label, $id = '')
$radiobutton->selectOption($value, false);
}

/**
* Expand a <details> element by <summary>.
*
* @Given I expand details labelled :summary
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xurizaemon

  1. This implementation relies on aria-expanded which is coupled to a specific implementation. Maybe this can be somehow made more generic.

  2. This method feels a bit one-sided: we allow to expand but not to collapse. Can it have a "brother" method to collapse?

  3. The description should use When rather than Given as this is an action rather than a prerequisite. Could you please update.

  4. It would be nice to be able to control the the usleep() number of seconds. Maybe as a parameter or via config.

*/
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"
*/
Expand Down