3 namespace Drupal\Tests\contextual\FunctionalJavascript;
6 * Functions for testing contextual links.
8 trait ContextualLinkClickTrait {
11 * Clicks a contextual link.
13 * @param string $selector
14 * The selector for the element that contains the contextual link.
15 * @param string $link_locator
16 * The link id, title, or text.
17 * @param bool $force_visible
18 * If true then the button will be forced to visible so it can be clicked.
20 protected function clickContextualLink($selector, $link_locator, $force_visible = TRUE) {
22 $this->toggleContextualTriggerVisibility($selector);
25 $element = $this->getSession()->getPage()->find('css', $selector);
26 $element->find('css', '.contextual button')->press();
27 $element->findLink($link_locator)->click();
30 $this->toggleContextualTriggerVisibility($selector);
35 * Toggles the visibility of a contextual trigger.
37 * @param string $selector
38 * The selector for the element that contains the contextual link.
40 protected function toggleContextualTriggerVisibility($selector) {
41 // Hovering over the element itself with should be enough, but does not
42 // work. Manually remove the visually-hidden class.
43 $this->getSession()->executeScript("jQuery('{$selector} .contextual .trigger').toggleClass('visually-hidden');");