public function testLocatingElementPosition()
 {
     $this->assertEquals('(descendant-or-self::p)[position()=1]', Locator::firstElement('p'));
     $this->assertEquals('(descendant-or-self::p)[position()=last()]', Locator::lastElement('p'));
     $this->assertEquals('(descendant-or-self::p)[position()=1]', Locator::elementAt('p', 1));
     $this->assertEquals('(descendant-or-self::p)[position()=last()-0]', Locator::elementAt('p', -1));
     $this->assertEquals('(descendant-or-self::p)[position()=last()-1]', Locator::elementAt('p', -2));
 }
Example #2
0
 public function testIsId()
 {
     $this->assertTrue(Locator::isID('#username'));
     $this->assertTrue(Locator::isID('#user.name'));
     $this->assertTrue(Locator::isID('#user-name'));
     $this->assertFalse(Locator::isID('#user-name .field'));
     $this->assertFalse(Locator::isID('.field'));
     $this->assertFalse(Locator::isID('hello'));
 }
 /**
  * Login the admin user using his email
  *
  * @param \AcceptanceTester $I
  */
 public function loginAdminUserTest(\AcceptanceTester $I)
 {
     $I->wantTo('log into the backend as Admin with email');
     $I->loginWithEmailAs($this->user['admin']);
     $this->saveLogin($I);
     $I->see('Dashboard');
     $I->see('Configuration', Locator::href('/bolt/users'));
     $I->see("You've been logged on successfully.");
 }
 /**
  * Login the admin user using his email
  *
  * @param \AcceptanceTester $I
  */
 public function loginAdminUserTest(\AcceptanceTester $I)
 {
     $I->wantTo('log into the backend as Admin with email');
     $I->loginWithEmailAs($this->user['admin']);
     $this->cookies[$this->tokenNames['authtoken']] = $I->grabCookie($this->tokenNames['authtoken']);
     $this->cookies[$this->tokenNames['session']] = $I->grabCookie($this->tokenNames['session']);
     $I->see('Dashboard');
     $I->see('Configuration', Locator::href('/bolt/users'));
     $I->see("You've been logged on successfully.");
 }
Example #5
0
 public function testHumanReadableString()
 {
     $this->assertEquals("'string selector'", Locator::humanReadableString("string selector"));
     $this->assertEquals("css '.something'", Locator::humanReadableString(['css' => '.something']));
     $this->assertEquals("css selector '.something'", Locator::humanReadableString(WebDriverBy::cssSelector('.something')));
     try {
         Locator::humanReadableString(null);
         $this->fail("Expected exception when calling humanReadableString() with invalid selector");
     } catch (\InvalidArgumentException $e) {
     }
 }
 protected function fail($nodes, $selector, ComparisonFailure $comparisonFailure = null)
 {
     $selectorString = Locator::humanReadableString($selector);
     if (!$this->string) {
         throw new \PHPUnit_Framework_ExpectationFailedException("Element {$selectorString} was found", $comparisonFailure);
     }
     $output = "There was {$selectorString} element";
     $output .= $this->uriMessage("on page");
     $output .= str_replace($this->string, "<bold>{$this->string}</bold>", $this->nodesList($nodes, $this->string));
     $output .= "\ncontaining '{$this->string}'";
     throw new \PHPUnit_Framework_ExpectationFailedException($output, $comparisonFailure);
 }
Example #7
0
 public function testGetArguments()
 {
     $by = WebDriverBy::cssSelector('.something');
     $step = $this->getStep([null, [$by]]);
     $this->assertEquals('"' . Locator::humanReadableString($by) . '"', $step->getArguments(true));
     $step = $this->getStep([null, [['just', 'array']]]);
     $this->assertEquals('"just","array"', $step->getArguments(true));
     $step = $this->getStep([null, [function () {
     }]]);
     $this->assertEquals('"lambda function"', $step->getArguments(true));
     $step = $this->getStep([null, [[$this, 'testGetArguments']]]);
     $this->assertEquals('"callable function"', $step->getArguments(true));
 }
