public function openPage($url)
 {
     $session = new Session($this->getDriver());
     $session->start();
     $session->visit($url);
     $this->page = $session->getPage();
 }
Example #2
0
 /**
  * Initialize element.
  *
  * @param Session $session
  */
 public function __construct(Session $session)
 {
     $this->xpathManipulator = new Manipulator();
     $this->session = $session;
     $this->driver = $session->getDriver();
     $this->selectorsHandler = $session->getSelectorsHandler();
 }
 /**
  * helper method for pages which needs an active login
  *
  * @throws ElementNotFoundException
  *
  * @return void
  */
 protected function login()
 {
     $page = $this->session->getPage();
     $page->fillField('email', 'root');
     $page->fillField('password', 'developer');
     $page->pressButton('Anmelden');
 }
 function it_throws_an_exception_if_neither_create_nor_update_key_word_has_been_found(Session $session, SymfonyPageInterface $createPage, SymfonyPageInterface $updatePage, UrlMatcherInterface $urlMatcher)
 {
     $session->getCurrentUrl()->willReturn('https://sylius.com/resource/show');
     $urlMatcher->match('/resource/show')->willReturn(['_route' => 'sylius_resource_show']);
     $createPage->getRouteName()->willReturn('sylius_resource_create');
     $updatePage->getRouteName()->willReturn('sylius_resource_update');
     $this->shouldThrow(\LogicException::class)->during('getCurrentPageWithForm', [[$createPage, $updatePage]]);
 }
Example #5
0
 function it_loads_base_url_and_sets_a_cookie_if_not_using_kernel_driver_and_driver_is_currently_outside_base_url(Session $minkSession, DriverInterface $driver)
 {
     $minkSession->getDriver()->willReturn($driver);
     $minkSession->getCurrentUrl()->willReturn('http://sylius.org');
     $minkSession->visit('http://localhost:8080/')->shouldBeCalled();
     $minkSession->setCookie('abc', 'def')->shouldBeCalled();
     $this->setCookie('abc', 'def');
 }
 /**
  * @return NodeElement
  *
  * @throws ElementNotFoundException
  */
 private function getMessageElement()
 {
     $messageElement = $this->session->getPage()->find('css', self::NOTIFICATION_ELEMENT_CSS);
     if (null === $messageElement) {
         throw new ElementNotFoundException($this->session->getDriver(), 'message element', 'css', self::NOTIFICATION_ELEMENT_CSS);
     }
     return $messageElement;
 }
Example #7
0
 /**
  * Attaches Selenium selector, that is later used during annotation processing.
  *
  * @param Session $session Mink session.
  *
  * @return self
  */
 protected function attachSeleniumSelector(Session $session)
 {
     $selectors_handler = $session->getSelectorsHandler();
     if (!$selectors_handler->isSelectorRegistered('se')) {
         $selectors_handler->registerSelector('se', new SeleniumSelector($selectors_handler));
     }
     return $session;
 }
 public function testBaseUrl()
 {
     $client = new Client(require __DIR__ . '/../app.php');
     $driver = new BrowserKitDriver($client, 'http://localhost/foo/');
     $session = new Session($driver);
     $session->visit('http://localhost/foo/index.html');
     $this->assertEquals(200, $session->getStatusCode());
     $this->assertEquals('http://localhost/foo/index.html', $session->getCurrentUrl());
 }
Example #9
0
 private function prepareMinkSessionIfNeeded()
 {
     if ($this->minkSession->getDriver() instanceof KernelDriver) {
         return;
     }
     if (false !== strpos($this->minkSession->getCurrentUrl(), $this->minkParameters['base_url'])) {
         return;
     }
     $this->minkSession->visit(rtrim($this->minkParameters['base_url'], '/') . '/');
 }
