/**
  * 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');
 }
 /**
  * @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;
 }
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $this->page = $this->prophesize(DocumentElement::class);
     $this->session = $this->prophesize(Session::class);
     $this->session->getPage()->willReturn($this->page->reveal());
     $this->webAssert = $this->prophesize(WebAssert::class);
 }
 public function openPage($url)
 {
     $session = new Session($this->getDriver());
     $session->start();
     $session->visit($url);
     $this->page = $session->getPage();
 }
Example #5
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 #6
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 #7
0
 /**
  * @Given /^I am on "([^"]*)"$/
  */
 public function iAmOn($arg1)
 {
     if (!$this->session) {
         $this->iOpenBrowser();
     }
     $url = $arg1;
     $this->session->visit($url);
     $this->page = $this->session->getPage();
 }
Example #8
0
 /**
  * Check if a select has an option.
  * 
  * @param string $select
  * @param string $option
  *
  * @return bool True if the option found in the select, else false
  */
 protected function checkSelectContainsOption($select, $option)
 {
     $obj = $this->session->getPage()->findField($select);
     if ($obj === null) {
         throw new \Exception(sprintf('Select box "%s" not found', $select));
     }
     $optionText = $obj->getText();
     $regex = '/' . preg_quote($option, '/') . '/ui';
     return preg_match($regex, $optionText) > 0;
 }
Example #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));
 }
Example #10
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;
 }
Example #11
0
 public function grabTextFrom($cssOrXPathOrRegex)
 {
     $el = null;
     if (Locator::isCSS($cssOrXPathOrRegex)) {
         $el = $this->session->getPage()->find('css', $cssOrXPathOrRegex);
         if ($el) {
             return $el->getText();
         }
     }
     if (!$el and Locator::isXPath($cssOrXPathOrRegex)) {
         $el = @$this->session->getPage()->find('xpath', $cssOrXPathOrRegex);
         if ($el) {
             return $el->getText();
         }
     }
     if (@preg_match($cssOrXPathOrRegex, $this->session->getPage()->getContent(), $matches)) {
         return $matches[1];
     }
     throw new ElementNotFound($cssOrXPathOrRegex, 'CSS or XPath or Regex');
 }
Example #12
0
 public function grabTextFrom($cssOrXPathOrRegex)
 {
     $el = null;
     try {
         $el = $this->session->getPage()->find('css', $cssOrXPathOrRegex);
     } catch (\Symfony\Component\CssSelector\Exception\ParseException $e) {
     }
     if ($el) {
         return $el->getText();
     }
     if (!$el) {
         $el = @$this->session->getPage()->find('xpath', $cssOrXPathOrRegex);
     }
     if ($el) {
         return $el->getText();
     }
     if (@preg_match($cssOrXPathOrRegex, $this->session->getPage()->getContent(), $matches)) {
         return $matches[1];
     }
     $this->fail("Element that matches '{$cssOrXPathOrRegex}' not found");
 }
Example #13
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();
 /**
  * If this was a POST request - we send something to the #extra_msg container
  *
  * @return bool
  */
 protected function wasPostRequest()
 {
     $extraMsg = $this->session->getPage()->find('css', '#extra_msg')->getText();
     return !empty($extraMsg);
 }
 /**
  * @Then I should get :expectedString
  */
 public function iShouldGet($expectedString)
 {
     $body = $this->session->getPage()->getContent();
     PHPUnit_Framework_Assert::assertEquals($expectedString, unserialize($body));
 }
 public function testGetPage()
 {
     $this->assertInstanceOf('Behat\\Mink\\Element\\DocumentElement', $this->session->getPage());
 }
Example #17
0
 /**
  * Guesses a basic field type and returns it.
  *
  * This method is intended to detect HTML form fields when no
  * moodleform-specific elements have been detected.
  *
  * @param NodeElement $fieldnode
  * @param Session $session
  * @return string|bool The field type or false.
  */
 public static function guess_field_type(NodeElement $fieldnode, Session $session)
 {
     // Textareas are considered text based elements.
     $tagname = strtolower($fieldnode->getTagName());
     if ($tagname == 'textarea') {
         // If there is an iframe with $id + _ifr there a TinyMCE editor loaded.
         $xpath = '//div[@id="' . $fieldnode->getAttribute('id') . 'editable"]';
         if ($session->getPage()->find('xpath', $xpath)) {
             return 'editor';
         }
         return 'textarea';
     } else {
         if ($tagname == 'input') {
             $type = $fieldnode->getAttribute('type');
             switch ($type) {
                 case 'text':
                 case 'password':
                 case 'email':
                 case 'file':
                     return 'text';
                 case 'checkbox':
                     return 'checkbox';
                     break;
                 case 'radio':
                     return 'radio';
                     break;
                 default:
                     // Here we return false because all text-based
                     // fields should be included in the first switch case.
                     return false;
             }
         } else {
             if ($tagname == 'select') {
                 // Select tag.
                 return 'select';
             }
         }
     }
     // We can not provide a closer field type.
     return false;
 }
