Пример #1
0
 /**
  * @param BeforeScenarioScope $scope
  *
  * @BeforeScenario
  */
 public function gatherContexts(BeforeScenarioScope $scope)
 {
     $environment = $scope->getEnvironment();
     $this->minkContext = $environment->getContext('Behat\\MinkExtension\\Context\\MinkContext');
     $this->jsonContext = $environment->getContext('Sanpi\\Behatch\\Context\\JsonContext');
     $this->restContext = $environment->getContext('Sanpi\\Behatch\\Context\\RestContext');
 }
Пример #2
0
 /**
  * @BeforeScenario
  */
 public function linkUsedSubcontexts(BeforeScenarioScope $scope)
 {
     $this->placeholders = $scope->getEnvironment()->getContext('AppBundle\\Behat\\PlaceholderContext');
     if ($scope->getEnvironment()->hasContextClass('Behat\\MinkExtension\\Context\\MinkContext')) {
         $this->mink = $scope->getEnvironment()->getContext('Behat\\MinkExtension\\Context\\MinkContext');
     }
 }
Пример #3
0
 /** @BeforeScenario */
 public function gatherContexts(BeforeScenarioScope $scope)
 {
     $environment = $scope->getEnvironment();
     $this->flowContext = $environment->getContext('T3DD\\Backend\\Tests\\Behat\\FlowContext');
     $this->webApiContext = $environment->getContext('Behat\\WebApiExtension\\Context\\WebApiContext');
     $this->objectManager = $this->flowContext->getObjectManager();
 }
Пример #4
0
 /**
  * @BeforeScenario
  */
 public function init(BeforeScenarioScope $scope)
 {
     $environment = $scope->getEnvironment();
     $this->gridContext = $environment->getContext(GridWebContext::class);
     $this->resourceContext = $environment->getContext(ResourceWebContext::class);
     $this->routingContext = $environment->getContext(RoutingContext::class);
 }
Пример #5
0
 /**
  * @BeforeScenario
  */
 public function registerScenario(BeforeScenarioScope $scope)
 {
     // Scenario not usually available to steps, so we do ourselves.
     // See issue
     $this->scenario = $scope->getScenario();
     //print  $this->scenario->getTitle();
 }
Пример #6
0
 /** Fetch the behat environment.
  *
  * @BeforeScenario
  *
  * @param scope
  */
 public function gatherContext(BeforeScenarioScope $scope)
 {
     $this->minkContext = $scope->getEnvironment()->getContext($this->contextName);
     if (!$this->minkContext) {
         $message = sprintf("Unable to fetch the required context: %s", $this->contextName);
         throw new ExpectationException($message, null);
     }
 }
Пример #7
0
 /** @BeforeScenario */
 public function gatherContexts(BeforeScenarioScope $scope)
 {
     $environment = $scope->getEnvironment();
     $this->minkContext = $environment->getContext('Sfynx\\BehatBundle\\Behat\\MinkExtension\\Context\\MinkContext');
     $this->ajaxsubcontext = $environment->getContext('Sfynx\\BehatBundle\\Behat\\MinkExtension\\Context\\SubContext\\AjaxContext');
     $this->hiddenfieldsubcontext = $environment->getContext('Sfynx\\BehatBundle\\Behat\\MinkExtension\\Context\\SubContext\\HiddenFieldSubContext');
     $this->xpathxubcontext = $environment->getContext('Sfynx\\BehatBundle\\Behat\\MinkExtension\\Context\\SubContext\\XpathSubContext');
 }
 /**
  * This is used to load in the different contexts so they can be used with in the class
  *
  * @param BeforeScenarioScope $scope
  *
  * @BeforeScenario
  */
 public function gatherContexts(BeforeScenarioScope $scope)
 {
     $environment = $scope->getEnvironment();
     $contexts = $this->_getArrayOfContexts();
     foreach ($contexts as $context => $classVar) {
         $this->{$classVar} = $environment->getContext($context);
     }
 }
 /**
  * Simple provider for the API context.
  *
  * @param BeforeScenarioScope $scenarioScope
  *
  * @return ApiContext
  */
 public static function connectToAPIContext(BeforeScenarioScope $scenarioScope)
 {
     $environment = $scenarioScope->getEnvironment();
     if (!$environment instanceof InitializedContextEnvironment) {
         throw new \RuntimeException(sprintf('Cannot run tests as current feature context needs to access `ApiContext`, but for that "%s" is needed!', InitializedContextEnvironment::class));
     }
     return $environment->getContext(ApiContext::class);
 }
 /**
  * Perform before scenario actions:
  * - Gather all contexts so they can be reused in the current context.
  *
  * @BeforeScenario
  */
 public function beforeScenario(BeforeScenarioScope $scope)
 {
     // Gather all contexts.
     $contexts = $scope->getEnvironment()->getContexts();
     foreach ($contexts as $context) {
         $context_class_name = get_class($context);
         $this->contexts[$context_class_name] = $context;
     }
 }