Example #10
0
 private function prepareSessionIfNeeded()
 {
     if (!$this->minkSession->getDriver() instanceof Selenium2Driver) {
         return;
     }
     if (false !== strpos($this->minkSession->getCurrentUrl(), $this->minkParameters['base_url'])) {
         return;
     }
     $this->homePage->open();
 }
 /**
  * {@inheritdoc}
  * 
  * @throws \LogicException
  */
 public function getCurrentPageWithForm(array $pages)
 {
     $routeParameters = $this->urlMatcher->match(parse_url($this->session->getCurrentUrl(), PHP_URL_PATH));
     Assert::allIsInstanceOf($pages, SymfonyPageInterface::class);
     foreach ($pages as $page) {
         if ($routeParameters['_route'] === $page->getRouteName()) {
             return $page;
         }
     }
     throw new \LogicException('Route name could not be matched to provided pages.');
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 public function logIn($email, $providerKey, Session $minkSession)
 {
     $user = $this->userRepository->findOneBy(['username' => $email]);
     if (null === $user) {
         throw new \InvalidArgumentException(sprintf('There is no user with email %s', $email));
     }
     $token = new UsernamePasswordToken($user, $user->getPassword(), $providerKey, $user->getRoles());
     $this->session->set('_security_user', serialize($token));
     $this->session->save();
     $minkSession->setCookie($this->session->getName(), $this->session->getId());
 }
Example #13
0
 /**
  * {@inheritdoc}
  * 
  * @throws \LogicException
  */
 public function getCurrentPageWithForm(CreatePageInterface $createPage, UpdatePageInterface $updatePage)
 {
     $routeParameters = $this->urlMatcher->match($this->session->getCurrentUrl());
     if (false !== strpos($routeParameters['_route'], 'create')) {
         return $createPage;
     }
     if (false !== strpos($routeParameters['_route'], 'update')) {
         return $updatePage;
     }
     throw new \LogicException('Route name does not have any of "update" or "create" keyword, so matcher was unable to match proper page.');
 }
Example #14
0
 function it_does_not_log_user_in_if_user_was_not_found($userRepository, $session, UserInterface $user, Session $minkSession)
 {
     $userRoles = ['ROLE_USER'];
     $userRepository->findOneBy(array('username' => '*****@*****.**'))->willReturn(null);
     $user->getRoles()->willReturn($userRoles);
     $user->getPassword()->willReturn('xyz');
     $user->serialize()->willReturn('serialized_user');
     $session->set('_security_user', Argument::any())->shouldNotBeCalled();
     $session->save()->shouldNotBeCalled();
     $session->getName()->willReturn('MOCKEDSID');
     $session->getId()->willReturn('xyzc123');
     $minkSession->setCookie('MOCKEDSID', 'xyzc123')->shouldNotBeCalled();
     $this->shouldThrow(new \InvalidArgumentException(sprintf('There is no user with email sylius@example.com')))->during('logIn', array('*****@*****.**', 'default', $minkSession));
 }
Example #15
0
 /**
  * Test record tabs for a particular ID.
  *
  * @param Session $session  Session
  * @param string  $id       ID to load
  * @param bool    $encodeId Should we URL encode the ID?
  *
  * @return void
  */
 protected function tryRecordTabsOnId(Session $session, $id, $encodeId = true)
 {
     $url = $this->getVuFindUrl('/Record/' . ($encodeId ? rawurlencode($id) : $id));
     $session->visit($url);
     $this->assertEquals(200, $session->getStatusCode());
     $page = $session->getPage();
     $staffViewTab = $page->findById('details');
     $this->assertTrue(is_object($staffViewTab));
     $this->assertEquals('Staff View', $staffViewTab->getText());
     $staffViewTab->click();
     $this->assertEquals($url . '#details', $session->getCurrentUrl());
     $staffViewTable = $page->find('css', '#details-tab table.citation');
     $this->assertTrue(is_object($staffViewTable));
     $this->assertEquals('LEADER', substr($staffViewTable->getText(), 0, 6));
 }
Example #16
0
 /**
  *
  * @return array
  */
 public function shoot()
 {
     $this->_session = $this->_camera->get_session();
     // Iterate over shots
     foreach ($this->_shots as $shot) {
         /* @var $shot Shot */
         $output = $this->_shoot_shot($shot);
         $this->_log_out("Saving as " . $this->_film->get_root_folder() . $shot->get_destination_file());
         // Save output in folder
         if (empty($output)) {
             $this->_log_out("There was an error capturing this page. Please, check or retry. ");
             continue;
         }
         $saved_result = $this->_film->get_filesystem()->put($shot->get_destination_file(), $output);
         if (!$saved_result) {
             $this->_log_out("There was an error saving the screenshot. Please, check or retry. ");
             continue;
         }
         // It was successful, mark it
         $shot->set_completed(true);
     }
     // If session is open (it should) just close it
     if ($this->_session->isStarted()) {
         $this->_session->stop();
     }
     return $this->_shots;
 }
Example #17
0
 /**
  * Shut down the Mink session.
  *
  * @return void
  */
 protected function stopMinkSession()
 {
     if (!empty($this->session)) {
         $this->session->stop();
         $this->session = null;
     }
 }
 /**
  * Stops all sessions, that might have started.
  *
  * @return void
  */
 protected function tearDown()
 {
     parent::tearDown();
     if ($this->session !== null) {
         $this->session->reset();
     }
 }
Example #19
0
 /**
  * Visit specified URL.
  *
  * @param string $url Url of the page.
  *
  * @return void
  */
 public function visit($url)
 {
     if (!$this->isStarted()) {
         $this->start();
     }
     parent::visit($url);
 }
Example #20
0
 public function _after(\Codeception\TestCase $test)
 {
     //that call does not really terminate node process
     //@see https://github.com/symfony/symfony/issues/5499
     $this->session->stop();
     //so we kill it ourselves
     exec('killall ' . pathinfo($this->server->getNodeBin(), PATHINFO_BASENAME) . ' > /dev/null 2>&1');
 }
Example #21
0
 public function dontSeeInTitle($title)
 {
     $el = $this->session->getPage()->find('css', 'title');
     if (!$el) {
         return $this->assertTrue(true);
     }
     $this->assertNotContains($title, $el->getText(), "page title contains {$title}");
 }
Example #22
0
 /**
  * Initializes exception.
  *
  * @param string                  $message   optional message
  * @param DriverInterface|Session $driver    driver instance (or session for BC)
  * @param \Exception|null         $exception expectation exception
  */
 public function __construct($message, $driver, \Exception $exception = null)
 {
     if ($driver instanceof Session) {
         @trigger_error('Passing a Session object to the ExpectationException constructor is deprecated as of Mink 1.7. Pass the driver instead.', E_USER_DEPRECATED);
         $this->session = $driver;
         $this->driver = $driver->getDriver();
     } elseif (!$driver instanceof DriverInterface) {
         // Trigger an exception as we cannot typehint a disjunction
         throw new \InvalidArgumentException('The ExpectationException constructor expects a DriverInterface or a Session.');
     } else {
         $this->driver = $driver;
     }
     if (!$message && null !== $exception) {
         $message = $exception->getMessage();
     }
     parent::__construct($message, 0, $exception);
 }
Example #23
0
 /**
  * Get the Symfony driver.
  * 
  * @return BrowserKitDriver
  *
  * @throws UnsupportedDriverActionException when not using mink browser kit driver
  */
 protected function getSymfonyDriver()
 {
     $driver = $this->session->getDriver();
     if ($driver instanceof BrowserKitDriver === false) {
         throw new UnsupportedDriverActionException('Not using the Symfony Driver - current driver is %s', $driver);
     }
     return $driver;
 }
Example #24
0
 /**
  * Checks the value in field is not equal to value passed.
  * Field is searched by its id|name|label|value or CSS selector.
  *
  * @param $field
  * @param $value
  */
 public function dontSeeInField($field, $value)
 {
     $node = $this->session->getPage()->findField($field);
     if (!$node) {
         return \PHPUnit_Framework_Assert::fail(", field not found");
     }
     \PHPUnit_Framework_Assert::assertNotEquals($this->escape($value), $node->getValue());
 }
Example #25
0
 /**
  * @param string $name
  * @param array $parameters
  *
  * @return NodeElement
  */
 private function createElement($name, array $parameters = [])
 {
     $definedElements = $this->getDefinedElements();
     if (!isset($definedElements[$name])) {
         throw new \InvalidArgumentException(sprintf('Could not find a defined element with name "%s". The defined ones are: %s.', $name, implode(', ', array_keys($definedElements))));
     }
     $elementSelector = strtr($definedElements[$name], $parameters);
     return new NodeElement($this->getSelectorAsXpath($elementSelector, $this->session->getSelectorsHandler()), $this->session);
 }
Example #26
0
 /**
  * Returns response information string.
  *
  * @return  string
  */
 protected function getResponseInfo()
 {
     $driver = basename(str_replace('\\', '/', get_class($this->session->getDriver())));
     $info = '+--[ ';
     if (!in_array($driver, array('SahiDriver', 'SeleniumDriver'))) {
         $info .= 'HTTP/1.1 ' . $this->session->getStatusCode() . ' | ';
     }
     $info .= $this->session->getCurrentUrl() . ' | ' . $driver . " ]\n|\n";
     return $info;
 }
 /**
  * @param $not
  * @param TableNode $paths
  *
  * @throws \Exception
  *
  * @Given /^user should(| not) have an access to the following pages:$/
  */
 public function checkUserAccessToPages($not, TableNode $paths)
 {
     $result = [];
     $code = $not ? 403 : 200;
     // Use "GoutteDriver" to have an ability to check answer code.
     $driver = new Mink\Driver\GoutteDriver();
     $session = new Mink\Session($driver);
     $session->start();
     foreach (array_keys($paths->getRowsHash()) as $path) {
         $path = trim($path, '/');
         $session->visit($this->locatePath($path));
         if ($session->getStatusCode() !== $code) {
             $result[] = $path;
         }
     }
     if (!empty($result)) {
         throw new \Exception(sprintf('The following paths: "%s" are %s accessible!', implode(', ', $result), $not ? '' : 'not'));
     }
 }
Example #28
0
 /**
  * @return $session 
  */
 public static function login($username, $password)
 {
     $driver = new GoutteDriver();
     $session = new Session($driver);
     $session->start();
     $session->visit('https://github.com/login');
     $page = $session->getPage();
     $form = $page->find('css', '.auth-form form');
     if (null === $form) {
         throw new \Exception('Couldn\'t locate the login form.');
     }
     $form->fillField('login_field', $username);
     $form->fillField('password', $password);
     $form->submit();
     // @todo need to check if successfully logged in here...
     $dumper = new Dumper();
     file_put_contents(__DIR__ . '/../settings.yml', $dumper->dump(['github' => ['username' => $username, 'password' => $password]], 2));
     return $session;
 }
 protected function makeScreenshot()
 {
     if (empty($this->session)) {
         return 'No session';
     }
     try {
         $name = date('Y-m-d_H:i:s') . '.png';
         file_put_contents('/tmp/' . $name, $this->session->getScreenshot());
         $imageUrl = $this->getUploader()->upload('/tmp/' . $name);
     } catch (\Exception $e) {
         $imageUrl = $e->getMessage();
     }
     return $imageUrl;
 }
Example #30
0
 /**
  * Creates Mink session using current session strategy and returns it.
  *
  * @return Session
  */
 public function getSession()
 {
     if ($this->_session) {
         return $this->_session;
     }
     $browser = $this->getBrowser();
     try {
         $this->_session = $this->getSessionStrategy()->session($browser);
         if ($this->getCollectCodeCoverageInformation()) {
             $this->_session->visit($browser->getBaseUrl());
         }
     } catch (DriverException $e) {
         $message = 'The Selenium Server is not active on host %s at port %s';
         $this->markTestSkipped(sprintf($message, $browser->getHost(), $browser->getPort()));
     }
     return $this->_session;
 }