Example #8
0
 public function testGetArguments()
 {
     $by = WebDriverBy::cssSelector('.something');
     $step = $this->getStep([null, [$by]]);
     $this->assertEquals('"' . Locator::humanReadableString($by) . '"', $step->getArgumentsAsString());
     $step = $this->getStep([null, [['just', 'array']]]);
     $this->assertEquals('["just","array"]', $step->getArgumentsAsString());
     $step = $this->getStep([null, [function () {
     }]]);
     $this->assertEquals('"Closure"', $step->getArgumentsAsString());
     $step = $this->getStep([null, [[$this, 'testGetArguments']]]);
     $this->assertEquals('["StepTest","testGetArguments"]', $step->getArgumentsAsString());
     $step = $this->getStep([null, [['PDO', 'getAvailableDrivers']]]);
     $this->assertEquals('["PDO","getAvailableDrivers"]', $step->getArgumentsAsString());
 }
Example #9
0
 protected function fail($nodes, $selector, ComparisonFailure $comparisonFailure = null)
 {
     if (!count($nodes)) {
         throw new ElementNotFound($selector, 'Element located either by name, CSS or XPath');
     }
     $output = "Failed asserting that any element by " . Locator::humanReadableString($selector);
     $output .= $this->uriMessage('on page');
     if (count($nodes) < 5) {
         $output .= "\nElements: ";
         $output .= $this->nodesList($nodes);
     } else {
         $message = new Message("[total %s elements]");
         $output .= $message->with(count($nodes))->style('debug');
     }
     $output .= "\ncontains text '" . $this->string . "'";
     throw new \PHPUnit_Framework_ExpectationFailedException($output, $comparisonFailure);
 }
Example #10
0
 /**
  * Create a page record.
  *
  * @param \AcceptanceTester $I
  */
 public function createRecordsTest(\AcceptanceTester $I)
 {
     $I->wantTo("Create and edit Pages as the 'editor' user");
     // Set up the browser
     $I->setCookie('bolt_authtoken', $this->cookies['bolt_authtoken']);
     $I->setCookie('bolt_session', $this->cookies['bolt_session']);
     $I->amOnPage('/bolt');
     $I->see('New Page');
     $I->click('New Page');
     $I->see('Pages', Locator::href('/bolt/overview/pages'));
     $I->see('View Pages', Locator::href('/bolt/overview/pages'));
     $I->see('New Page', Locator::href('/bolt/editcontent/pages'));
     $I->fillField('#title', 'A page I made');
     $I->fillField('#teaser', 'Woop woop woop! Crazy nice stuff inside!');
     $I->fillField('#body', 'Take it, take it! I have three more of these!');
     $I->click('Save Page');
     $I->see('The new Page has been saved.');
     $I->see('A page I made');
     $I->see('Woop woop woop');
 }
Example #11
0
 public function test_default_non_editable_department_named_company(SuperUser $i)
 {
     $i->wantTo('Test if default "Company" named department is there and it is non editable');
     $i->login('*****@*****.**');
     $i->clickMenu('HR->Department');
     $i->see('Company', Locator::elementAt('//table/tbody/tr/td', 1));
     $i->dontSeeElementInDOM('table tbody tr:first-child  td:last-child a');
     $i->wantTo('Test Quick Search');
     $i->searchFor('comp');
     $i->see('Company', Locator::elementAt('//table/tbody/tr/td', 1));
     $i->searchFor('xxxxssssss');
     $i->see('No matching records found');
     $i->searchFor('');
     $i->dontSee('No matching records found');
     $i->see('Company', Locator::elementAt('//table/tbody/tr/td', 1));
     $i->click('Active');
     $i->waitPageLoad();
     $i->click('InActive');
     $i->waitPageLoad();
 }