Пример #11
0
 /**
  * @BeforeScenario
  */
 public function gatherContexts(BeforeScenarioScope $scope)
 {
     foreach ($scope->getEnvironment()->getContexts() as $context) {
         if ($context instanceof SubContext) {
             $context->setMainContext($this);
             $this->contexts[$context->getName()] = $context;
         }
     }
     $this->session = $this->getSession();
 }
 /**
  * @BeforeScenario
  */
 public function gatherContexts(BeforeScenarioScope $scope)
 {
     /** @var Environment $environment */
     $environment = $scope->getEnvironment();
     // Inject the specific contexts so they can be reused here.
     foreach ($this->contexts_map as $key => $class) {
         $context = $environment->getContext($class);
         $this->contexts[$key] = $context;
         unset($this->contexts_map[$key]);
     }
 }
Пример #13
0
 /**
  * @BeforeScenario
  *
  * Enable the testing app before the first scenario of the feature and
  * reset the configs before each scenario
  * @param BeforeScenarioScope $event
  */
 public function prepareParameters(BeforeScenarioScope $event)
 {
     $user = $this->currentUser;
     $this->currentUser = '******';
     $scenarios = $event->getFeature()->getScenarios();
     if ($event->getScenario() === reset($scenarios)) {
         $this->setStatusTestingApp(true);
     }
     $this->resetAppConfigs();
     $this->currentUser = $user;
 }
Пример #14
0
 /** @BeforeScenario */
 public function gatherContexts(BeforeScenarioScope $scope)
 {
     $environment = $scope->getEnvironment();
     foreach ($environment->getContexts() as $context) {
         if ($context instanceof \Behat\MinkExtension\Context\RawMinkContext) {
             $context->getSession('default')->setRequestHeader('Accept', 'text/html');
             $username = $this->kernel->getContainer()->getParameter('api_wtw_repositories_user_name_super');
             $password = $this->kernel->getContainer()->getParameter('api_wtw_repositories_password');
             $context->getSession('default')->setBasicAuth($username, $password);
         }
     }
 }
Пример #15
0
 /**
  * @BeforeScenario
  */
 public function before(BeforeScenarioScope $scope)
 {
     if (!self::$isPrepared) {
         $this->prepare();
         self::$isPrepared = true;
     }
     // Scenario skips a line so it's not a new example
     if ($scope->getScenario()->getLine() !== self::$lastScenarioLine + 1) {
         $this->reset();
     }
     self::$lastScenarioLine = $scope->getScenario()->getLine();
     return;
 }
Пример #16
0
 /**
  * @BeforeScenario
  */
 public function before(BeforeScenarioScope $scope)
 {
     $environment = $scope->getEnvironment();
     $this->minkContext = $environment->getContext('Drupal\\DrupalExtension\\Context\\MinkContext');
     if (module_exists('maillog')) {
         $this->maillog_last_id = (int) db_query('SELECT MAX(idmaillog) FROM {maillog}')->fetchField();
         // maillog configuration
         variable_set('maillog_send', 0);
         variable_set('maillog_log', 1);
         variable_set('maillog_devel', 0);
         // Set the the maillog handler in all mail system types
         $mail_system = array('default-system' => 'MaillogMailSystem', 'htmlmail' => 'MaillogMailSystem', 'variable_email' => 'MaillogMailSystem', 'maillog' => 'MaillogMailSystem');
         variable_set('mail_system', $mail_system);
     }
 }
 /**
  *
  * @BeforeScenario
  *
  * @param BeforeScenarioScope $scope
  */
 public function beforeScenario(BeforeScenarioScope $scope)
 {
     $this->scenarioData = ['file' => $scope->getFeature()->getFile(), 'line' => $scope->getScenario()->getLine(), 'title' => $scope->getScenario()->getTitle(), 'tags' => $scope->getScenario()->getTags()];
     $this->_w3c = $scope->getEnvironment()->getContext(W3CValidationContext::class);
     $this->_screenshot = $scope->getEnvironment()->getContext(ScreenshotContext::class);
     $this->setLogPath();
 }
