本文整理汇总了PHP中Codeception\Util\Locator类的典型用法代码示例。如果您正苦于以下问题:PHP Locator类的具体用法?PHP Locator怎么用?PHP Locator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Locator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testLocatingElementPosition
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));
}
示例2: testIsId
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'));
}
示例3: loginAdminUserTest
/**
* 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.");
}
示例4: loginAdminUserTest
/**
* 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.");
}
示例5: testHumanReadableString
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) {
}
}
示例6: fail
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);
}
示例7: testGetArguments
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));
}
示例8: testGetArguments
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());
}
示例9: fail
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);
}
示例10: createRecordsTest
/**
* 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');
}
示例11: test_default_non_editable_department_named_company
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('management@xavoc.com');
$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();
}
示例12: match
/**
* @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;
}
示例13: fileManagementViewEditTemplatesTest
/**
* 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"));
}
示例14: filterByXPath
/**
* @param $locator
* @return Crawler
*/
protected function filterByXPath($locator)
{
if (!Locator::isXPath($locator)) {
throw new MalformedLocatorException($locator, 'xpath');
}
return $this->getCrawler()->filterXPath($locator);
}
示例15: grabTextFrom
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');
}