Example #12
0
 /**
  * @param $page
  * @param $selector
  * @param bool $throwMalformed
  * @return array
  */
 protected function match($page, $selector, $throwMalformed = true)
 {
     if (is_array($selector)) {
         try {
             return $page->findElements($this->getStrictLocator($selector));
         } catch (InvalidSelectorException $e) {
             throw new MalformedLocatorException(key($selector) . ' => ' . reset($selector), "Strict locator");
         }
     }
     if ($selector instanceof WebDriverBy) {
         try {
             return $page->findElements($selector);
         } catch (InvalidSelectorException $e) {
             throw new MalformedLocatorException(sprintf("WebDriverBy::%s('%s')", $selector->getMechanism(), $selector->getValue()), 'WebDriver');
         }
     }
     $isValidLocator = false;
     $nodes = [];
     try {
         if (Locator::isID($selector)) {
             $isValidLocator = true;
             $nodes = $page->findElements(WebDriverBy::id(substr($selector, 1)));
         }
         if (empty($nodes) and Locator::isCSS($selector)) {
             $isValidLocator = true;
             $nodes = $page->findElements(WebDriverBy::cssSelector($selector));
         }
         if (empty($nodes) and Locator::isXPath($selector)) {
             $isValidLocator = true;
             $nodes = $page->findElements(WebDriverBy::xpath($selector));
         }
     } catch (InvalidSelectorException $e) {
         throw new MalformedLocatorException($selector);
     }
     if (!$isValidLocator and $throwMalformed) {
         throw new MalformedLocatorException($selector);
     }
     return $nodes;
 }
Example #13
0
 /**
  * Test the 'File management -> View / edit templates' interface
  *
  * @param \AcceptanceTester $I
  */
 public function fileManagementViewEditTemplatesTest(\AcceptanceTester $I)
 {
     $I->wantTo("Use the 'File management -> View / edit templates' interface as the 'developer' user");
     // Set up the browser
     $this->setLoginCookies($I);
     $I->amOnPage('/bolt/files/themes');
     // Inspect the landing page
     $dir = 'base-2016';
     $I->see('Create folder', Locator::find('a', ['href' => '#']));
     $I->see($dir, Locator::href("/bolt/files/themes/{$dir}"));
     $I->see("Rename {$dir}", Locator::find('a', ['href' => '#']));
     $I->see("Delete {$dir}", Locator::find('a', ['href' => '#']));
     // Navigate into the theme and check the results
     $I->click("{$dir}", Locator::href("/bolt/files/themes/{$dir}"));
     $I->see('css', Locator::href("/bolt/files/themes/{$dir}/css"));
     $I->see('images', Locator::href("/bolt/files/themes/{$dir}/images"));
     $I->see('js', Locator::href("/bolt/files/themes/{$dir}/js"));
     $I->see('theme.yml', Locator::href("/bolt/file/edit/themes/{$dir}/theme.yml"));
     $I->see('record.twig', Locator::href("/bolt/file/edit/themes/{$dir}/record.twig"));
     $I->see('index.twig', Locator::href("/bolt/file/edit/themes/{$dir}/index.twig"));
     // Navigate into a subdirectory
     $I->click('css', Locator::href("/bolt/files/themes/{$dir}/css"));
     $I->see('theme.css', Locator::href("/bolt/file/edit/themes/{$dir}/css/theme.css"));
 }
Example #14
0
 /**
  * @param $locator
  * @return Crawler
  */
 protected function filterByXPath($locator)
 {
     if (!Locator::isXPath($locator)) {
         throw new MalformedLocatorException($locator, 'xpath');
     }
     return $this->getCrawler()->filterXPath($locator);
 }
Example #15
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 #16
0
 public function testGetArguments()
 {
     $by = WebDriverBy::cssSelector('.something');
     $step = $this->getMockBuilder('\\Codeception\\Step')->setConstructorArgs([null, [$by]])->setMethods(null)->getMock();
     $this->assertEquals('"' . Locator::humanReadableString($by) . '"', $step->getArguments(true));
 }
