Exemple #1
0
 /**
  * Resets the test environment.
  *
  * @throws Exception If here we are not using the test database it should be because of a coding error
  * @BeforeScenario
  */
 public function before_scenario($event)
 {
     global $CFG;
     // Check if the test environment is ready: dataroot, database, server
     if (!defined('BEHAT_TEST') || !defined('BEHAT_SITE_RUNNING') || php_sapi_name() != 'cli' || !BehatTestingUtil::is_test_mode_enabled() || !BehatTestingUtil::is_test_site()) {
         throw new Exception('Behat only can modify the test database and the test dataroot!');
     }
     // Check if the browser is running and supports javascript
     $moreinfo = 'More info in ' . BehatCommand::DOCS_URL . '#Running_tests';
     $driverexceptionmsg = 'Selenium server is not running, you need to start it to run tests that involve Javascript. ' . $moreinfo;
     try {
         $session = $this->getSession();
     } catch (CurlExec $e) {
         // Exception thrown by WebDriver, so only @javascript tests will be caugth; in
         throw new Exception($driverexceptionmsg);
     } catch (DriverException $e) {
         throw new Exception($driverexceptionmsg);
     } catch (UnknownError $e) {
         // Generic 'I have no idea' Selenium error. Custom exception to provide more feedback about possible solutions.
         throw new Exception($e);
     }
     // Register the named selectors for mahara
     if (self::is_first_scenario()) {
         BehatSelectors::register_mahara_selectors($session);
         BehatContextHelper::set_session($session);
         // Reset the browser
         $session->restart();
         // Run all test with medium (1024x768) screen size, to avoid responsive problems.
         $this->resize_window('medium');
     }
     // Reset $SESSION.
     $_SESSION = array();
     $SESSION = new stdClass();
     $_SESSION['SESSION'] =& $SESSION;
     BehatTestingUtil::reset_database();
     BehatTestingUtil::reset_dataroot();
     // Reset the nasty strings list used during the last test.
     NastyStrings::reset_used_strings();
     // Set current user is admin
     // Start always in the the homepage.
     try {
         // Let's be conservative as we never know when new upstream issues will affect us.
         $session->visit($this->locate_path('/'));
     } catch (UnknownError $e) {
         $this->Exception($e);
     }
     // Checking that the root path is a mahara test site.
     if (!self::$initprocessesfinished) {
         $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 or your web server is correctly started and set up');
         $this->find("xpath", "//head/child::title[contains(., '" . BehatTestingUtil::BEHATSITENAME . "')]", $notestsiteexception);
         self::$initprocessesfinished = true;
     }
 }
Exemple #2
0
 /**
  * We print the site info + driver used and OS.
  *
  * At this point behat_hooks::before_suite() already
  * ran, so we have $CFG and family.
  *
  * @param SuiteEvent $event
  * @return void
  */
 public function beforeSuite(SuiteEvent $event)
 {
     global $CFG;
     require_once $CFG->docroot . '/testing/frameworks/behat/classes/util.php';
     // Calling all directly from here as we avoid more behat framework extensions.
     $runinfo = \BehatTestingUtil::get_site_info();
     $runinfo .= 'Server OS "' . PHP_OS . '"' . ', Browser: "firefox"' . PHP_EOL;
     $runinfo .= 'Started at ' . date('d-m-Y, H:i', time());
     $this->writeln($runinfo);
 }
Exemple #3
0
            cli::cli_exit("\nAcceptance tests site dropped\n");
        } else {
            if ($cli->get_cli_param('enable')) {
                BehatTestingUtil::start_test_mode();
                $runtestscommand = BehatCommand::get_behat_command(true) . ' --config ' . BehatConfigManager::get_behat_cli_config_filepath();
                cli::cli_exit("\nAcceptance tests environment enabled on {$CFG->behat_wwwroot}, to run the tests use:\n " . $runtestscommand . "\n");
            } else {
                if ($cli->get_cli_param('disable')) {
                    BehatTestingUtil::stop_test_mode();
                    cli::cli_exit("\nAcceptance test site is disabled\n");
                } else {
                    if ($cli->get_cli_param('diag')) {
                        $code = BehatTestingUtil::get_behat_status();
                        exit($code);
                    } else {
                        if ($cli->get_cli_param('config')) {
                            $code = BehatTestingUtil::get_behat_status();
                            if ($code == 0) {
                                echo BehatTestingUtil::get_behat_config_path();
                            }
                            exit($code);
                        }
                    }
                }
            }
        }
    }
} catch (Exception $e) {
    cli::cli_exit($e->getMessage(), true);
}
exit(0);