MDL-67813 core: Add a manual 'enter' key press behat action step
authorVictor Deniz Falcon <victor@moodle.com>
Tue, 26 May 2020 03:27:54 +0000 (11:27 +0800)
committerMihail Geshoski <mihail@moodle.com>
Thu, 28 May 2020 04:06:32 +0000 (12:06 +0800)
lib/tests/behat/behat_general.php

index e3830b7..f211d9f 100644 (file)
@@ -1898,4 +1898,19 @@ EOF;
                     $this->getSession());
         }
     }
+
+    /**
+     * Manually press enter key.
+     *
+     * @When /^I press enter/
+     * @throws DriverException
+     */
+    public function i_manually_press_enter() {
+        if (!$this->running_javascript()) {
+            throw new DriverException('Enter press step is not available with Javascript disabled');
+        }
+
+        $value = [\WebDriver\Key::ENTER];
+        $this->getSession()->getDriver()->getWebDriverSession()->activeElement()->postValue(['value' => $value]);
+    }
 }