/** * Sets the field value. * * @param string $value * @return void */ public function set_value($value) { // Getting the filemanager label from the DOM. $fieldlabel = $this->get_field_locator(); // Getting the filepicker context and using the step definition // to upload the requested file. $uploadcontext = BehatContextHelper::get('behat_repository_upload'); $uploadcontext->i_upload_file_to_filemanager($value, $fieldlabel); }
/** * Sets the browser session. * * @param Session $session * @return void */ public static function set_session(Session $session) { // Set mink to be able to init a context. self::$mink = new Mink(array('mink' => $session)); self::$mink->setDefaultSessionName('mink'); }
/** * 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; } }