예제 #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;
     }
 }
예제 #2
0
 /**
  * Transforms from step definition's argument style to Mink format.
  *
  * Delegates all the process to BehatBase::transform_selector() checking
  * the provided $selectortype.
  *
  * @throws ExpectationException
  * @param string $selectortype It can be css, xpath or any of the named selectors.
  * @param string $element The locator (or string) we are looking for.
  * @return array Contains the selector and the locator expected by Mink.
  */
 protected function transform_text_selector($selectortype, $element)
 {
     $selectors = BehatSelectors::get_allowed_text_selectors();
     if (empty($selectors[$selectortype])) {
         throw new ExpectationException('The "' . $selectortype . '" selector can not be used to select text nodes', $this->getSession());
     }
     return $this->transform_selector($selectortype, $element);
 }