/** * {@inheritdoc} */ public static function tearDownAfterClass() { if (null !== self::$mink) { self::$mink->stopSessions(); self::$mink = null; } }
/** * Registers Mink sessions on it's initialization. * * @param Behat\Mink\Mink $mink Mink manager instance */ protected static function registerMinkSessions(Mink $mink, array $parameters) { if (!$mink->hasSession('goutte')) { $params = $parameters['goutte']; $mink->registerSession('goutte', static::initGoutteSession($params['zend_config'], $params['server_parameters'])); } if (!$mink->hasSession('sahi')) { $params = $parameters['sahi']; $mink->registerSession('sahi', static::initSahiSession($parameters['browser'], $params['sid'], $params['host'], $params['port'])); } if (!$mink->hasSession('zombie')) { $params = $parameters['zombie']; $mink->registerSession('zombie', static::initZombieSession($params['host'], $params['port'], $params['auto_server'], $params['node_bin'])); } if (!$mink->hasSession('selenium')) { $params = $parameters['selenium']; $browser = isset($params['browser']) ? $params['browser'] : '*' . $parameters['browser']; $mink->registerSession('selenium', static::initSeleniumSession($browser, $parameters['base_url'], $params['host'], $params['port'])); } if (!$mink->hasSession('webdriver')) { $params = $parameters['webdriver']; $browser = $parameters['browser']; $mink->registerSession('webdriver', static::initWebdriverSession($browser, $params['host'], $params['capabilities'])); } }
public function rebootSessionDriver() { $driver = $this->mink->getSession('silex')->getDriver(); if ($driver instanceof KernelDriver) { $driver->reboot($this->manager->getBootedApplication()); } }
function it_should_call_the_image_upload_with_correct_params(Mink $mink, Session $session, Local $localImageDriver) { $mink->getSession()->willReturn($session); $session->getScreenshot()->willReturn('binary-image'); $localImageDriver->upload('binary-image', 'test.png')->shouldBeCalled(); $this->takeScreenshot('test.png'); }
/** * Destroys mink instance. */ public static function tearDownAfterClass() { if (null !== self::$minkTestCaseMinkInstance) { self::$minkTestCaseMinkInstance->stopSessions(); self::$minkTestCaseMinkInstance = null; } }
/** * Save the screenshot as the given filename * * @param string $fileName */ public function takeScreenshot($fileName = 'failure.png') { $screenshot = $this->mink->getSession()->getScreenshot(); foreach ($this->imageDrivers as $imageDriver) { $imageUrl = $imageDriver->upload($screenshot, $fileName); $this->output->writeln('Screenshot has been taken. Open image at ' . $imageUrl); } }
public function restoreDefaultSession() { if ($this->giffyEnabled) { $this->mink->setDefaultSessionName($this->defaultSessionName); $this->giffyEnabled = false; $this->path = ''; } }
protected function contextWithDriver(DriverInterface $driver) { $selectorsHandler = new SelectorsHandler(); $sessionName = 'mocked'; $mink = new Mink(array($sessionName => new Session($driver, $selectorsHandler))); $mink->setDefaultSessionName($sessionName); return new ContextTester($mink); }
public function dragByPixels($selector, $pixelsX, $pixelsY) { $session = $this->mink->getSession()->getDriver()->getWebDriverSession(); $el = $session->element('css selector', $selector); $session->moveto(['element' => $el->getID(), 'xoffset' => 2, 'yoffset' => 2]); $session->buttondown(""); $session->moveto(['element' => null, 'xoffset' => (int) $pixelsX, 'yoffset' => (int) $pixelsY]); $session->buttonup(""); usleep(50000); }
/** * Save the screenshot into a local buffer */ public function takeScreenshot() { try { $this->screenshots[] = $this->mink->getSession()->getScreenshot(); } catch (UnsupportedDriverActionException $e) { return; } catch (\Exception $e) { $this->output->writeln($e->getMessage()); } }
protected function getContextMock() { $pageMock = $this->getMockBuilder('Behat\\Mink\\Element\\DocumentElement')->disableOriginalConstructor()->setMethods(array('find'))->getMock(); $sessionMock = $this->getMockBuilder('Behat\\Mink\\Session')->setConstructorArgs(array($this->getMock('Behat\\Mink\\Driver\\DriverInterface'), $this->getMock('Behat\\Mink\\Selector\\SelectorsHandler')))->setMethods(array('getPage'))->getMock(); $sessionMock->expects($this->any())->method('getPage')->will($this->returnValue($pageMock)); $mink = new Mink(array('default' => $sessionMock)); $mink->setDefaultSessionName('default'); $context = new SilverStripeContext(array()); $context->setMink($mink); return $context; }
public function __construct($params) { $this->setBrowserstackParams($params); $host = "http://{$this->browserstack_username}:{$this->browserstack_password}@hub.browserstack.com/wd/hub"; if (self::$driver === null) { self::$driver = new Selenium2Driver('', $this->capabilities, $host); } $mink = new Mink(array('selenium2' => new Session(self::$driver))); $mink->setDefaultSessionName('selenium2'); $this->setMink($mink); $this->setMinkParameters($params); }
/** * Registers Mink sessions on it's initialization. * * @param Behat\Mink\Mink $mink Mink manager instance */ protected static function registerMinkSessions(Mink $mink) { if (!$mink->hasSession('goutte')) { $mink->registerSession('goutte', static::initGoutteSession()); $mink->setDefaultSessionName('goutte'); } if (!$mink->hasSession('sahi')) { $mink->registerSession('sahi', static::initSahiSession()); } if (!$mink->hasSession('zombie')) { $mink->registerSession('zombie', static::initZombieSession()); } }
/** * @Given /^I wait until I am on "([^"]*)"$/ */ public function iWaitUntilIAmOn($location) { $tries = 15; $fullLocation = $this->minkParameters['base_url'] . $location; for ($c = 0; $c < $tries; $c++) { if ($fullLocation != $this->mink->getSession()->getCurrentUrl()) { sleep(1); continue; } else { return; } } throw new \Exception("Timed out waiting for URL to be: {$fullLocation}"); }
/** * Adds Basic HTTP Auth to the Mink session before each scenario. * * @throws \InvalidArgumentException */ public function setBasicAuth() { $auth = $this->auth; if (null !== $auth['user']) { $this->mink->getSession()->setBasicAuth($auth['user'], $auth['password']); } }
/** * @param string $pageClass * * @return SymfonyPage */ private function instantiatePage($pageClass) { if (!is_subclass_of($pageClass, SymfonyPage::class)) { throw new \InvalidArgumentException(sprintf('Invalid page object class: %s, to use this factory you need to extend SymfonyPage', $pageClass)); } return new $pageClass($this->mink->getSession(), $this, $this->pageParameters, $this->router); }
protected function _createContextWithDriver(DriverInterface $driver) { $uimapYaml = new vfsStreamFile('page.yml'); $uimapYaml->setContent($this->_uimapYamlContent); $vfs = vfsStream::setup('vfs'); $vfs->addChild($uimapYaml); $tafPageSource = new TafPageSource(vfsStream::url('vfs/page.yml')); $uimapSelector = new UimapSelector($tafPageSource); $selectorsHandler = new SelectorsHandler(array('uimap' => $uimapSelector)); $sessionName = 'mocked'; $mink = new Mink(array($sessionName => new Session($driver, $selectorsHandler))); $mink->setDefaultSessionName($sessionName); $context = $this->getObjectForTrait('Irs\\BehatUimapExtension\\Context\\UimapContext'); $context->setMink($mink); $context->setPageSource($tafPageSource); $context->loadPage('category_page_before_reindex'); return $context; }
/** * Registers Mink sessions on it's initialization. * * @param Behat\Mink\Mink $mink Mink manager instance */ protected static function registerMinkSessions(Mink $mink) { $configs = sfConfig::get('sf_phpunit_mink'); foreach ($configs['drivers'] as $driver => $options) { if (!$mink->hasSession($driver)) { $initFn = 'init' . ucfirst($driver) . 'Session'; $mink->registerSession($driver, static::$initFn()); } } $mink->setDefaultSessionName($configs['default_driver']); }
public function testRestartSessions() { $session1 = $this->getSessionMock(); $session1->expects($this->once())->method('isStarted')->will($this->returnValue(false)); $session1->expects($this->never())->method('restart'); $session2 = $this->getSessionMock(); $session2->expects($this->once())->method('isStarted')->will($this->returnValue(true)); $session2->expects($this->once())->method('restart'); $this->mink->registerSession('not started', $session1); $this->mink->registerSession('started', $session2); $this->mink->restartSessions(); }
/** * @param AfterStepTested $event * @throws JavaScriptException\UnknownErrorException * @throws JavaScriptErrorExceptionInterface */ public function showJavaScriptErrors(AfterStepTested $event) { $session = $this->mink->getSession(); $errors = $session->evaluateScript('ErrorHandler.get();'); $exception = null; foreach ($errors as $error) { switch ($error['type']) { case 'error': $exception = new JavaScriptException\JavaScriptErrorException($this->formatMessage($error), 0, $exception); break; case 'ajaxError': $exception = new JavaScriptException\AjaxErrorException($this->formatMessage($error), 0, $exception); break; default: throw new JavaScriptException\UnknownErrorTypeException(sprintf('Unknown error type received "%s"', $error['type'])); break; } } $session->executeScript('ErrorHandler.clear()'); if (null !== $exception) { throw $exception; } }
/** * @Then /^I click (?:on )?"([^"]+)" in mail$/ */ public function clickInMail($text) { $message = $this->getCurrentMessage(); if ($message->hasPart('text/html')) { $links = $this->getCrawler($message)->filter('a')->each(function ($link) { return array('href' => $link->attr('href'), 'text' => $link->text()); }); } else { throw new \RuntimeException(sprintf('Unable to click in mail')); } $href = null; foreach ($links as $link) { if (false !== strpos($link['text'], $text)) { $href = $link['href']; break; } } if (null === $href) { throw new \RuntimeException(sprintf('Unable to find link "%s" in those links: "%s".', $text, implode('", "', array_map(function ($link) { return $link['text']; }, $links)))); } return $this->mink->getSession($this->mink->getDefaultSessionName())->visit($href); }
/** * Returns Mink session. * * @param string $name * (optional) Name of the session. Defaults to the active session. * * @return \Behat\Mink\Session * The active Mink session object. */ public function getSession($name = NULL) { return $this->mink->getSession($name); }
/** * @param string|null $name name of the session OR active session will be used * * @return WebAssert */ public function assertSession($name = null) { return $this->mink->assertSession($name); }
Filter::register('symfony.register', function ($chain) { Debug::enable(); Request::enableHttpMethodParameterOverride(); $kernel = new AppKernel('test', true); $kernel->loadClassCache(); $kernel->boot(); $this->suite()->symfony = $kernel; return $chain->next(); }); Filter::register('mink.register', function ($chain) { $default_browser = getenv('MINK_DEFAULT_BROWSER') !== false ? getenv('MINK_DEFAULT_BROWSER') : 'chrome'; $firefox_location = getenv('SELENIUM_FIREFOX_HOST') !== false ? getenv('SELENIUM_FIREFOX_HOST') : 'localhost'; $chrome_location = getenv('SELENIUM_CHROME_HOST') !== false ? getenv('SELENIUM_CHROME_HOST') : 'localhost'; $firefox_selenium_host = "http://{$firefox_location}:4444/wd/hub"; $chrome_selenium_host = "http://{$chrome_location}:4444/wd/hub"; $mink = new Mink(['firefox' => new Session(new Selenium2Driver('firefox', ['browserName' => 'firefox'], $firefox_selenium_host)), 'chrome' => new Session(new Selenium2Driver('chrome', ['browserName' => 'chrome'], $chrome_selenium_host))]); $mink->setDefaultSessionName($default_browser); /** @var Suite $root */ $root = $this->suite(); $root->mink = $mink; $root->beforeEach(function () use($mink) { $mink->resetSessions(); }); $root->after(function () use($mink) { $mink->stopSessions(); }); return $chain->next(); }); Filter::register('specs.prepare', function ($chain) { $callback = (require_once __DIR__ . '/prepare.php'); /** @var Suite $root */
/** * Stops all sessions, that might have started. * * @return void */ public static function tearDownAfterClass() { parent::tearDownAfterClass(); self::$mink->stopSessions(); }
private function initializeMinkStub(Mink $mink, Session $session) { $mink->getSession()->willReturn($session); }
/** * Returns assert session. * * @return WebAssert */ protected function getAssertSession() { return self::$mink->assertSession('sess'); }
public function __construct(array $parameters) { $mink = new Mink(array('selenium2' => new Session(new Selenium2Driver($parameters['wd_capabilities']['browser'], $parameters['wd_capabilities'], $parameters['wd_host'])))); $this->gui = $mink->getSession('selenium2'); }
/** * @return Session */ public function getSession() { return $this->mink->getSession(); }
/** * @param null $name * * @return Session */ private function getSession($name = null) { return $this->mink->getSession($name); }