2017-04-04 17:25:22 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data object for the information needed to locate an element in a web page
|
|
|
|
* using Mink.
|
|
|
|
*
|
|
|
|
* Locators can be created directly using the constructor, or through a more
|
|
|
|
* fluent interface with Locator::forThe().
|
|
|
|
*/
|
|
|
|
class Locator {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $description;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $selector;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string|array
|
|
|
|
*/
|
|
|
|
private $locator;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var null|Locator|\Behat\Mink\Element\ElementInterface
|
|
|
|
*/
|
|
|
|
private $ancestor;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Starting point for the fluent interface to create Locators.
|
|
|
|
*
|
|
|
|
* @return LocatorBuilder
|
|
|
|
*/
|
|
|
|
public static function forThe() {
|
|
|
|
return new LocatorBuilder();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $description
|
|
|
|
* @param string $selector
|
|
|
|
* @param string|array $locator
|
|
|
|
* @param null|Locator|\Behat\Mink\Element\ElementInterface $ancestor
|
|
|
|
*/
|
|
|
|
public function __construct($description, $selector, $locator, $ancestor = null) {
|
|
|
|
$this->description = $description;
|
|
|
|
$this->selector = $selector;
|
|
|
|
$this->locator = $locator;
|
|
|
|
$this->ancestor = $ancestor;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getDescription() {
|
|
|
|
return $this->description;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getSelector() {
|
|
|
|
return $this->selector;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string|array
|
|
|
|
*/
|
|
|
|
public function getLocator() {
|
|
|
|
return $this->locator;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return null|Locator|\Behat\Mink\Element\ElementInterface
|
|
|
|
*/
|
|
|
|
public function getAncestor() {
|
|
|
|
return $this->ancestor;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class LocatorBuilder {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $selector
|
|
|
|
* @param string|array $locator
|
|
|
|
* @return LocatorBuilderSecondStep
|
|
|
|
*/
|
|
|
|
public function customSelector($selector, $locator) {
|
|
|
|
return new LocatorBuilderSecondStep($selector, $locator);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $cssExpression
|
|
|
|
* @return LocatorBuilderSecondStep
|
|
|
|
*/
|
|
|
|
public function css($cssExpression) {
|
|
|
|
return $this->customSelector("css", $cssExpression);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $xpathExpression
|
|
|
|
* @return LocatorBuilderSecondStep
|
|
|
|
*/
|
|
|
|
public function xpath($xpathExpression) {
|
|
|
|
return $this->customSelector("xpath", $xpathExpression);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $value
|
|
|
|
* @return LocatorBuilderSecondStep
|
|
|
|
*/
|
|
|
|
public function id($value) {
|
2020-03-26 11:30:18 +03:00
|
|
|
return $this->customSelector("named_exact", ["id", $value]);
|
2017-04-04 17:25:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $value
|
|
|
|
* @return LocatorBuilderSecondStep
|
|
|
|
*/
|
|
|
|
public function idOrName($value) {
|
2020-03-26 11:30:18 +03:00
|
|
|
return $this->customSelector("named_exact", ["id_or_name", $value]);
|
2017-04-04 17:25:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $value
|
|
|
|
* @return LocatorBuilderSecondStep
|
|
|
|
*/
|
|
|
|
public function link($value) {
|
2020-03-26 11:30:18 +03:00
|
|
|
return $this->customSelector("named_exact", ["link", $value]);
|
2017-04-04 17:25:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $value
|
|
|
|
* @return LocatorBuilderSecondStep
|
|
|
|
*/
|
|
|
|
public function button($value) {
|
2020-03-26 11:30:18 +03:00
|
|
|
return $this->customSelector("named_exact", ["button", $value]);
|
2017-04-04 17:25:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $value
|
|
|
|
* @return LocatorBuilderSecondStep
|
|
|
|
*/
|
|
|
|
public function linkOrButton($value) {
|
2020-03-26 11:30:18 +03:00
|
|
|
return $this->customSelector("named_exact", ["link_or_button", $value]);
|
2017-04-04 17:25:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $value
|
|
|
|
* @return LocatorBuilderSecondStep
|
|
|
|
*/
|
|
|
|
public function field($value) {
|
2020-03-26 11:30:18 +03:00
|
|
|
return $this->customSelector("named_exact", ["field", $value]);
|
2017-04-04 17:25:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $value
|
|
|
|
* @return LocatorBuilderSecondStep
|
|
|
|
*/
|
|
|
|
public function selectField($value) {
|
2020-03-26 11:30:18 +03:00
|
|
|
return $this->customSelector("named_exact", ["select", $value]);
|
2017-04-04 17:25:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $value
|
|
|
|
* @return LocatorBuilderSecondStep
|
|
|
|
*/
|
|
|
|
public function checkbox($value) {
|
2020-03-26 11:30:18 +03:00
|
|
|
return $this->customSelector("named_exact", ["checkbox", $value]);
|
2017-04-04 17:25:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $value
|
|
|
|
* @return LocatorBuilderSecondStep
|
|
|
|
*/
|
|
|
|
public function radioButton($value) {
|
2020-03-26 11:30:18 +03:00
|
|
|
return $this->customSelector("named_exact", ["radio", $value]);
|
2017-04-04 17:25:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $value
|
|
|
|
* @return LocatorBuilderSecondStep
|
|
|
|
*/
|
|
|
|
public function fileInput($value) {
|
2020-03-26 11:30:18 +03:00
|
|
|
return $this->customSelector("named_exact", ["file", $value]);
|
2017-04-04 17:25:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $value
|
|
|
|
* @return LocatorBuilderSecondStep
|
|
|
|
*/
|
|
|
|
public function optionGroup($value) {
|
2020-03-26 11:30:18 +03:00
|
|
|
return $this->customSelector("named_exact", ["optgroup", $value]);
|
2017-04-04 17:25:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $value
|
|
|
|
* @return LocatorBuilderSecondStep
|
|
|
|
*/
|
|
|
|
public function option($value) {
|
2020-03-26 11:30:18 +03:00
|
|
|
return $this->customSelector("named_exact", ["option", $value]);
|
2017-04-04 17:25:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $value
|
|
|
|
* @return LocatorBuilderSecondStep
|
|
|
|
*/
|
|
|
|
public function fieldSet($value) {
|
2020-03-26 11:30:18 +03:00
|
|
|
return $this->customSelector("named_exact", ["fieldset", $value]);
|
2017-04-04 17:25:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $value
|
|
|
|
* @return LocatorBuilderSecondStep
|
|
|
|
*/
|
|
|
|
public function table($value) {
|
2020-03-26 11:30:18 +03:00
|
|
|
return $this->customSelector("named_exact", ["table", $value]);
|
2017-04-04 17:25:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class LocatorBuilderSecondStep {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $selector;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string|array
|
|
|
|
*/
|
|
|
|
private $locator;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $selector
|
|
|
|
* @param string|array $locator
|
|
|
|
*/
|
|
|
|
public function __construct($selector, $locator) {
|
|
|
|
$this->selector = $selector;
|
|
|
|
$this->locator = $locator;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Locator|\Behat\Mink\Element\ElementInterface $ancestor
|
|
|
|
* @return LocatorBuilderThirdStep
|
|
|
|
*/
|
|
|
|
public function descendantOf($ancestor) {
|
|
|
|
return new LocatorBuilderThirdStep($this->selector, $this->locator, $ancestor);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $description
|
|
|
|
* @return Locator
|
|
|
|
*/
|
|
|
|
public function describedAs($description) {
|
|
|
|
return new Locator($description, $this->selector, $this->locator);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class LocatorBuilderThirdStep {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $selector;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string|array
|
|
|
|
*/
|
|
|
|
private $locator;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Locator|\Behat\Mink\Element\ElementInterface
|
|
|
|
*/
|
|
|
|
private $ancestor;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $selector
|
|
|
|
* @param string|array $locator
|
|
|
|
* @param Locator|\Behat\Mink\Element\ElementInterface $ancestor
|
|
|
|
*/
|
|
|
|
public function __construct($selector, $locator, $ancestor) {
|
|
|
|
$this->selector = $selector;
|
|
|
|
$this->locator = $locator;
|
|
|
|
$this->ancestor = $ancestor;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $description
|
|
|
|
* @return Locator
|
|
|
|
*/
|
|
|
|
public function describedAs($description) {
|
|
|
|
return new Locator($description, $this->selector, $this->locator, $this->ancestor);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|