123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 |
- <?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) {
- return $this->customSelector("named_exact", array("id", $value));
- }
- /**
- * @param string $value
- * @return LocatorBuilderSecondStep
- */
- public function idOrName($value) {
- return $this->customSelector("named_exact", array("id_or_name", $value));
- }
- /**
- * @param string $value
- * @return LocatorBuilderSecondStep
- */
- public function link($value) {
- return $this->customSelector("named_exact", array("link", $value));
- }
- /**
- * @param string $value
- * @return LocatorBuilderSecondStep
- */
- public function button($value) {
- return $this->customSelector("named_exact", array("button", $value));
- }
- /**
- * @param string $value
- * @return LocatorBuilderSecondStep
- */
- public function linkOrButton($value) {
- return $this->customSelector("named_exact", array("link_or_button", $value));
- }
- /**
- * @param string $value
- * @return LocatorBuilderSecondStep
- */
- public function field($value) {
- return $this->customSelector("named_exact", array("field", $value));
- }
- /**
- * @param string $value
- * @return LocatorBuilderSecondStep
- */
- public function selectField($value) {
- return $this->customSelector("named_exact", array("select", $value));
- }
- /**
- * @param string $value
- * @return LocatorBuilderSecondStep
- */
- public function checkbox($value) {
- return $this->customSelector("named_exact", array("checkbox", $value));
- }
- /**
- * @param string $value
- * @return LocatorBuilderSecondStep
- */
- public function radioButton($value) {
- return $this->customSelector("named_exact", array("radio", $value));
- }
- /**
- * @param string $value
- * @return LocatorBuilderSecondStep
- */
- public function fileInput($value) {
- return $this->customSelector("named_exact", array("file", $value));
- }
- /**
- * @param string $value
- * @return LocatorBuilderSecondStep
- */
- public function optionGroup($value) {
- return $this->customSelector("named_exact", array("optgroup", $value));
- }
- /**
- * @param string $value
- * @return LocatorBuilderSecondStep
- */
- public function option($value) {
- return $this->customSelector("named_exact", array("option", $value));
- }
- /**
- * @param string $value
- * @return LocatorBuilderSecondStep
- */
- public function fieldSet($value) {
- return $this->customSelector("named_exact", array("fieldset", $value));
- }
- /**
- * @param string $value
- * @return LocatorBuilderSecondStep
- */
- public function table($value) {
- return $this->customSelector("named_exact", array("table", $value));
- }
- }
- 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);
- }
- }
|