/** * * @param StoryTeller $st * @return void */ public function start(StoryTeller $st) { // Sauce Labs handles proxying for us (if required) // via the Sauce Connect app // build the Sauce Labs url $url = "http://" . urlencode($this->browserDetails->saucelabs->username) . ':' . urlencode($this->browserDetails->saucelabs->accesskey) . '@ondemand.saucelabs.com/wd/hub'; // build the Sauce Labs capabilities array $desiredCapabilities = $this->browserDetails->desiredCapabilities; // add the story's name, so that someone looking at the Sauce Labs // list of jobs can see what this browser was used for // // due to encoding errors at SauceLabs, we can't use '>' as a // delimiter in the story's name $story = $st->getStory(); $desiredCapabilities['name'] = $st->getTestEnvironmentName() . ' / ' . $st->getCurrentPhase() . ': ' . $st->getCurrentPhaseName() . ' / ' . $story->getName(); // create the browser session $webDriver = new WebDriverClient($url); $this->browserSession = $webDriver->newSession($this->browserDetails->browser, $desiredCapabilities); }
public function initAfterModulesAvailable(StoryTeller $st, CliEngine $engine, Injectables $injectables) { // shorthand $output = $injectables->output; // are we keeping the test environment hanging around afterwards? if (isset($engine->options->persistTarget) && $engine->options->persistTarget) { $injectables->activeConfig->setData('storyplayer.phases.testEnvShutdown.TestEnvironmentDestruction', false); $injectables->activeConfig->unsetData('storyplayer.phases.userAbort.TestEnvironmentDestruction'); $st->setPersistTestEnvironment(); } // are we trying to use a test environment that has previously // been persisted? if (isset($engine->options->reuseTarget) && $engine->options->reuseTarget) { // does the target exist to be reused? $output->setSilentMode(); $hasTarget = $st->fromTargetsTable()->hasCurrentTestEnvironment(); $output->resetSilentMode(); if (!$hasTarget) { $output->logCliWarning("target environment '" . $st->getTestEnvironmentName() . "' does not exist; ignoring --reuse-target switch"); return; } // okay, so we have the test environment in the targets table, // but has the test environment been changed at all? $output->setSilentMode(); $origSig = $st->fromTargetsTable()->getCurrentTestEnvironmentSignature(); $currentSig = $st->getTestEnvironmentSignature(); $output->resetSilentMode(); if ($origSig != $currentSig) { // our test environment entry isn't valid, so remove it $output->setSilentMode(); $st->usingTargetsTable()->removeCurrentTestEnvironment(); $output->resetSilentMode(); $output->logCliWarning("target environment '" . $st->getTestEnvironmentName() . "' has changed; ignoring --reuse-target switch"); return; } // if we get here, then we do not need to create the test environment $injectables->activeConfig->setData('storyplayer.phases.testEnvStartup.TestEnvironmentConstruction', false); } else { // do we already have this target? // // this can happen when the test environment was previously // persisted, and this time we're being run without the // --reuse-target flag // does the target exist to be reused? $output->setSilentMode(); $hasTarget = $st->fromTargetsTable()->hasCurrentTestEnvironment(); $output->resetSilentMode(); if ($hasTarget) { // remove this target from the table $output->setSilentMode(); $st->usingTargetsTable()->removeCurrentTestEnvironment(); $output->resetSilentMode(); } } }