Example #18
0
 /**
  * @param Session $session
  *
  * @return string|null
  */
 private function getRequestContentLogMessage(Session $session)
 {
     try {
         return 'Response content:' . "\n" . $session->getPage()->getContent() . "\n";
     } catch (MinkException $exception) {
         return null;
     }
 }
 /**
  * Opens order history page.
  *
  * @param \Behat\Mink\Session $oMinkSession
  */
 private function _openOrderHistory($oMinkSession)
 {
     $oMinkSession->visit(shopURL . "en/order-history/");
     $oPage = $oMinkSession->getPage();
     $oLoginInput = $oPage->find('xpath', "//input[contains(@id, 'loginUser')]");
     $oPasswordInput = $oPage->find('xpath', "//input[contains(@id, 'loginPwd')]");
     $oLoginButton = $oPage->find('xpath', "//button[contains(@id, 'loginButton')]");
     $oLoginInput->setValue('*****@*****.**');
     $oPasswordInput->setValue('useruser');
     $oLoginButton->click();
     $oContentTitle = $oPage->find('xpath', "//section[contains(@id, 'content')]/h1");
     $this->assertEquals('%PAGE_TITLE_ACCOUNT_ORDER%', $oContentTitle->getText(), 'Given page title: "' . $oContentTitle->getText() . '" is not same.');
     $this->checkForErrors();
 }
Example #20
0
 /** @noinspection MoreThanThreeArgumentsInspection
  * @param Module $module
  * @param Session $session
  * @param int $wait
  * @param bool $makeSS
  */
 private function openModule(Module $module, Session $session, $wait = 100, $makeSS = false)
 {
     $page = $session->getPage();
     $nav = $page->findById('nav');
     $container = $nav->findById('mi_' . $module->getId());
     $link = $container->find('css', 'a:first-child');
     $link->click();
     $this->wait($wait);
     if ($makeSS) {
         Mink::getInstance()->ss();
     }
 }
Example #21
0
 /**
  * Checks, that page contains specified text
  *
  * @param Session $session
  * @param string  $text     text to look for
  * @param string  $message  optional message to show on fail
  *
  * @throws ResponseTextException
  *
  * @return void
  */
 public static function assertPageContainsText(Session $session, $text, $message = null)
 {
     $text = str_replace('\\"', '"', $text);
     $haystack = $session->getPage()->getText();
     $message = $message ?: sprintf('The text "%s" was not found anywhere in the text of the page', $text);
     $constraint = new PageContainsConstraint($text, false);
     self::assertThat($haystack, $constraint, $message);
 }
Example #22
0
 /**
  * Get a reference to a standard search results page.
  *
  * @param Session $session Mink session
  *
  * @return Element
  */
 protected function getSearchResultsPage(Session $session)
 {
     $path = '/Search/Results?lookfor=id%3A(testsample1+OR+testsample2)';
     $session->visit($this->getVuFindUrl() . $path);
     return $session->getPage();
 }
 /**
  * Checks, that content is present on a page.
  *
  * @param string $content Content to find.
  *
  * @return void
  */
 protected function assertPageContains($content)
 {
     $page_content = $this->session->getPage()->getContent();
     $this->assertTrue(strpos($page_content, $content) !== false, 'Page contains "' . $content . '" content');
 }
Example #24
0
 /**
  * Helper function to get some information about the current page
  * Possible modes are 'controller', 'action' and 'template' or a combination of them
  * Please note, that 'template' only works in combination with 'controller' and/or 'action'.
  * @param \Behat\Mink\Session $session
  * @param array $selectionMode
  * @return array|bool
  */
 public static function getPageInfo(\Behat\Mink\Session $session, array $selectionMode)
 {
     $prefixes = ['emotion' => ['controller' => 'ctl_'], 'responsive' => ['controller' => 'is--ctl-', 'action' => 'is--act-']];
     $body = $session->getPage()->find('css', 'body');
     $class = $body->getAttribute('class');
     foreach ($prefixes as $template => $modes) {
         $activeModes = [];
         foreach ($modes as $mode => $prefix) {
             if (in_array($mode, $selectionMode)) {
                 $activeModes[] = $prefix . '([A-Za-z]+)';
             }
         }
         if (empty($activeModes)) {
             continue;
         }
         $regex = '/' . implode(' ', $activeModes) . '/';
         if (preg_match($regex, $class, $mode) !== 1) {
             continue;
         }
         $result = array_fill_keys($selectionMode, null);
         if (array_key_exists('controller', $result)) {
             $result['controller'] = $mode['1'];
             if (array_key_exists('action', $result) && isset($mode['2'])) {
                 $result['action'] = $mode['2'];
             }
         } elseif (array_key_exists('action', $result) && isset($mode['1'])) {
             $result['action'] = $mode['1'];
         }
         if (array_key_exists('template', $result)) {
             $result['template'] = $template;
         }
         return $result;
     }
     return false;
 }
Example #25
0
 protected function visit($path)
 {
     $this->session->visit(rtrim($this->baseUrl, '/') . '/' . ltrim($path, '/'));
     return $this->session->getPage();
 }
Example #26
0
 public function testExample()
 {
     $this->session->visit('localhost');
     $page = $this->session->getPage();
     $this->session->{$this}->assertEquals('Mink is a php 5.3 library that you’ll use inside your test suites or project. Before you begin, ensure that you have at least PHP 5.3.1 installed.', $page->find('css', 'h1')->getText());
 }
 /**
  * @param string $url
  * @return \Behat\Mink\Element\DocumentElement
  */
 protected function visit($url)
 {
     $this->session->visit($url);
     return $this->session->getPage();
 }
 /**
  * @return NodeElement
  */
 private function getMessageElement()
 {
     return $this->session->getPage()->find('css', self::NOTIFICATION_ELEMENT_CSS);
 }