Пример #18
0
 /**
  * @BeforeScenario
  *
  * @param BeforeScenarioScope $scope
  */
 public function gatherOutcomeContext(BeforeScenarioScope $scope)
 {
     /** @var \Behat\Behat\Context\Environment\InitializedContextEnvironment $environment */
     $environment = $scope->getEnvironment();
     $this->webApiContext = $environment->getContext('Muchacuba\\WebApiContext');
 }
Пример #19
0
 /**
  * @BeforeScenario
  */
 public function before(BeforeScenarioScope $scope)
 {
     $environment = $scope->getEnvironment();
     $this->minkContext = $environment->getContext('Drupal\\DrupalExtension\\Context\\MinkContext');
 }
Пример #20
0
 /**
  * @BeforeScenario
  *
  * @param BeforeScenarioScope $scope
  */
 public function gatherRootContext(BeforeScenarioScope $scope)
 {
     /** @var InitializedContextEnvironment $environment */
     $environment = $scope->getEnvironment();
     $this->rootContext = $environment->getContext('Muchacuba\\Context');
 }
Пример #21
0
 /** @BeforeScenario */
 public function gatherContexts(BeforeScenarioScope $scope)
 {
     $environment = $scope->getEnvironment();
     $this->minkContext = $environment->getContext('Knp\\FriendlyContexts\\Context\\MinkContext');
 }
Пример #22
0
 /** @BeforeScenario */
 public function gatherContexts(BeforeScenarioScope $scope)
 {
     $environment = $scope->getEnvironment();
     $this->urlContext = $environment->getContext('Behat\\MinkExtension\\Context\\MinkContext');
 }
Пример #23
0
 /**
  * Gathers other contexts we rely on, before the scenario starts.
  *
  * @BeforeScenario
  */
 public function gatherContexts(BeforeScenarioScope $scope)
 {
     $environment = $scope->getEnvironment();
     $this->variableContext = $environment->getContext(VariableContext::class);
 }
Пример #24
0
 /**
  * Gives access to the Behatch context.
  *
  * @param BeforeScenarioScope $scope
  *
  * @BeforeScenario
  */
 public function gatherContexts(BeforeScenarioScope $scope)
 {
     /** @var InitializedContextEnvironment $environment */
     $environment = $scope->getEnvironment();
     $this->restContext = $environment->getContext('Sanpi\\Behatch\\Context\\RestContext');
 }
