diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php
index 904e8b04d64..c5e4b3e1dc1 100644
--- a/lib/tests/behat/behat_general.php
+++ b/lib/tests/behat/behat_general.php
@@ -1347,4 +1347,32 @@ class behat_general extends behat_base {
     protected function get_page_load_xpath() {
         return "//span[@data-rel = '" . self::PAGE_LOAD_DETECTION_STRING . "']";
     }
+
+    /**
+     * Wait unit user press Enter/Return key. Useful when debugging a scenario.
+     *
+     * @Then /^(?:|I )pause(?:| scenario execution)$/
+     */
+    public function i_pause_scenario_executon() {
+        global $CFG;
+
+        $posixexists = function_exists('posix_isatty');
+
+        // Make sure this step is only used with interactive terminal (if detected).
+        if ($posixexists && !@posix_isatty(STDOUT)) {
+            $session = $this->getSession();
+            throw new ExpectationException('Break point should only be used with interative terminal.', $session);
+        }
+
+        // Windows don't support ANSI code by default, but with ANSICON.
+        $isansicon = getenv('ANSICON');
+        if (($CFG->ostype === 'WINDOWS') && empty($isansicon)) {
+            fwrite(STDOUT, "Paused. Press Enter/Return to continue.");
+            fread(STDIN, 1024);
+        } else {
+            fwrite(STDOUT, "\033[s\n\033[0;93mPaused. Press \033[1;31mEnter/Return\033[0;93m to continue.\033[0m");
+            fread(STDIN, 1024);
+            fwrite(STDOUT, "\033[2A\033[u\033[2B");
+        }
+    }
 }