コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public static function tearDownAfterClass()
 {
     if (null !== self::$mink) {
         self::$mink->stopSessions();
         self::$mink = null;
     }
 }
コード例 #2
0
ファイル: MinkContext.php プロジェクト: kingsj/core
 /**
  * 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']));
     }
 }
コード例 #3
0
 public function rebootSessionDriver()
 {
     $driver = $this->mink->getSession('silex')->getDriver();
     if ($driver instanceof KernelDriver) {
         $driver->reboot($this->manager->getBootedApplication());
     }
 }
コード例 #4
0
 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');
 }
コード例 #5
0
ファイル: TestCase.php プロジェクト: noelg/Mink
 /**
  * Destroys mink instance.
  */
 public static function tearDownAfterClass()
 {
     if (null !== self::$minkTestCaseMinkInstance) {
         self::$minkTestCaseMinkInstance->stopSessions();
         self::$minkTestCaseMinkInstance = null;
     }
 }
コード例 #6
0
 /**
  * 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);
     }
 }
コード例 #7
0
 public function restoreDefaultSession()
 {
     if ($this->giffyEnabled) {
         $this->mink->setDefaultSessionName($this->defaultSessionName);
         $this->giffyEnabled = false;
         $this->path = '';
     }
 }
コード例 #8
0
 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);
 }
コード例 #9
0
 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);
 }
コード例 #10
0
 /**
  * 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;
 }
コード例 #12
0
 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);
 }
コード例 #13
0
ファイル: TestCase.php プロジェクト: robo47/Mink
 /**
  * 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());
     }
 }
コード例 #14
0
ファイル: WaitContext.php プロジェクト: jimbojsb/behat-extras
 /**
  * @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']);
     }
 }
コード例 #16
0
ファイル: PageObjectFactory.php プロジェクト: Mangetsu/Sylius
 /**
  * @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);
 }
コード例 #17
0
 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;
 }
コード例 #18
0
 /**
  * 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']);
 }
コード例 #19
0
ファイル: MinkTest.php プロジェクト: dunglas/Mink
 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();
 }
コード例 #20
0
 /**
  * @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;
     }
 }
コード例 #21
0
 /**
  * @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);
 }
コード例 #22
0
ファイル: BrowserTestBase.php プロジェクト: ddrozdik/dmaps
 /**
  * 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);
 }
コード例 #23
0
ファイル: FeatureContext.php プロジェクト: Spomky/Sylius
 /**
  * @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);
 }
コード例 #24
0
ファイル: init.php プロジェクト: Safranil/symfony-okoa
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 */
コード例 #25
0
 /**
  * Stops all sessions, that might have started.
  *
  * @return void
  */
 public static function tearDownAfterClass()
 {
     parent::tearDownAfterClass();
     self::$mink->stopSessions();
 }
コード例 #26
0
 private function initializeMinkStub(Mink $mink, Session $session)
 {
     $mink->getSession()->willReturn($session);
 }
コード例 #27
0
ファイル: TestCase.php プロジェクト: cigraphics/Mink
 /**
  * Returns assert session.
  *
  * @return WebAssert
  */
 protected function getAssertSession()
 {
     return self::$mink->assertSession('sess');
 }
コード例 #28
0
 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');
 }
コード例 #29
0
ファイル: SubContext.php プロジェクト: GerDner/luck-docker
 /**
  * @return Session
  */
 public function getSession()
 {
     return $this->mink->getSession();
 }
コード例 #30
0
ファイル: SecurityContext.php プロジェクト: stevedien/Sylius
 /**
  * @param null $name
  *
  * @return Session
  */
 private function getSession($name = null)
 {
     return $this->mink->getSession($name);
 }