MDL-48761 behat: Added new step for debugging scenarios

This commit is contained in:
Rajesh Taneja 2015-01-15 12:44:56 +08:00
parent da0ef2e4cf
commit d58b0ad6f1

View File

@ -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");
}
}
}