--- /dev/null
+@core
+Feature: Navigate action menu
+ In order to navigate an action menu
+ As a user
+ I need to be able to use the keyboard
+
+ @javascript
+ Scenario: The menu does not close on keyboard navigation
+ When I log in as "admin"
+ # Click to open the user menu.
+ And I click on ".usermenu a.toggle-display" "css_element" in the ".usermenu" "css_element"
+ # The menu should now be visible.
+ Then ".usermenu [role='menu']" "css_element" should be visible
+ # Press down arrow.
+ And I press key "40" in "#actionmenuaction-1" "css_element"
+ # The menu should still be visible.
+ And ".usermenu [role='menu']" "css_element" should be visible
+
+ @javascript
+ Scenario: The menu closes when it clicked outside
+ When I log in as "admin"
+ # Click to open the user menu.
+ And I click on ".usermenu a.toggle-display" "css_element" in the ".usermenu" "css_element"
+ # The menu should now be visible.
+ Then ".usermenu [role='menu']" "css_element" should be visible
+ # Click outside the menu.
+ And I click on "adminsearchquery" "field"
+ # The menu should now be hidden.
+ And ".usermenu [role='menu']" "css_element" should not be visible
throw new ExpectationException('Unknown browser button.', $session);
}
}
+
+ /**
+ * Trigger a keydown event for a key on a specific element.
+ *
+ * @When /^I press key "(?P<key_string>(?:[^"]|\\")*)" in "(?P<element_string>(?:[^"]|\\")*)" "(?P<selector_string>[^"]*)"$/
+ * @param string $key either char-code or character itself,
+ * may optionally be prefixed with ctrl-, alt-, shift- or meta-
+ * @param string $element Element we look for
+ * @param string $selectortype The type of what we look for
+ * @throws DriverException
+ * @throws ExpectationException
+ */
+ public function i_press_key_in_element($key, $element, $selectortype) {
+ if (!$this->running_javascript()) {
+ throw new DriverException('Key down step is not available with Javascript disabled');
+ }
+ // Gets the node based on the requested selector type and locator.
+ $node = $this->get_selected_node($selectortype, $element);
+ $modifier = null;
+ $validmodifiers = array('ctrl', 'alt', 'shift', 'meta');
+ $char = $key;
+ if (strpos($key, '-')) {
+ list($modifier, $char) = preg_split('/-/', $key, 2);
+ $modifier = strtolower($modifier);
+ if (!in_array($modifier, $validmodifiers)) {
+ throw new ExpectationException(sprintf('Unknown key modifier: %s.', $modifier));
+ }
+ }
+ if (is_numeric($char)) {
+ $char = (int)$char;
+ }
+
+ $node->keyDown($char, $modifier);
+ $node->keyPress($char, $modifier);
+ $node->keyUp($char, $modifier);
+ }
}