/** * @see Behat\Behat\Context\ExtendedContextInterface::getMainContext() */ public function getMainContext() { if (null !== $this->parentContext) { return $this->parentContext->getMainContext(); } return $this; }
public function initialize(ContextInterface $context) { // Set Drupal driver manager. $context->setDrupal($this->drupal); // Set event dispatcher. $context->setDispatcher($this->dispatcher); // Add all parameters to the context. $context->setDrupalParameters($this->parameters); // Add commonly used parameters as proper class variables. if (isset($this->parameters['basic_auth'])) { $context->basic_auth = $this->parameters['basic_auth']; } // Initialize any available sub-contexts. if (isset($this->parameters['subcontexts'])) { $paths = array(); // Drivers may specify paths to subcontexts. if ($this->parameters['subcontexts']['autoload']) { foreach ($this->drupal->getDrivers() as $name => $driver) { if ($driver instanceof DrupalSubContextFinderInterface) { $paths += $driver->getSubContextPaths(); } } } // Additional subcontext locations may be specified manually in behat.yml. if (isset($this->parameters['subcontexts']['paths'])) { $paths = array_merge($paths, $this->parameters['subcontexts']['paths']); } foreach ($paths as $path) { if ($subcontexts = $this->findAvailableSubContexts($path)) { $this->loadSubContexts($subcontexts); } } $context->initializeSubContexts(); } }
public function run(ContextInterface $context) { if (!$context instanceof BehatContext) { return; } list($className, $methodName) = $this->getCallback(); $context->run($className, $methodName, $this->getValues()); }
/** * {@inheritdoc} */ public function initialize(ContextInterface $context) { if ($context instanceof ApplicationAwareInterface) { $context->setApplication($this->application); } if ($context instanceof ServiceLocatorAwareInterface) { $context->setServiceLocator($this->application->getServiceManager()); } }
/** * @see Behat\Behat\Context\Loader\ContextLoaderInterface::load() */ public function load(ContextInterface $context) { foreach ($context->getStepDefinitionResources() as $path) { $this->definitionLoader->load($path); } foreach ($context->getHookDefinitionResources() as $path) { $this->hookLoader->load($path); } }
public function initialize(ContextInterface $context) { $initializer = $this; $context->setBrowserInformations(function () use($initializer) { $browser = $initializer->getBrowser(); if (true === $this->browserFullScreen) { $browser->getWindows()->maximize(); } return $browser; }, $this->baseUrl, $this->timeout); }
/** * Initializes provided context. * * @param ContextInterface $context */ public function initialize(ContextInterface $context) { $client = new \Google_Client(); $client->setApplicationName('BehatGoogleAnalyticsExtension'); $client->setScopes(array('https://www.googleapis.com/auth/analytics.readonly')); $client->setClientId($this->parameters['client_id']); $key = file_get_contents($this->parameters['key_file_location']); $cred = new \Google_Auth_AssertionCredentials($this->parameters['service_account_name'], array('https://www.googleapis.com/auth/analytics.readonly'), $key); $client->setAssertionCredentials($cred); $service = new \Google_Service_Analytics($client); $context->setAnalyticsApiService($service); $context->setGoogleAnalyticsParameters($this->parameters); }
/** * @param MinkExtraContext $context */ public function initialize(ContextInterface $context) { foreach ($this->getContexts() as $alias => $subContext) { if (isset($this->parameters[$alias]) && $this->parameters[$alias]['enabled']) { $subContext->setParameters($this->parameters[$alias]); if ($subContext instanceof \Weavora\MinkExtra\Definition\DefinitionDispatcherAwareInterface) { $subContext->setDefinitionDispatcher($this->definitionDispatcher); } $subContext->initialize(); $context->useContext($alias, $subContext); } } }
/** * Loads definitions and translations from provided context. * * @param ContextInterface $context * * @throws \InvalidArgumentException */ public function load(ContextInterface $context) { foreach ($context->getTranslationResources() as $path) { $extension = pathinfo($path, PATHINFO_EXTENSION); if ('yml' === $extension) { $this->translator->addResource('yaml', $path, basename($path, '.yml'), 'behat.definitions'); } elseif ('xliff' === $extension) { $this->translator->addResource('xliff', $path, basename($path, '.xliff'), 'behat.definitions'); } elseif ('php' === $extension) { $this->translator->addResource('php', $path, basename($path, '.php'), 'behat.definitions'); } else { throw new \InvalidArgumentException(sprintf('Can not read definitions translations from file "%s". File is not supported', $path)); } } }
/** * Executes provided step definition. * * If the result is not a failure then take a screenshot and compare for differences. * * @param StepNode $step * @param DefinitionInterface $definition * @throws PerceptualDiffException If there are differences compared to the baseline */ protected function executeStepDefinition(StepNode $step, DefinitionInterface $definition) { parent::executeStepDefinition($step, $definition); $session = $this->context->getSession(); // give JavaScript time to trigger additional ajax requests after onload $session->wait(100); // Wait for an ajax request to complete, but only for a maximum of X seconds to avoid deadlocks $session->wait(5000, "(typeof window.__ajaxStatus !== 'undefined' ? window.__ajaxStatus() : 'no ajax') !== 'waiting'"); // The 'sleep' config setting will be respected in the comparator logic, // and is required to be at least ~200ms to give the browser a chance to finish rendering $diff = $this->screenshotComparator->takeScreenshot($this->context, $step); if ($diff > 0 && $this->failOnDiff) { // There were differences between the two screenshots throw new PerceptualDiffException(sprintf('There was a perceptual difference of %d', $diff)); } }
public function initialize(ContextInterface $context) { $context->setApp($this->app); $context->setConfigManager($this->configManager); $context->setCacheManager($this->cacheManager); $context->setFixtureFactory($this->factory); $context->setSessionService($this->session); }
/** * Initializes provided context. * * @param ContextInterface $context */ public function initialize(ContextInterface $context) { $context->setRegistry($this->registry); }
/** * Initializes provided context. * * @param ContextInterface $context */ public function initialize(ContextInterface $context) { $context->setMongoClient(new \MongoClient("mongodb://{$this->mongoHost}:27017")); $context->setMongoDatabase($this->mongoDatabase); }
/** * Sets page source into context * * @param ContextInterface $context */ public function initialize(ContextInterface $context) { $context->setPageSource($this->pageSource); }
/** * Initializes provided context. * * @param ContextInterface $context */ public function initialize(ContextInterface $context) { $context->setMontserrat($this->montserrat); }
public function initialize(ContextInterface $context) { $context->setBoomerangServiceProvider($this->serviceProvider); }
/** * Initializes provided context. * * @param ContextInterface $context */ public function initialize(ContextInterface $context) { $context->setDatabase($this->databaseName); $context->setAjaxSteps($this->ajaxSteps); $context->setAjaxTimeout($this->ajaxTimeout); $context->setScreenshotPath($this->screenshotPath); $context->setRegionMap($this->regionMap); $context->setAdminUrl($this->adminUrl); $context->setLoginUrl($this->loginUrl); }
/** * Passes the Moodle config to the main Moodle context * @see Behat\Behat\Context\Initializer.InitializerInterface::initialize() * @param ContextInterface $context */ public function initialize(ContextInterface $context) { $context->setMoodleConfig($this->parameters); }
/** * @param Behat\Behat\Context\ContextInterface $context * * @return null */ public function initialize(ContextInterface $context) { $context->setServiceMocker($this->serviceMocker); }
/** * {@inheritdoc} */ public function initialize(ContextInterface $context) { $context->setKernel($this->kernel); }
/** * Takes a screenshot if the step passes and compares it to the baseline * * @param ContextInterface $context * @param StepNode $step */ public function takeScreenshot(ContextInterface $context, StepNode $step) { // Increment the step number $this->stepNumber++; if ($this->sleep > 0) { // Convert seconds to microseconds usleep($this->sleep * 1000000); } $screenshotPath = $this->getScreenshotPath(); $screenshotFile = $screenshotPath . $this->getFilepath($step); $this->ensureDirectoryExists($screenshotFile); // Save the screenshot file_put_contents($screenshotFile, $context->getSession()->getScreenshot()); // Comparison $baselinePath = $this->getBaselinePath(); $diffPath = $this->getDiffPath(); $baselineFile = str_replace($screenshotPath, $baselinePath, $screenshotFile); if (!is_file($baselineFile)) { $this->ensureDirectoryExists($baselineFile); // New step, move into the baseline but return as there is no need for a comparison copy($screenshotFile, $baselineFile); return; } // Output the comparison to a temp file $tempFile = $this->path . '/temp.png'; // Run the comparison $output = array(); exec($this->getCompareCommand($baselineFile, $screenshotFile, $tempFile), $output, $return); if ($return === 0 || $return === 1) { // Check that there are some differences if ($return === 1) { $diffFile = str_replace($screenshotPath, $diffPath, $screenshotFile); $this->ensureDirectoryExists($diffFile); // Store the diff rename($tempFile, $diffFile); // Record the diff for output $this->diffs[spl_object_hash($step)] = $this->getFilepath($step); } elseif (is_file($tempFile)) { // Clean up the temp file unlink($tempFile); } return $output[0]; } return false; }
public function initialize(ContextInterface $context) { $context->setZf2App($this->zf2App); }
/** * Injects Magento installer and initializer into context * * @see \Behat\Behat\Context\Initializer\InitializerInterface::initialize() */ public function initialize(ContextInterface $context) { $context->setInstaller($this->installer); $context->setInitializer($this->initializer); }
/** * Initializes provided context. * * @param ContextInterface $context */ public function initialize(ContextInterface $context) { $context->setYiiWebApplication($this->yii); }
public function initialize(ContextInterface $context) { $context->setParameters($this->parameters); }
public function initialize(ContextInterface $context) { $context->setMink($this->mink); }