Skip to content

Commit

Permalink
Merge branch 'MDL-41555_25' of git://github.com/dmonllao/moodle into …
Browse files Browse the repository at this point in the history
…MOODLE_25_STABLE
  • Loading branch information
Sam Hemelryk committed Sep 10, 2013
2 parents b7e603a + 0141968 commit 4923518
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
1 change: 1 addition & 0 deletions admin/tool/behat/lang/en/tool_behat.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
$string['stepsdefinitionsfilters'] = 'Steps definitions';
$string['stepsdefinitionstype'] = 'Type';
$string['theninfo'] = 'Then. Checkings to ensure the outcomes are the expected ones';
$string['unknownexceptioninfo'] = 'There was a problem with Selenium or the browser, try to upgrade Selenium to the latest version. Error: ';
$string['viewsteps'] = 'Filter';
$string['wheninfo'] = 'When. Actions that provokes an event';
$string['wrongbehatsetup'] = 'Something is wrong with behat setup, ensure:<ul>
Expand Down
58 changes: 34 additions & 24 deletions lib/tests/behat/behat_hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
Behat\Behat\Event\StepEvent as StepEvent,
WebDriver\Exception\NoSuchWindow as NoSuchWindow,
WebDriver\Exception\UnexpectedAlertOpen as UnexpectedAlertOpen,
WebDriver\Exception\UnknownError as UnknownError,
WebDriver\Exception\CurlExec as CurlExec,
WebDriver\Exception\NoAlertOpenError as NoAlertOpenError;

/**
Expand Down Expand Up @@ -103,7 +105,9 @@ public static function before_suite($event) {
}

if (!behat_util::is_server_running()) {
throw new Exception($CFG->behat_wwwroot . ' is not available, ensure you started your PHP built-in server. More info in ' . behat_command::DOCS_URL . '#Running_tests');
throw new Exception($CFG->behat_wwwroot .
' is not available, ensure you started your PHP built-in server or your web server is correctly started and set up.' .
' More info in ' . behat_command::DOCS_URL . '#Running_tests');
}

// Prevents using outdated data, upgrade script would start and tests would fail.
Expand Down Expand Up @@ -170,12 +174,23 @@ public function before_scenario($event) {
}

// Start always in the the homepage.
$this->getSession()->visit($this->locate_path('/'));
try {
$this->getSession()->visit($this->locate_path('/'));
} catch (CurlExec $e) {
// Exception thrown by WebDriver, so only @javascript tests will be caugth; in
// behat_util::is_server_running() we already checked that the server is running.
$moreinfo = 'More info in ' . behat_command::DOCS_URL . '#Running_tests';
$msg = 'Selenium server is not running, you need to start it to run tests that involve Javascript. ' . $moreinfo;
throw new Exception($msg);
} catch (UnknownError $e) {
// Generic 'I have no idea' Selenium error. Custom exception to provide more feedback about possible solutions.
$this->throw_unknown_exception($e);
}

// Checking that the root path is a Moodle test site.
if (self::is_first_scenario()) {
$notestsiteexception = new Exception('The base URL (' . $CFG->wwwroot . ') is not a behat test site, ' .
'ensure you started the built-in web server in the correct directory');
'ensure you started the built-in web server in the correct directory or your web server is correctly started and set up');
$this->find("xpath", "//head/child::title[normalize-space(.)='Acceptance test site']", $notestsiteexception);

self::$initprocessesfinished = true;
Expand All @@ -192,27 +207,6 @@ public function before_scenario($event) {

}

/**
* Ensures selenium is running.
*
* Is only executed in scenarios which requires Javascript to run,
* it returns a direct error message about what's going on.
*
* @throws Exception
* @BeforeScenario @javascript
*/
public function before_scenario_javascript($event) {

// Just trying if server responds.
try {
$this->getSession()->wait(0, false);
} catch (Exception $e) {
$moreinfo = 'More info in ' . behat_command::DOCS_URL . '#Running_tests';
$msg = 'Selenium server is not running, you need to start it to run tests that involves Javascript. ' . $moreinfo;
throw new Exception($msg);
}
}

/**
* Checks that all DOM is ready.
*
Expand Down Expand Up @@ -246,6 +240,9 @@ public function after_step_javascript($event) {

} catch (NoSuchWindow $e) {
// If we were interacting with a popup window it will not exists after closing it.
} catch (UnknownError $e) {
// Custom exception to provide more feedback about possible solutions.
$this->throw_unknown_exception($e);
}
}

Expand Down Expand Up @@ -363,4 +360,17 @@ protected function get_debug_text($html) {
protected static function is_first_scenario() {
return !(self::$initprocessesfinished);
}

/**
* Throws an exception after appending an extra info text.
*
* @throws Exception
* @param UnknownError $exception
* @return void
*/
protected function throw_unknown_exception(UnknownError $exception) {
$text = get_string('unknownexceptioninfo', 'tool_behat');
throw new Exception($text . PHP_EOL . $exception->getMessage());
}

}

0 comments on commit 4923518

Please sign in to comment.