Пример #25
0
 /**
  * Resets the test environment.
  *
  * @param BeforeScenarioScope $scope scope passed by event fired before scenario.
  * @throws behat_stop_exception If here we are not using the test database it should be because of a coding error
  */
 public function before_scenario(BeforeScenarioScope $scope)
 {
     global $DB, $CFG;
     // As many checks as we can.
     if (!defined('BEHAT_TEST') || !defined('BEHAT_SITE_RUNNING') || php_sapi_name() != 'cli' || !behat_util::is_test_mode_enabled() || !behat_util::is_test_site()) {
         throw new behat_stop_exception('Behat only can modify the test database and the test dataroot!');
     }
     $moreinfo = 'More info in ' . behat_command::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
         // behat_util::check_server_status() we already checked that the server is running.
         throw new behat_stop_exception($driverexceptionmsg);
     } catch (DriverException $e) {
         throw new behat_stop_exception($driverexceptionmsg);
     } catch (UnknownError $e) {
         // Generic 'I have no idea' Selenium error. Custom exception to provide more feedback about possible solutions.
         throw new behat_stop_exception($e->getMessage());
     }
     $suitename = $scope->getSuite()->getName();
     // Register behat selectors for theme, if suite is changed. We do it for every suite change.
     if ($suitename !== self::$runningsuite) {
         behat_context_helper::set_environment($scope->getEnvironment());
         // We need the Mink session to do it and we do it only before the first scenario.
         $namedpartialclass = 'behat_partial_named_selector';
         $namedexactclass = 'behat_exact_named_selector';
         if ($suitename !== 'default') {
             // If override selector exist, then set it as default behat selectors class.
             $overrideclass = behat_config_util::get_behat_theme_selector_override_classname($suitename, 'named_partial', true);
             if (class_exists($overrideclass)) {
                 $namedpartialclass = $overrideclass;
             }
             // If override selector exist, then set it as default behat selectors class.
             $overrideclass = behat_config_util::get_behat_theme_selector_override_classname($suitename, 'named_exact', true);
             if (class_exists($overrideclass)) {
                 $namedexactclass = $overrideclass;
             }
         }
         $this->getSession()->getSelectorsHandler()->registerSelector('named_partial', new $namedpartialclass());
         $this->getSession()->getSelectorsHandler()->registerSelector('named_exact', new $namedexactclass());
     }
     // Reset mink session between the scenarios.
     $session->reset();
     // Reset $SESSION.
     \core\session\manager::init_empty_session();
     behat_util::reset_all_data();
     // Assign valid data to admin user (some generator-related code needs a valid user).
     $user = $DB->get_record('user', array('username' => 'admin'));
     \core\session\manager::set_user($user);
     // Reset the browser if specified in config.php.
     if (!empty($CFG->behat_restart_browser_after) && $this->running_javascript()) {
         $now = time();
         if (self::$lastbrowsersessionstart + $CFG->behat_restart_browser_after < $now) {
             $session->restart();
             self::$lastbrowsersessionstart = $now;
         }
     }
     // Set the theme if not default.
     if ($suitename !== "default") {
         set_config('theme', $suitename);
         self::$runningsuite = $suitename;
     }
     // 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) {
         throw new behat_stop_exception($e->getMessage());
     }
     // Checking that the root path is a Moodle test site.
     if (self::is_first_scenario()) {
         $notestsiteexception = new behat_stop_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[normalize-space(.)='" . behat_util::BEHATSITENAME . "']", $notestsiteexception);
         self::$initprocessesfinished = true;
     }
     // Run all test with medium (1024x768) screen size, to avoid responsive problems.
     $this->resize_window('medium');
 }
Пример #26
0
 /** @BeforeScenario */
 public function gatherContexts(BeforeScenarioScope $scope)
 {
     $environment = $scope->getEnvironment();
     $this->dataContext = $environment->getContext('FSi\\Bundle\\GalleryBundle\\Behat\\Context\\DataContext');
 }
Пример #27
0
 /** @BeforeScenario */
 public function iAm(BeforeScenarioScope $scope)
 {
     $environment = $scope->getEnvironment();
     $this->minkContext = $environment->getContext('Behat\\MinkExtension\\Context\\MinkContext');
     $this->minkContext->visit('/login');
 }
Пример #28
0
 /** @BeforeScenario */
 public function gatherContexts(BeforeScenarioScope $scope)
 {
     $environment = $scope->getEnvironment();
     $this->featureContext = $environment->getContext('Shopware\\Tests\\Mink\\FeatureContext');
 }
 /**
  * @param BeforeScenarioScope $scope
  *
  * @BeforeScenario
  */
 public function beforeScenario(BeforeScenarioScope $scope)
 {
     $this->tags += array_merge($scope->getFeature()->getTags(), $scope->getScenario()->getTags());
     // Any page should be visited due to using jQuery and checking the cookies.
     $this->getSession()->visit($this->locatePath('/'));
 }
Пример #30
0
 /**
  * @BeforeScenario
  *
  * Allow access to the HelperContext.
  */
 public function gatherContexts(BeforeScenarioScope $scope)
 {
     $environment = $scope->getEnvironment();
     $this->helperContext = $environment->getContext('CWTest\\Context\\HelperContext');
 }