Example #17
0
 protected function stringifyArgument($argument)
 {
     if (is_string($argument)) {
         return '"' . strtr($argument, ["\n" => '\\n', "\r" => '\\r', "\t" => ' ']) . '"';
     } elseif (is_resource($argument)) {
         $argument = (string) $argument;
     } elseif (is_array($argument)) {
         foreach ($argument as $key => $value) {
             if (is_object($value)) {
                 $argument[$key] = $this->getClassName($value);
             }
         }
     } elseif (is_object($argument)) {
         if (method_exists($argument, '__toString')) {
             $argument = (string) $argument;
         } elseif (get_class($argument) == 'Facebook\\WebDriver\\WebDriverBy') {
             $argument = Locator::humanReadableString($argument);
         } else {
             $argument = $this->getClassName($argument);
         }
     }
     return json_encode($argument, JSON_UNESCAPED_UNICODE);
 }
 public function testStrictLocators()
 {
     $this->module->amOnPage('/login');
     $this->module->seeElement(['id' => 'submit-label']);
     $this->module->seeElement(['name' => 'password']);
     $this->module->seeElement(['class' => 'optional']);
     $this->module->seeElement(['css' => 'form.global_form_box']);
     $this->module->seeElement(['xpath' => \Codeception\Util\Locator::tabIndex(4)]);
     $this->module->fillField(['name' => 'password'], '123456');
     $this->module->amOnPage('/form/select');
     $this->module->selectOption(['name' => 'age'], 'child');
     $this->module->amOnPage('/form/checkbox');
     $this->module->checkOption(['name' => 'terms']);
     $this->module->amOnPage('/');
     $this->module->seeElement(['link' => 'Test']);
     $this->module->click(['link' => 'Test']);
     $this->module->seeCurrentUrlEquals('/form/hidden');
 }
Example #19
0
    protected function match($selector)
    {
        try {
            $selector = CssSelector::toXPath($selector);
        } catch (ParseException $e) {
        }
        if (!Locator::isXPath($selector)) return null;

        return @$this->crawler->filterXPath($selector);
    }
    $I->see('Test plant latin', 'tr td');
}
$I = new AcceptanceTester($scenario);
$I->wantTo('Edit plant');
/*
 * The user creates a plant width all the information on a plant.
 */
helperCreatePlant($I);
/*
 * He is now on the front page and he wants to edit the newly created plant.
 */
$plantID = $I->grabRecord('plants', array('name' => 'Test plant'))->id;
/*
 * He clicks on the link "mere.." at the plant.
 */
$I->click('Mere..', Locator::href('/plant-detail/' . $plantID));
/*
 * Here he sees all the information on the plant has been saved correct.
 */
$I->seeInCurrentUrl('plant-detail/' . $plantID);
/*
 * Now he clicks on the edit button for the plant.
 */
$I->click('edit plant');
/*
 * The page redirects him to the edit page
 */
$I->seeInCurrentUrl('show-edit-plant');
/*
 * Here he sees all the checkboxes is checked correctly.
 */
Example #21
0
 /**
  * @param $selector
  *
  * @return Crawler
  */
 protected function match($selector)
 {
     if (is_array($selector)) {
         return $this->strictMatch($selector);
     }
     try {
         $selector = CssSelector::toXPath($selector);
     } catch (ParseException $e) {
     }
     if (!Locator::isXPath($selector)) {
         return null;
     }
     return @$this->crawler->filterXPath($selector);
 }
