Ejemplo n.º 1
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'], '/') . '/');
 }
Ejemplo n.º 2
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();
 }
Ejemplo n.º 3
0
 /**
  * {@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.');
 }
Ejemplo n.º 4
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.');
 }
Ejemplo n.º 5
0
 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]]);
 }
Ejemplo n.º 6
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');
 }
Ejemplo n.º 7
0
 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());
 }
Ejemplo n.º 8
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;
 }
Ejemplo n.º 9
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));
 }
Ejemplo n.º 10
0
 public function grabFromCurrentUrl($uri = null)
 {
     if (!$uri) {
         return $this->session->getCurrentUrl();
     }
     $matches = array();
     $res = preg_match($uri, $this->session->getCurrentUrl(), $matches);
     if (!$res) {
         $this->fail("Couldn't match {$uri} in " . $this->session->getCurrentUrl());
     }
     if (!isset($matches[1])) {
         $this->fail("Nothing to grab. A regex parameter required. Ex: '/user/(\\d+)'");
     }
     return $matches[1];
 }
Ejemplo n.º 11
0
 /**
  * Checks if the given page is currently opened in browser.
  *
  * @param Page $page Page to check.
  *
  * @return boolean
  */
 public function opened(Page $page)
 {
     return $this->pageUrlMatcherRegistry->match($this->_session->getCurrentUrl(), $page);
 }
Ejemplo n.º 12
0
 public function testGetCurrentUrl()
 {
     $this->driver->expects($this->once())->method('getCurrentUrl')->will($this->returnValue($ret = 'http://some.url'));
     $this->assertEquals($ret, $this->session->getCurrentUrl());
 }
Ejemplo n.º 13
0
<?php

require_once __DIR__ . '/vendor/autoload.php';
use Behat\Mink\Driver\GoutteDriver;
use Behat\Mink\Session;
use Behat\Mink\Driver\Selenium2Driver;
//$driver = new GoutteDriver();
$driver = new Selenium2Driver();
$session = new Session($driver);
$session->start();
$session->visit('http://jurassicpark.wikia.com');
//echo "Status code: ". $session->getStatusCode() . "\n";
echo "Current URL: " . $session->getCurrentUrl() . "\n";
$page = $session->getPage();
echo "First 160 chars: " . substr($page->getText(), 0, 160) . "\n";
//$anchorEle = $page->find('css', 'h3 a.title');
//$spanEle = $anchorElement->find('css', 'span.emph');
$element = $page->find('css', '.subnav-2 li a');
echo "The link text is: " . $element->getText() . "\n";
$selectorsHandler = $session->getSelectorsHandler();
$element = $page->find('named', array('link', $selectorsHandler->xpathLiteral('Random page')));
$element = $page->findLink('Random page');
echo sprintf("The URL is '%s'\n", $element->getAttribute('href'));
$element->click();
$element->click();
echo "Page URL after click: " . $session->getCurrentUrl() . "\n";
//behat-ls/vendor/behat/mink/src/Behat/Mink/Selector/NamedSelector.php@$selectors
$session->stop();
 /**
  * @param string $name
  * @param Session  $subject
  * @param array  $arguments
  *
  * @return FailureException
  */
 protected function getFailureException($name, $subject, array $arguments)
 {
     return new FailureException(sprintf('Expected session to have status code %s, but it is %s.', $this->presenter->presentValue($subject->getCurrentUrl()), $this->presenter->presentValue($arguments[0])));
 }
Ejemplo n.º 15
0
<?php

require __DIR__ . '/vendor/autoload.php';
use Behat\Mink\Driver\GoutteDriver;
use Behat\Mink\Driver\Selenium2Driver;
use Behat\Mink\Session;
//$driver = new GoutteDriver();
$driver = new Selenium2Driver();
$session = new Session($driver);
$session->start();
$session->visit('http://jurassicpark.wikia.com');
//echo "The status code is ".$session->getStatusCode()."\n";
echo "The current URL is " . $session->getCurrentUrl() . "\n";
// Hallo! I'm a DocumentElement
$page = $session->getPage();
echo "The start of the page text is " . substr($page->getText(), 0, 56) . "\n";
// And I'm a NodeElement!
$nodeElement = $page->find('css', '.subnav-2 li a');
echo "The matched link text is " . $nodeElement->getText() . "\n";
$randomLink = $page->findLink('Random page');
echo "The matched URL is " . $randomLink->getAttribute('href') . "\n";
$randomLink->click();
echo "The new URL is " . $session->getCurrentUrl() . "\n";
$session->stop();
 /**
  * @param string $name
  * @param Session  $subject
  * @param array  $arguments
  *
  * @return FailureException
  */
 protected function getNegativeFailureException($name, $subject, array $arguments)
 {
     return new FailureException(sprintf('Expected %s not to match %s, but it does.', $this->presenter->presentString($this->cleanPath($subject->getCurrentUrl())), $this->presenter->presentString($arguments[0])));
 }
Ejemplo n.º 17
0
 /**
  * Checks if current url contains the $uri.
  *
  * @param $uri
  */
 public function seeInCurrentUrl($uri)
 {
     \PHPUnit_Framework_Assert::assertContains($uri, $this->session->getCurrentUrl(), '');
 }