Example #22
0
 /**
  * Test that the 'developer' user can configure installed extensions.
  *
  * @param \AcceptanceTester $I
  */
 public function configureInstalledExtensions(\AcceptanceTester $I, \Codeception\Scenario $scenario)
 {
     $I->wantTo("See that the 'developer' user can configure installed extensions.");
     // Set up the browser
     $I->setCookie($this->tokenNames['authtoken'], $this->cookies[$this->tokenNames['authtoken']]);
     $I->setCookie($this->tokenNames['session'], $this->cookies[$this->tokenNames['session']]);
     $I->amOnPage('/bolt/files/config/extensions');
     $I->see('testerevents.bolt.yml', Locator::href('/bolt/file/edit/config/extensions/testerevents.bolt.yml'));
     $I->click('testerevents.bolt.yml', Locator::href('/bolt/file/edit/config/extensions/testerevents.bolt.yml'));
     $I->see('# Sit back and breathe', 'textarea');
     $I->see('its_nice_to_know_you_work_alone: true', 'textarea');
     // Edit the field
     $twig = $I->grabTextFrom('#form_contents', 'textarea');
     $twig .= PHP_EOL . "# Let's make this perfectly clear";
     $twig .= PHP_EOL . 'theres_no_secrets_this_year: true' . PHP_EOL;
     $I->fillField('#form_contents', $twig);
     $token = $I->grabValueFrom('#form__token');
     $I->sendAjaxPostRequest('/bolt/file/edit/config/extensions/testerevents.bolt.yml', ['form[_token]' => $token, 'form[contents]' => $twig]);
     $I->amOnPage('/bolt/file/edit/config/extensions/testerevents.bolt.yml');
     $I->see("# Let's make this perfectly clear", 'textarea');
     $I->see('theres_no_secrets_this_year: true', 'textarea');
 }
Example #23
0
 /**
  * @param $selector
  * @return WebDriverBy
  * @throws \InvalidArgumentException
  */
 protected function getLocator($selector)
 {
     if ($selector instanceof WebDriverBy) {
         return $selector;
     }
     if (is_array($selector)) {
         return $this->getStrictLocator($selector);
     }
     if (Locator::isID($selector)) {
         return WebDriverBy::id(substr($selector, 1));
     }
     if (Locator::isCSS($selector)) {
         return WebDriverBy::cssSelector($selector);
     }
     if (Locator::isXPath($selector)) {
         return WebDriverBy::xpath($selector);
     }
     throw new \InvalidArgumentException("Only CSS or XPath allowed");
 }
Example #24
0
 public function __construct($selector, $message = null)
 {
     $selector = Locator::humanReadableString($selector);
     parent::__construct($message . " element with {$selector} was not found.");
 }
Example #25
0
 protected function parseArgumentAsString($argument)
 {
     if (is_object($argument)) {
         if (method_exists($argument, '__toString')) {
             return (string) $argument;
         }
         if (get_class($argument) == 'Facebook\\WebDriver\\WebDriverBy') {
             return Locator::humanReadableString($argument);
         }
         return $this->getClassName($argument);
     }
     if (is_array($argument)) {
         foreach ($argument as $key => $value) {
             if (is_object($value)) {
                 $argument[$key] = $this->getClassName($value);
             }
         }
         return $argument;
     }
     if (is_resource($argument)) {
         return (string) $argument;
     }
     return $argument;
 }
Example #26
0
 /**
  * @param $page
  * @param $selector
  * @return array
  */
 protected function match($page, $selector)
 {
     $nodes = array();
     if (is_array($selector)) {
         return $page->findElements($this->getWebDriverLocator($selector));
     }
     if ($selector instanceof \WebDriverBy) {
         return $page->findElements($selector);
     }
     if (Locator::isID($selector)) {
         $nodes = $page->findElements(\WebDriverBy::id(substr($selector, 1)));
     }
     if (!empty($nodes)) {
         return $nodes;
     }
     if (Locator::isCSS($selector)) {
         $nodes = $page->findElements(\WebDriverBy::cssSelector($selector));
     }
     if (!empty($nodes)) {
         return $nodes;
     }
     if (Locator::isXPath($selector)) {
         $nodes = $page->findElements(\WebDriverBy::xpath($selector));
     }
     return $nodes;
 }
Example #27
0
 public function testWebDriverByLocators()
 {
     $this->module->amOnPage('/login');
     $this->module->seeElement(WebDriverBy::id('submit-label'));
     $this->module->seeElement(WebDriverBy::name('password'));
     $this->module->seeElement(WebDriverBy::className('optional'));
     $this->module->seeElement(WebDriverBy::cssSelector('form.global_form_box'));
     $this->module->seeElement(WebDriverBy::xpath(\Codeception\Util\Locator::tabIndex(4)));
     $this->module->fillField(WebDriverBy::name('password'), '123456');
     $this->module->amOnPage('/form/select');
     $this->module->selectOption(WebDriverBy::name('age'), 'child');
     $this->module->amOnPage('/form/checkbox');
     $this->module->checkOption(WebDriverBy::name('terms'));
     $this->module->amOnPage('/');
     $this->module->seeElement(WebDriverBy::linkText('Test'));
     $this->module->click(WebDriverBy::linkText('Test'));
     $this->module->seeCurrentUrlEquals('/form/hidden');
 }
Example #28
0
 /**
  * @param $selector
  *
  * @return Crawler
  */
 protected function match($selector)
 {
     if (is_array($selector)) {
         return $this->strictMatch($selector);
     }
     try {
         $selector = CssSelector::toXPath($selector);
     } catch (ParseException $e) {
     }
     if (!Locator::isXPath($selector)) {
         codecept_debug("XPath `{$selector}` is malformed!");
         return new \Symfony\Component\DomCrawler\Crawler();
     }
     return @$this->crawler->filterXPath($selector);
 }
 /**
  * Check that admin user can view all content types
  *
  * @param \AcceptanceTester $I
  */
 public function viewAllContenttypesTest(\AcceptanceTester $I)
 {
     $I->wantTo('make sure the admin user can view all content types');
     // Set up the browser
     $I->setCookie('bolt_authtoken', $this->cookies['bolt_authtoken']);
     $I->setCookie('bolt_session', $this->cookies['bolt_session']);
     $I->amOnPage('/bolt');
     // Pages
     $I->see('Pages', Locator::href('/bolt/overview/pages'));
     $I->see('View Pages', Locator::href('/bolt/overview/pages'));
     $I->see('New Page', Locator::href('/bolt/editcontent/pages'));
     // Entries
     $I->see('Entries', Locator::href('/bolt/overview/entries'));
     $I->see('View Entries', Locator::href('/bolt/overview/entries'));
     $I->see('New Entry', Locator::href('/bolt/editcontent/entries'));
     // Showcases
     $I->see('Showcases', Locator::href('/bolt/overview/showcases'));
     $I->see('View Showcases', Locator::href('/bolt/overview/showcases'));
     $I->see('New Showcase', Locator::href('/bolt/editcontent/showcases'));
     // Resources
     $I->see('Resources', Locator::href('/bolt/overview/resources'));
     $I->see('View Resources', Locator::href('/bolt/overview/resources'));
     $I->see('New Resource', Locator::href('/bolt/editcontent/resources'));
 }
Example #30
0
 protected function parseArgumentAsString($argument)
 {
     if (is_object($argument)) {
         if (method_exists($argument, '__toString')) {
             return (string) $argument;
         }
         if (get_class($argument) == 'Facebook\\WebDriver\\WebDriverBy') {
             return Locator::humanReadableString($argument);
         }
     }
     if ($argument instanceof \Closure) {
         return 'lambda function';
     }
     if (is_callable($argument)) {
         return 'callable function';
     }
     if (!is_object($argument)) {
         return $argument;
     }
     return isset($argument->__mocked) ? $this->formatClassName($argument->__mocked) : $this->formatClassName(get_class($argument));
 }