diff --git a/.gitignore b/.gitignore index 9af11e2..6084c1d 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,5 @@ phpunit.phar # local phpunit config /phpunit.xml -tests/_output/* \ No newline at end of file +tests/_output/* +tests/_support/_generated \ No newline at end of file diff --git a/README.md b/README.md index 598f963..543d87f 100644 --- a/README.md +++ b/README.md @@ -100,3 +100,83 @@ return [ - Yii won't create the database for you, this has to be done manually before you can access it. - Check and edit the other files in the `config/` directory to customize your application as required. - Refer to the README in the `tests` directory for information specific to basic application tests. + + + +TESTING +------- + +Tests are located in `tests` directory, developed with [Codeception PHP Testing Framework](http://codeception.com/). +By default there are 3 test suites: `unit`, `functional` and `acceptance`. Tests can be executed by running + + ``` + composer exec codecept run + ``` + +This will execute unit and functional tests. Unit tests are testing the system components, while functional tests are for testing user interaction. +Acceptance tests are disabled by default as they require additional setup as they perform testing in real browser. + +To execute acceptance tests do the following: + +1. Rename `tests/acceptance.suite.yml.example` to `tests/acceptance.suite.yml` to enable suite configuration + +2. Replace `codeception/base` package in `composer.json` with `codeception/codeception` to install full featured version of Codeception. + +3. Update dependencies with Composer + + ``` + composer update + ``` + +4. Download [Selenium Server](http://www.seleniumhq.org/download/) and launch it: + + ``` + java -jar java -jar ~/selenium-server-standalone-x.xx.x.jar + ``` + +5. (Optional) Create `yii2_basic_tests` database and update it by applying migrations if you have them. + + ``` + tests/bin/yii migrate + ``` + + The database configuration can be found at `config/test_db.php`. + + +6. Start web server: + + ``` + tests/bin/yii serve + ``` + +7. Now you can run all available tests + + ``` + # run all available tests + composer exec codecept run + + # run acceptance tests + composer exec codecept run acceptance + + # run only unit and functional tests + composer exec codecept run unit,functional + ``` + +Code coverage support +--------------------- + +By default, code coverage is disabled in `codeception.yml` configuration file, you should uncomment needed rows to be able +to collect code coverage. You can run your tests and collect coverage with the following command: + +``` +#collect coverage for all tests +composer exec codecept run --coverage-html --coverage-xml + +#collect coverage only for unit tests +composer exec codecept run unit --coverage-html --coverage-xml + +#collect coverage for unit and functional tests +composer exec codecept run functional,unit --coverage-html --coverage-xml +``` + +You can see code coverage output under the `tests/_output` directory. \ No newline at end of file diff --git a/codeception.yml b/codeception.yml index d5d1aaf..335165e 100644 --- a/codeception.yml +++ b/codeception.yml @@ -1,4 +1,18 @@ actor: Tester +paths: + tests: tests + log: tests/_output + data: tests/_data + helpers: tests/_support +settings: + bootstrap: _bootstrap.php + memory_limit: 1024M + colors: true +modules: + config: + Yii2: + configFile: 'config/test.php' + # To enable code coverage: #coverage: # #c3_url: http://localhost:8080/index-test.php/ @@ -19,13 +33,4 @@ actor: Tester # - ../vendor/* # - ../views/* # - ../web/* -# - ../tests/* -paths: - tests: tests - log: tests/_output - data: tests/_data - helpers: tests/_support -settings: - bootstrap: _bootstrap.php - memory_limit: 1024M - colors: true \ No newline at end of file +# - ../tests/* \ No newline at end of file diff --git a/composer.json b/composer.json index 137ee77..b97bcd9 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,7 @@ "yiisoft/yii2-swiftmailer": "*" }, "require-dev": { - "yiisoft/yii2-codeception": "*", - "codeception/specify": "*", + "codeception/base": "^2.2.3", "codeception/verify": "*", "yiisoft/yii2-debug": "*", "yiisoft/yii2-gii": "*", diff --git a/config/console.php b/config/console.php index 7306e27..3945d9e 100644 --- a/config/console.php +++ b/config/console.php @@ -1,7 +1,5 @@ [ 'showScriptName' => true, ], + 'user' => [ + 'identityClass' => 'app\models\User', + ], 'request' => [ - // it's not recommended to run functional tests with CSRF validation enabled + 'cookieValidationKey' => 'test', 'enableCsrfValidation' => false, // but if you absolutely need it set cookie domain to localhost /* diff --git a/config/test_db.php b/config/test_db.php new file mode 100644 index 0000000..c951052 --- /dev/null +++ b/config/test_db.php @@ -0,0 +1,6 @@ + - ``` - - Then add `/vendor/bin` to you `PATH` environment variable. Now we're able to use `codecept` from command - line globally. - -2. Install faker extension by running the following from template root directory where `composer.json` is: - - ``` - composer require --dev "yiisoft/yii2-faker:*" - ``` - -3. Create `yii2_basic_tests` database and update it by applying migrations (you may skip this step if you do not have created any migrations yet): - - ``` - cd tests - codeception/bin/yii migrate - ``` - - The command needs to be run in the `tests` directory. - The database configuration can be found at `tests/codeception/config/config.php`. - -4. Build the test suites: - - ``` - codecept build - ``` - -5. In order to be able to run acceptance tests you need to start a webserver. The simplest way is to use built-in Yii -command: - - ``` - ./yii serve - ``` - -6. Now you can run the tests with the following commands: - - ``` - # run all available tests - codecept run - # run acceptance tests - codecept run acceptance - # run functional tests - codecept run functional - # run unit tests - codecept run unit - ``` - -Fixtures Default Configuration ------------------------------- -The `fixture` commands refer to the following `ActiveFixture` configuration by default: - -- Fixtures path: `@tests/unit/fixtures` -- Fixtures data path: `@tests/unit/fixtures/data` -- Template files path: `@tests/unit/templates/fixtures` -- Namespace: `tests\unit\fixtures` - -Where `@tests` refers to `@app/tests/codeception`. - -Code coverage support ---------------------- - -By default, code coverage is disabled in `codeception.yml` configuration file, you should uncomment needed rows to be able -to collect code coverage. You can run your tests and collect coverage with the following command: - -``` -#collect coverage for all tests -codecept run --coverage-html --coverage-xml - -#collect coverage only for unit tests -codecept run unit --coverage-html --coverage-xml - -#collect coverage for unit and functional tests -codecept run functional,unit --coverage-html --coverage-xml -``` - -You can see code coverage output under the `tests/_output` directory. - -###Remote code coverage - -When you run your tests not in the same process where code coverage is collected, then you should uncomment `remote` option and its -related options, to be able to collect code coverage correctly. To setup remote code coverage you should follow [instructions](http://codeception.com/docs/11-Codecoverage) -from codeception site. - -1. install `Codeception c3` remote support `composer require "codeception/c3:*"`; - -2. copy `c3.php` file under your `web` directory; - -3. include `c3.php` file in your `index-test.php` file before application run, so it can catch needed requests. - -4. edit `c3.php` to update config file path (~ line 55) with `$config_file = realpath(__DIR__ . '/../tests/codeception.yml');` - -Configuration options that are used by remote code coverage: - -- c3_url: url pointing to entry script that includes `c3.php` file, so `Codeception` will be able to produce code coverage; -- remote: whether to enable remote code coverage or not; -- remote_config: path to the `codeception.yml` configuration file, from the directory where `c3.php` file is located. This is needed - so that `Codeception` can create itself instance and collect code coverage correctly. - -By default `c3_url` and `remote_config` setup correctly, you only need to copy and include `c3.php` file in your `index-test.php` - -After that you should be able to collect code coverage from tests that run through `PhpBrowser` or `WebDriver` with same command -as for other tests: - -``` -#collect coverage from remote -codecept run acceptance --coverage-html --coverage-xml -``` - -Please refer to [Codeception tutorial](http://codeception.com/docs/01-Introduction) for -more details about writing and running acceptance, functional and unit tests. diff --git a/tests/_bootstrap.php b/tests/_bootstrap.php index c7f5cfc..6a86590 100644 --- a/tests/_bootstrap.php +++ b/tests/_bootstrap.php @@ -1,10 +1,8 @@ $value) { - $inputType = $field === 'body' ? 'textarea' : 'input'; - $this->actor->fillField($inputType . '[name="ContactForm[' . $field . ']"]', $value); - } - $this->actor->click('contact-button'); - } -} diff --git a/tests/_pages/LoginPage.php b/tests/_pages/LoginPage.php deleted file mode 100644 index c3a2ef2..0000000 --- a/tests/_pages/LoginPage.php +++ /dev/null @@ -1,25 +0,0 @@ -actor->fillField('input[name="LoginForm[username]"]', $username); - $this->actor->fillField('input[name="LoginForm[password]"]', $password); - $this->actor->click('login-button'); - } -} diff --git a/tests/_support/FunctionalTester.php b/tests/_support/FunctionalTester.php index 7e888f8..db2ce28 100644 --- a/tests/_support/FunctionalTester.php +++ b/tests/_support/FunctionalTester.php @@ -20,7 +20,4 @@ class FunctionalTester extends \Codeception\Actor { use _generated\FunctionalTesterActions; - /** - * Define custom actions here - */ } diff --git a/tests/_support/_generated/AcceptanceTesterActions.php b/tests/_support/_generated/AcceptanceTesterActions.php index 0965f33..62eb177 100644 --- a/tests/_support/_generated/AcceptanceTesterActions.php +++ b/tests/_support/_generated/AcceptanceTesterActions.php @@ -1,11 +1,12 @@ -getScenario()->runStep(new \Codeception\Step\Action('setHeader', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Authenticates user for HTTP_AUTH - * - * @param $username - * @param $password - * @see \Codeception\Module\PhpBrowser::amHttpAuthenticated() - */ - public function amHttpAuthenticated($username, $password) { - return $this->getScenario()->runStep(new \Codeception\Step\Condition('amHttpAuthenticated', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Open web page at the given absolute URL and sets its hostname as the base host. - * - * ``` php - * amOnUrl('http://codeception.com'); - * $I->amOnPage('/quickstart'); // moves to http://codeception.com/quickstart - * ?> - * ``` - * @see \Codeception\Module\PhpBrowser::amOnUrl() - */ - public function amOnUrl($url) { - return $this->getScenario()->runStep(new \Codeception\Step\Condition('amOnUrl', func_get_args())); + public function debugWebDriverLogs() { + return $this->getScenario()->runStep(new \Codeception\Step\Action('debugWebDriverLogs', func_get_args())); } @@ -82,7 +48,7 @@ trait AcceptanceTesterActions * @param $subdomain * * @return mixed - * @see \Codeception\Module\PhpBrowser::amOnSubdomain() + * @see \Codeception\Module\WebDriver::amOnSubdomain() */ public function amOnSubdomain($subdomain) { return $this->getScenario()->runStep(new \Codeception\Step\Condition('amOnSubdomain', func_get_args())); @@ -92,76 +58,193 @@ trait AcceptanceTesterActions /** * [!] Method is generated. Documentation taken from corresponding module. * - * Low-level API method. - * If Codeception commands are not enough, use [Guzzle HTTP Client](http://guzzlephp.org/) methods directly - * - * Example: + * Takes a screenshot of the current window and saves it to `tests/_output/debug`. * * ``` php * executeInGuzzle(function (\GuzzleHttp\Client $client) { - * $client->get('/get', ['query' => ['foo' => 'bar']]); - * }); + * $I->amOnPage('/user/edit'); + * $I->makeScreenshot('edit_page'); + * // saved to: tests/_output/debug/edit_page.png * ?> * ``` * - * It is not recommended to use this command on a regular basis. - * If Codeception lacks important Guzzle Client methods, implement them and submit patches. - * - * @param callable $function - * @see \Codeception\Module\PhpBrowser::executeInGuzzle() + * @param $name + * @see \Codeception\Module\WebDriver::makeScreenshot() */ - public function executeInGuzzle($function) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('executeInGuzzle', func_get_args())); + public function makeScreenshot($name) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('makeScreenshot', func_get_args())); } /** * [!] Method is generated. Documentation taken from corresponding module. * - * Sets the HTTP header to the passed value - which is used on - * subsequent HTTP requests through PhpBrowser. + * Resize the current window. * - * Example: - * ```php + * ``` php * setHeader('X-Requested-With', 'Codeception'); - * $I->amOnPage('test-headers.php'); - * ?> + * $I->resizeWindow(800, 600); + * * ``` * - * @param string $name the name of the request header - * @param string $value the value to set it to for subsequent - * requests - * @see \Codeception\Lib\InnerBrowser::haveHttpHeader() + * @param int $width + * @param int $height + * @see \Codeception\Module\WebDriver::resizeWindow() */ - public function haveHttpHeader($name, $value) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('haveHttpHeader', func_get_args())); + public function resizeWindow($width, $height) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('resizeWindow', func_get_args())); } /** * [!] Method is generated. Documentation taken from corresponding module. * - * Deletes the header with the passed name. Subsequent requests - * will not have the deleted header in its request. + * Checks that a cookie with the given name is set. + * You can set additional cookie params like `domain`, `path` as array passed in last argument. * - * Example: - * ```php + * ``` php * haveHttpHeader('X-Requested-With', 'Codeception'); - * $I->amOnPage('test-headers.php'); - * // ... - * $I->deleteHeader('X-Requested-With'); - * $I->amOnPage('some-other-page.php'); + * $I->seeCookie('PHPSESSID'); * ?> * ``` * - * @param string $name the name of the header to delete. - * @see \Codeception\Lib\InnerBrowser::deleteHeader() + * @param $cookie + * @param array $params + * @return mixed + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Module\WebDriver::seeCookie() */ - public function deleteHeader($name) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('deleteHeader', func_get_args())); + public function canSeeCookie($cookie, $params = null) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeCookie', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that a cookie with the given name is set. + * You can set additional cookie params like `domain`, `path` as array passed in last argument. + * + * ``` php + * seeCookie('PHPSESSID'); + * ?> + * ``` + * + * @param $cookie + * @param array $params + * @return mixed + * @see \Codeception\Module\WebDriver::seeCookie() + */ + public function seeCookie($cookie, $params = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeCookie', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that there isn't a cookie with the given name. + * You can set additional cookie params like `domain`, `path` as array passed in last argument. + * + * @param $cookie + * + * @param array $params + * @return mixed + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Module\WebDriver::dontSeeCookie() + */ + public function cantSeeCookie($cookie, $params = null) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeCookie', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that there isn't a cookie with the given name. + * You can set additional cookie params like `domain`, `path` as array passed in last argument. + * + * @param $cookie + * + * @param array $params + * @return mixed + * @see \Codeception\Module\WebDriver::dontSeeCookie() + */ + public function dontSeeCookie($cookie, $params = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeCookie', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Sets a cookie with the given name and value. + * You can set additional cookie params like `domain`, `path`, `expires`, `secure` in array passed as last argument. + * + * ``` php + * setCookie('PHPSESSID', 'el4ukv0kqbvoirg7nkp4dncpk3'); + * ?> + * ``` + * + * @param $name + * @param $val + * @param array $params + * + * @return mixed + * @see \Codeception\Module\WebDriver::setCookie() + */ + public function setCookie($cookie, $value, $params = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('setCookie', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Unsets cookie with the given name. + * You can set additional cookie params like `domain`, `path` in array passed as last argument. + * + * @param $cookie + * + * @param array $params + * @return mixed + * @see \Codeception\Module\WebDriver::resetCookie() + */ + public function resetCookie($cookie, $params = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('resetCookie', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Grabs a cookie value. + * You can set additional cookie params like `domain`, `path` in array passed as last argument. + * + * @param $cookie + * + * @param array $params + * @return mixed + * @see \Codeception\Module\WebDriver::grabCookie() + */ + public function grabCookie($cookie, $params = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabCookie', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Open web page at the given absolute URL and sets its hostname as the base host. + * + * ``` php + * amOnUrl('http://codeception.com'); + * $I->amOnPage('/quickstart'); // moves to http://codeception.com/quickstart + * ?> + * ``` + * @see \Codeception\Module\WebDriver::amOnUrl() + */ + public function amOnUrl($url) { + return $this->getScenario()->runStep(new \Codeception\Step\Condition('amOnUrl', func_get_args())); } @@ -179,52 +262,13 @@ trait AcceptanceTesterActions * ``` * * @param $page - * @see \Codeception\Lib\InnerBrowser::amOnPage() + * @see \Codeception\Module\WebDriver::amOnPage() */ public function amOnPage($page) { return $this->getScenario()->runStep(new \Codeception\Step\Condition('amOnPage', func_get_args())); } - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Perform a click on a link or a button, given by a locator. - * If a fuzzy locator is given, the page will be searched for a button, link, or image matching the locator string. - * For buttons, the "value" attribute, "name" attribute, and inner text are searched. - * For links, the link text is searched. - * For images, the "alt" attribute and inner text of any parent links are searched. - * - * The second parameter is a context (CSS or XPath locator) to narrow the search. - * - * Note that if the locator matches a button of type `submit`, the form will be submitted. - * - * ``` php - * click('Logout'); - * // button of form - * $I->click('Submit'); - * // CSS button - * $I->click('#form input[type=submit]'); - * // XPath - * $I->click('//form/*[@type=submit]'); - * // link in context - * $I->click('Logout', '#nav'); - * // using strict locator - * $I->click(['link' => 'Login']); - * ?> - * ``` - * - * @param $link - * @param $context - * @see \Codeception\Lib\InnerBrowser::click() - */ - public function click($link, $context = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('click', func_get_args())); - } - - /** * [!] Method is generated. Documentation taken from corresponding module. * @@ -257,7 +301,7 @@ trait AcceptanceTesterActions * @param $text * @param null $selector * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::see() + * @see \Codeception\Module\WebDriver::see() */ public function canSee($text, $selector = null) { return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('see', func_get_args())); @@ -293,7 +337,7 @@ trait AcceptanceTesterActions * * @param $text * @param null $selector - * @see \Codeception\Lib\InnerBrowser::see() + * @see \Codeception\Module\WebDriver::see() */ public function see($text, $selector = null) { return $this->getScenario()->runStep(new \Codeception\Step\Assertion('see', func_get_args())); @@ -330,7 +374,7 @@ trait AcceptanceTesterActions * @param $text * @param null $selector * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::dontSee() + * @see \Codeception\Module\WebDriver::dontSee() */ public function cantSee($text, $selector = null) { return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSee', func_get_args())); @@ -364,7 +408,7 @@ trait AcceptanceTesterActions * * @param $text * @param null $selector - * @see \Codeception\Lib\InnerBrowser::dontSee() + * @see \Codeception\Module\WebDriver::dontSee() */ public function dontSee($text, $selector = null) { return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSee', func_get_args())); @@ -384,7 +428,7 @@ trait AcceptanceTesterActions * * @param $raw * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::seeInSource() + * @see \Codeception\Module\WebDriver::seeInSource() */ public function canSeeInSource($raw) { return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInSource', func_get_args())); @@ -401,7 +445,7 @@ trait AcceptanceTesterActions * ``` * * @param $raw - * @see \Codeception\Lib\InnerBrowser::seeInSource() + * @see \Codeception\Module\WebDriver::seeInSource() */ public function seeInSource($raw) { return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInSource', func_get_args())); @@ -421,7 +465,7 @@ trait AcceptanceTesterActions * * @param $raw * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::dontSeeInSource() + * @see \Codeception\Module\WebDriver::dontSeeInSource() */ public function cantSeeInSource($raw) { return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInSource', func_get_args())); @@ -438,13 +482,112 @@ trait AcceptanceTesterActions * ``` * * @param $raw - * @see \Codeception\Lib\InnerBrowser::dontSeeInSource() + * @see \Codeception\Module\WebDriver::dontSeeInSource() */ public function dontSeeInSource($raw) { return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeInSource', func_get_args())); } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the page source contains the given string. + * + * ```php + * seeInPageSource('getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInPageSource', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the page source contains the given string. + * + * ```php + * seeInPageSource('getScenario()->runStep(new \Codeception\Step\Assertion('seeInPageSource', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the page source doesn't contain the given string. + * + * @param $text + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Module\WebDriver::dontSeeInPageSource() + */ + public function cantSeeInPageSource($text) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInPageSource', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the page source doesn't contain the given string. + * + * @param $text + * @see \Codeception\Module\WebDriver::dontSeeInPageSource() + */ + public function dontSeeInPageSource($text) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeInPageSource', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Perform a click on a link or a button, given by a locator. + * If a fuzzy locator is given, the page will be searched for a button, link, or image matching the locator string. + * For buttons, the "value" attribute, "name" attribute, and inner text are searched. + * For links, the link text is searched. + * For images, the "alt" attribute and inner text of any parent links are searched. + * + * The second parameter is a context (CSS or XPath locator) to narrow the search. + * + * Note that if the locator matches a button of type `submit`, the form will be submitted. + * + * ``` php + * click('Logout'); + * // button of form + * $I->click('Submit'); + * // CSS button + * $I->click('#form input[type=submit]'); + * // XPath + * $I->click('//form/*[@type=submit]'); + * // link in context + * $I->click('Logout', '#nav'); + * // using strict locator + * $I->click(['link' => 'Login']); + * ?> + * ``` + * + * @param $link + * @param $context + * @see \Codeception\Module\WebDriver::click() + */ + public function click($link, $context = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('click', func_get_args())); + } + + /** * [!] Method is generated. Documentation taken from corresponding module. * @@ -461,7 +604,7 @@ trait AcceptanceTesterActions * @param $text * @param null $url * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::seeLink() + * @see \Codeception\Module\WebDriver::seeLink() */ public function canSeeLink($text, $url = null) { return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeLink', func_get_args())); @@ -481,7 +624,7 @@ trait AcceptanceTesterActions * * @param $text * @param null $url - * @see \Codeception\Lib\InnerBrowser::seeLink() + * @see \Codeception\Module\WebDriver::seeLink() */ public function seeLink($text, $url = null) { return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeLink', func_get_args())); @@ -504,7 +647,7 @@ trait AcceptanceTesterActions * @param $text * @param null $url * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::dontSeeLink() + * @see \Codeception\Module\WebDriver::dontSeeLink() */ public function cantSeeLink($text, $url = null) { return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeLink', func_get_args())); @@ -524,7 +667,7 @@ trait AcceptanceTesterActions * * @param $text * @param null $url - * @see \Codeception\Lib\InnerBrowser::dontSeeLink() + * @see \Codeception\Module\WebDriver::dontSeeLink() */ public function dontSeeLink($text, $url = null) { return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeLink', func_get_args())); @@ -547,7 +690,7 @@ trait AcceptanceTesterActions * * @param $uri * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::seeInCurrentUrl() + * @see \Codeception\Module\WebDriver::seeInCurrentUrl() */ public function canSeeInCurrentUrl($uri) { return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInCurrentUrl', func_get_args())); @@ -567,50 +710,13 @@ trait AcceptanceTesterActions * ``` * * @param $uri - * @see \Codeception\Lib\InnerBrowser::seeInCurrentUrl() + * @see \Codeception\Module\WebDriver::seeInCurrentUrl() */ public function seeInCurrentUrl($uri) { return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInCurrentUrl', func_get_args())); } - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the current URI doesn't contain the given string. - * - * ``` php - * dontSeeInCurrentUrl('/users/'); - * ?> - * ``` - * - * @param $uri - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::dontSeeInCurrentUrl() - */ - public function cantSeeInCurrentUrl($uri) { - return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInCurrentUrl', func_get_args())); - } - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the current URI doesn't contain the given string. - * - * ``` php - * dontSeeInCurrentUrl('/users/'); - * ?> - * ``` - * - * @param $uri - * @see \Codeception\Lib\InnerBrowser::dontSeeInCurrentUrl() - */ - public function dontSeeInCurrentUrl($uri) { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeInCurrentUrl', func_get_args())); - } - - /** * [!] Method is generated. Documentation taken from corresponding module. * @@ -626,7 +732,7 @@ trait AcceptanceTesterActions * * @param $uri * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::seeCurrentUrlEquals() + * @see \Codeception\Module\WebDriver::seeCurrentUrlEquals() */ public function canSeeCurrentUrlEquals($uri) { return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeCurrentUrlEquals', func_get_args())); @@ -645,13 +751,89 @@ trait AcceptanceTesterActions * ``` * * @param $uri - * @see \Codeception\Lib\InnerBrowser::seeCurrentUrlEquals() + * @see \Codeception\Module\WebDriver::seeCurrentUrlEquals() */ public function seeCurrentUrlEquals($uri) { return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeCurrentUrlEquals', func_get_args())); } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the current URL matches the given regular expression. + * + * ``` php + * seeCurrentUrlMatches('~$/users/(\d+)~'); + * ?> + * ``` + * + * @param $uri + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Module\WebDriver::seeCurrentUrlMatches() + */ + public function canSeeCurrentUrlMatches($uri) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeCurrentUrlMatches', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the current URL matches the given regular expression. + * + * ``` php + * seeCurrentUrlMatches('~$/users/(\d+)~'); + * ?> + * ``` + * + * @param $uri + * @see \Codeception\Module\WebDriver::seeCurrentUrlMatches() + */ + public function seeCurrentUrlMatches($uri) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeCurrentUrlMatches', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the current URI doesn't contain the given string. + * + * ``` php + * dontSeeInCurrentUrl('/users/'); + * ?> + * ``` + * + * @param $uri + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Module\WebDriver::dontSeeInCurrentUrl() + */ + public function cantSeeInCurrentUrl($uri) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInCurrentUrl', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the current URI doesn't contain the given string. + * + * ``` php + * dontSeeInCurrentUrl('/users/'); + * ?> + * ``` + * + * @param $uri + * @see \Codeception\Module\WebDriver::dontSeeInCurrentUrl() + */ + public function dontSeeInCurrentUrl($uri) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeInCurrentUrl', func_get_args())); + } + + /** * [!] Method is generated. Documentation taken from corresponding module. * @@ -667,7 +849,7 @@ trait AcceptanceTesterActions * * @param $uri * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::dontSeeCurrentUrlEquals() + * @see \Codeception\Module\WebDriver::dontSeeCurrentUrlEquals() */ public function cantSeeCurrentUrlEquals($uri) { return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeCurrentUrlEquals', func_get_args())); @@ -686,52 +868,13 @@ trait AcceptanceTesterActions * ``` * * @param $uri - * @see \Codeception\Lib\InnerBrowser::dontSeeCurrentUrlEquals() + * @see \Codeception\Module\WebDriver::dontSeeCurrentUrlEquals() */ public function dontSeeCurrentUrlEquals($uri) { return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeCurrentUrlEquals', func_get_args())); } - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the current URL matches the given regular expression. - * - * ``` php - * seeCurrentUrlMatches('~$/users/(\d+)~'); - * ?> - * ``` - * - * @param $uri - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::seeCurrentUrlMatches() - */ - public function canSeeCurrentUrlMatches($uri) { - return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeCurrentUrlMatches', func_get_args())); - } - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the current URL matches the given regular expression. - * - * ``` php - * seeCurrentUrlMatches('~$/users/(\d+)~'); - * ?> - * ``` - * - * @param $uri - * @see \Codeception\Lib\InnerBrowser::seeCurrentUrlMatches() - */ - public function seeCurrentUrlMatches($uri) { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeCurrentUrlMatches', func_get_args())); - } - - /** * [!] Method is generated. Documentation taken from corresponding module. * @@ -746,7 +889,7 @@ trait AcceptanceTesterActions * * @param $uri * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::dontSeeCurrentUrlMatches() + * @see \Codeception\Module\WebDriver::dontSeeCurrentUrlMatches() */ public function cantSeeCurrentUrlMatches($uri) { return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeCurrentUrlMatches', func_get_args())); @@ -764,7 +907,7 @@ trait AcceptanceTesterActions * ``` * * @param $uri - * @see \Codeception\Lib\InnerBrowser::dontSeeCurrentUrlMatches() + * @see \Codeception\Module\WebDriver::dontSeeCurrentUrlMatches() */ public function dontSeeCurrentUrlMatches($uri) { return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeCurrentUrlMatches', func_get_args())); @@ -787,7 +930,7 @@ trait AcceptanceTesterActions * @param null $uri * * @return mixed - * @see \Codeception\Lib\InnerBrowser::grabFromCurrentUrl() + * @see \Codeception\Module\WebDriver::grabFromCurrentUrl() */ public function grabFromCurrentUrl($uri = null) { return $this->getScenario()->runStep(new \Codeception\Step\Action('grabFromCurrentUrl', func_get_args())); @@ -809,7 +952,7 @@ trait AcceptanceTesterActions * * @param $checkbox * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::seeCheckboxIsChecked() + * @see \Codeception\Module\WebDriver::seeCheckboxIsChecked() */ public function canSeeCheckboxIsChecked($checkbox) { return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeCheckboxIsChecked', func_get_args())); @@ -828,7 +971,7 @@ trait AcceptanceTesterActions * ``` * * @param $checkbox - * @see \Codeception\Lib\InnerBrowser::seeCheckboxIsChecked() + * @see \Codeception\Module\WebDriver::seeCheckboxIsChecked() */ public function seeCheckboxIsChecked($checkbox) { return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeCheckboxIsChecked', func_get_args())); @@ -849,7 +992,7 @@ trait AcceptanceTesterActions * * @param $checkbox * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::dontSeeCheckboxIsChecked() + * @see \Codeception\Module\WebDriver::dontSeeCheckboxIsChecked() */ public function cantSeeCheckboxIsChecked($checkbox) { return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeCheckboxIsChecked', func_get_args())); @@ -867,7 +1010,7 @@ trait AcceptanceTesterActions * ``` * * @param $checkbox - * @see \Codeception\Lib\InnerBrowser::dontSeeCheckboxIsChecked() + * @see \Codeception\Module\WebDriver::dontSeeCheckboxIsChecked() */ public function dontSeeCheckboxIsChecked($checkbox) { return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeCheckboxIsChecked', func_get_args())); @@ -894,7 +1037,7 @@ trait AcceptanceTesterActions * @param $field * @param $value * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::seeInField() + * @see \Codeception\Module\WebDriver::seeInField() */ public function canSeeInField($field, $value) { return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInField', func_get_args())); @@ -918,7 +1061,7 @@ trait AcceptanceTesterActions * * @param $field * @param $value - * @see \Codeception\Lib\InnerBrowser::seeInField() + * @see \Codeception\Module\WebDriver::seeInField() */ public function seeInField($field, $value) { return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInField', func_get_args())); @@ -945,7 +1088,7 @@ trait AcceptanceTesterActions * @param $field * @param $value * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::dontSeeInField() + * @see \Codeception\Module\WebDriver::dontSeeInField() */ public function cantSeeInField($field, $value) { return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInField', func_get_args())); @@ -969,7 +1112,7 @@ trait AcceptanceTesterActions * * @param $field * @param $value - * @see \Codeception\Lib\InnerBrowser::dontSeeInField() + * @see \Codeception\Module\WebDriver::dontSeeInField() */ public function dontSeeInField($field, $value) { return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeInField', func_get_args())); @@ -1039,7 +1182,7 @@ trait AcceptanceTesterActions * @param $formSelector * @param $params * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::seeInFormFields() + * @see \Codeception\Module\WebDriver::seeInFormFields() */ public function canSeeInFormFields($formSelector, $params) { return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInFormFields', func_get_args())); @@ -1106,7 +1249,7 @@ trait AcceptanceTesterActions * * @param $formSelector * @param $params - * @see \Codeception\Lib\InnerBrowser::seeInFormFields() + * @see \Codeception\Module\WebDriver::seeInFormFields() */ public function seeInFormFields($formSelector, $params) { return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInFormFields', func_get_args())); @@ -1156,7 +1299,7 @@ trait AcceptanceTesterActions * @param $formSelector * @param $params * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::dontSeeInFormFields() + * @see \Codeception\Module\WebDriver::dontSeeInFormFields() */ public function cantSeeInFormFields($formSelector, $params) { return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInFormFields', func_get_args())); @@ -1203,39 +1346,757 @@ trait AcceptanceTesterActions * * @param $formSelector * @param $params - * @see \Codeception\Lib\InnerBrowser::dontSeeInFormFields() + * @see \Codeception\Module\WebDriver::dontSeeInFormFields() */ public function dontSeeInFormFields($formSelector, $params) { return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeInFormFields', func_get_args())); } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Selects an option in a select tag or in radio button group. + * + * ``` php + * selectOption('form select[name=account]', 'Premium'); + * $I->selectOption('form input[name=payment]', 'Monthly'); + * $I->selectOption('//form/select[@name=account]', 'Monthly'); + * ?> + * ``` + * + * Provide an array for the second argument to select multiple options: + * + * ``` php + * selectOption('Which OS do you use?', array('Windows','Linux')); + * ?> + * ``` + * + * Or provide an associative array for the second argument to specifically define which selection method should be used: + * + * ``` php + * selectOption('Which OS do you use?', array('text' => 'Windows')); // Only search by text 'Windows' + * $I->selectOption('Which OS do you use?', array('value' => 'windows')); // Only search by value 'windows' + * ?> + + ``` + * + * @param $select + * @param $option + * @see \Codeception\Module\WebDriver::selectOption() + */ + public function selectOption($select, $option) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('selectOption', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\WebDriver::unselectOption() + */ + public function unselectOption($select, $option) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('unselectOption', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Ticks a checkbox. For radio buttons, use the `selectOption` method instead. + * + * ``` php + * checkOption('#agree'); + * ?> + * ``` + * + * @param $option + * @see \Codeception\Module\WebDriver::checkOption() + */ + public function checkOption($option) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('checkOption', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Unticks a checkbox. + * + * ``` php + * uncheckOption('#notify'); + * ?> + * ``` + * + * @param $option + * @see \Codeception\Module\WebDriver::uncheckOption() + */ + public function uncheckOption($option) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('uncheckOption', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Fills a text field or textarea with the given string. + * + * ``` php + * fillField("//input[@type='text']", "Hello World!"); + * $I->fillField(['name' => 'email'], 'jon@mail.com'); + * ?> + * ``` + * + * @param $field + * @param $value + * @see \Codeception\Module\WebDriver::fillField() + */ + public function fillField($field, $value) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('fillField', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Attaches a file relative to the Codeception data directory to the given file upload field. + * + * ``` php + * attachFile('input[@type="file"]', 'prices.xls'); + * ?> + * ``` + * + * @param $field + * @param $filename + * @see \Codeception\Module\WebDriver::attachFile() + */ + public function attachFile($field, $filename) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('attachFile', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Grabs all visible text from the current page. + * + * @return string + * @see \Codeception\Module\WebDriver::getVisibleText() + */ + public function getVisibleText() { + return $this->getScenario()->runStep(new \Codeception\Step\Action('getVisibleText', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Finds and returns the text contents of the given element. + * If a fuzzy locator is used, the element is found using CSS, XPath, + * and by matching the full page source by regular expression. + * + * ``` php + * grabTextFrom('h1'); + * $heading = $I->grabTextFrom('descendant-or-self::h1'); + * $value = $I->grabTextFrom('~ + * ``` + * + * @param $cssOrXPathOrRegex + * + * @return mixed + * @see \Codeception\Module\WebDriver::grabTextFrom() + */ + public function grabTextFrom($cssOrXPathOrRegex) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabTextFrom', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Grabs the value of the given attribute value from the given element. + * Fails if element is not found. + * + * ``` php + * grabAttributeFrom('#tooltip', 'title'); + * ?> + * ``` + * + * + * @param $cssOrXpath + * @param $attribute + * + * @return mixed + * @see \Codeception\Module\WebDriver::grabAttributeFrom() + */ + public function grabAttributeFrom($cssOrXpath, $attribute) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabAttributeFrom', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Finds the value for the given form field. + * If a fuzzy locator is used, the field is found by field name, CSS, and XPath. + * + * ``` php + * grabValueFrom('Name'); + * $name = $I->grabValueFrom('input[name=username]'); + * $name = $I->grabValueFrom('descendant-or-self::form/descendant::input[@name = 'username']'); + * $name = $I->grabValueFrom(['name' => 'username']); + * ?> + * ``` + * + * @param $field + * + * @return mixed + * @see \Codeception\Module\WebDriver::grabValueFrom() + */ + public function grabValueFrom($field) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabValueFrom', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Grabs either the text content, or attribute values, of nodes + * matched by $cssOrXpath and returns them as an array. + * + * ```html + * First + * Second + * Third + * ``` + * + * ```php + * grabMultiple('a'); + * + * // would return ['#first', '#second', '#third'] + * $aLinks = $I->grabMultiple('a', 'href'); + * ?> + * ``` + * + * @param $cssOrXpath + * @param $attribute + * @return string[] + * @see \Codeception\Module\WebDriver::grabMultiple() + */ + public function grabMultiple($cssOrXpath, $attribute = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabMultiple', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the given element exists on the page and is visible. + * You can also specify expected attributes of this element. + * + * ``` php + * seeElement('.error'); + * $I->seeElement('//form/input[1]'); + * $I->seeElement('input', ['name' => 'login']); + * $I->seeElement('input', ['value' => '123456']); + * + * // strict locator in first arg, attributes in second + * $I->seeElement(['css' => 'form input'], ['name' => 'login']); + * ?> + * ``` + * + * @param $selector + * @param array $attributes + * @return + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Module\WebDriver::seeElement() + */ + public function canSeeElement($selector, $attributes = null) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeElement', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the given element exists on the page and is visible. + * You can also specify expected attributes of this element. + * + * ``` php + * seeElement('.error'); + * $I->seeElement('//form/input[1]'); + * $I->seeElement('input', ['name' => 'login']); + * $I->seeElement('input', ['value' => '123456']); + * + * // strict locator in first arg, attributes in second + * $I->seeElement(['css' => 'form input'], ['name' => 'login']); + * ?> + * ``` + * + * @param $selector + * @param array $attributes + * @return + * @see \Codeception\Module\WebDriver::seeElement() + */ + public function seeElement($selector, $attributes = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeElement', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the given element is invisible or not present on the page. + * You can also specify expected attributes of this element. + * + * ``` php + * dontSeeElement('.error'); + * $I->dontSeeElement('//form/input[1]'); + * $I->dontSeeElement('input', ['name' => 'login']); + * $I->dontSeeElement('input', ['value' => '123456']); + * ?> + * ``` + * + * @param $selector + * @param array $attributes + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Module\WebDriver::dontSeeElement() + */ + public function cantSeeElement($selector, $attributes = null) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeElement', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the given element is invisible or not present on the page. + * You can also specify expected attributes of this element. + * + * ``` php + * dontSeeElement('.error'); + * $I->dontSeeElement('//form/input[1]'); + * $I->dontSeeElement('input', ['name' => 'login']); + * $I->dontSeeElement('input', ['value' => '123456']); + * ?> + * ``` + * + * @param $selector + * @param array $attributes + * @see \Codeception\Module\WebDriver::dontSeeElement() + */ + public function dontSeeElement($selector, $attributes = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeElement', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the given element exists on the page, even it is invisible. + * + * ``` php + * seeElementInDOM('//form/input[type=hidden]'); + * ?> + * ``` + * + * @param $selector + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Module\WebDriver::seeElementInDOM() + */ + public function canSeeElementInDOM($selector, $attributes = null) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeElementInDOM', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the given element exists on the page, even it is invisible. + * + * ``` php + * seeElementInDOM('//form/input[type=hidden]'); + * ?> + * ``` + * + * @param $selector + * @see \Codeception\Module\WebDriver::seeElementInDOM() + */ + public function seeElementInDOM($selector, $attributes = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeElementInDOM', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Opposite of `seeElementInDOM`. + * + * @param $selector + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Module\WebDriver::dontSeeElementInDOM() + */ + public function cantSeeElementInDOM($selector, $attributes = null) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeElementInDOM', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Opposite of `seeElementInDOM`. + * + * @param $selector + * @see \Codeception\Module\WebDriver::dontSeeElementInDOM() + */ + public function dontSeeElementInDOM($selector, $attributes = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeElementInDOM', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that there are a certain number of elements matched by the given locator on the page. + * + * ``` php + * seeNumberOfElements('tr', 10); + * $I->seeNumberOfElements('tr', [0,10]); //between 0 and 10 elements + * ?> + * ``` + * @param $selector + * @param mixed $expected : + * - string: strict number + * - array: range of numbers [0,10] + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Module\WebDriver::seeNumberOfElements() + */ + public function canSeeNumberOfElements($selector, $expected) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeNumberOfElements', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that there are a certain number of elements matched by the given locator on the page. + * + * ``` php + * seeNumberOfElements('tr', 10); + * $I->seeNumberOfElements('tr', [0,10]); //between 0 and 10 elements + * ?> + * ``` + * @param $selector + * @param mixed $expected : + * - string: strict number + * - array: range of numbers [0,10] + * @see \Codeception\Module\WebDriver::seeNumberOfElements() + */ + public function seeNumberOfElements($selector, $expected) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeNumberOfElements', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Module\WebDriver::seeNumberOfElementsInDOM() + */ + public function canSeeNumberOfElementsInDOM($selector, $expected) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeNumberOfElementsInDOM', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\WebDriver::seeNumberOfElementsInDOM() + */ + public function seeNumberOfElementsInDOM($selector, $expected) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeNumberOfElementsInDOM', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the given option is selected. + * + * ``` php + * seeOptionIsSelected('#form input[name=payment]', 'Visa'); + * ?> + * ``` + * + * @param $selector + * @param $optionText + * + * @return mixed + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Module\WebDriver::seeOptionIsSelected() + */ + public function canSeeOptionIsSelected($selector, $optionText) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeOptionIsSelected', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the given option is selected. + * + * ``` php + * seeOptionIsSelected('#form input[name=payment]', 'Visa'); + * ?> + * ``` + * + * @param $selector + * @param $optionText + * + * @return mixed + * @see \Codeception\Module\WebDriver::seeOptionIsSelected() + */ + public function seeOptionIsSelected($selector, $optionText) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeOptionIsSelected', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the given option is not selected. + * + * ``` php + * dontSeeOptionIsSelected('#form input[name=payment]', 'Visa'); + * ?> + * ``` + * + * @param $selector + * @param $optionText + * + * @return mixed + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Module\WebDriver::dontSeeOptionIsSelected() + */ + public function cantSeeOptionIsSelected($selector, $optionText) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeOptionIsSelected', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the given option is not selected. + * + * ``` php + * dontSeeOptionIsSelected('#form input[name=payment]', 'Visa'); + * ?> + * ``` + * + * @param $selector + * @param $optionText + * + * @return mixed + * @see \Codeception\Module\WebDriver::dontSeeOptionIsSelected() + */ + public function dontSeeOptionIsSelected($selector, $optionText) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeOptionIsSelected', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the page title contains the given string. + * + * ``` php + * seeInTitle('Blog - Post #1'); + * ?> + * ``` + * + * @param $title + * + * @return mixed + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Module\WebDriver::seeInTitle() + */ + public function canSeeInTitle($title) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInTitle', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the page title contains the given string. + * + * ``` php + * seeInTitle('Blog - Post #1'); + * ?> + * ``` + * + * @param $title + * + * @return mixed + * @see \Codeception\Module\WebDriver::seeInTitle() + */ + public function seeInTitle($title) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInTitle', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the page title does not contain the given string. + * + * @param $title + * + * @return mixed + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Module\WebDriver::dontSeeInTitle() + */ + public function cantSeeInTitle($title) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInTitle', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the page title does not contain the given string. + * + * @param $title + * + * @return mixed + * @see \Codeception\Module\WebDriver::dontSeeInTitle() + */ + public function dontSeeInTitle($title) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeInTitle', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Accepts the active JavaScript native popup window, as created by `window.alert`|`window.confirm`|`window.prompt`. + * Don't confuse popups with modal windows, + * as created by [various libraries](http://jster.net/category/windows-modals-popups). + * @see \Codeception\Module\WebDriver::acceptPopup() + */ + public function acceptPopup() { + return $this->getScenario()->runStep(new \Codeception\Step\Action('acceptPopup', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Dismisses the active JavaScript popup, as created by `window.alert`|`window.confirm`|`window.prompt`. + * @see \Codeception\Module\WebDriver::cancelPopup() + */ + public function cancelPopup() { + return $this->getScenario()->runStep(new \Codeception\Step\Action('cancelPopup', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the active JavaScript popup, + * as created by `window.alert`|`window.confirm`|`window.prompt`, contains the given string. + * + * @param $text + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Module\WebDriver::seeInPopup() + */ + public function canSeeInPopup($text) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInPopup', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the active JavaScript popup, + * as created by `window.alert`|`window.confirm`|`window.prompt`, contains the given string. + * + * @param $text + * @see \Codeception\Module\WebDriver::seeInPopup() + */ + public function seeInPopup($text) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInPopup', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Enters text into a native JavaScript prompt popup, as created by `window.prompt`. + * + * @param $keys + * @see \Codeception\Module\WebDriver::typeInPopup() + */ + public function typeInPopup($keys) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('typeInPopup', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Reloads the current page. + * @see \Codeception\Module\WebDriver::reloadPage() + */ + public function reloadPage() { + return $this->getScenario()->runStep(new \Codeception\Step\Action('reloadPage', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Moves back in history. + * @see \Codeception\Module\WebDriver::moveBack() + */ + public function moveBack() { + return $this->getScenario()->runStep(new \Codeception\Step\Action('moveBack', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Moves forward in history. + * @see \Codeception\Module\WebDriver::moveForward() + */ + public function moveForward() { + return $this->getScenario()->runStep(new \Codeception\Step\Action('moveForward', func_get_args())); + } + + /** * [!] Method is generated. Documentation taken from corresponding module. * * Submits the given form on the page, optionally with the given form - * values. Pass the form field's values as an array in the second - * parameter. + * values. Give the form fields values as an array. Note that hidden fields + * can't be accessed. * - * Although this function can be used as a short-hand version of - * `fillField()`, `selectOption()`, `click()` etc. it has some important - * differences: - * - * * Only field *names* may be used, not CSS/XPath selectors nor field labels - * * If a field is sent to this function that does *not* exist on the page, - * it will silently be added to the HTTP request. This is helpful for testing - * some types of forms, but be aware that you will *not* get an exception - * like you would if you called `fillField()` or `selectOption()` with - * a missing field. - * - * Fields that are not provided will be filled by their values from the page, - * or from any previous calls to `fillField()`, `selectOption()` etc. + * Skipped fields will be filled by their values from the page. * You don't need to click the 'Submit' button afterwards. * This command itself triggers the request to form's action. * - * You can optionally specify which button's value to include - * in the request with the last parameter (as an alternative to - * explicitly setting its value in the second parameter), as + * You can optionally specify what button's value to include + * in the request with the last parameter as an alternative to + * explicitly setting its value in the second parameter, as * button values are not otherwise included in the request. * * Examples: @@ -1280,11 +2141,9 @@ trait AcceptanceTesterActions * $I->submitForm( * '#userForm', * [ - * 'user' => [ - * 'login' => 'Davert', - * 'password' => '123456', - * 'agree' => true - * ] + * 'user[login]' => 'Davert', + * 'user[password]' => '123456', + * 'user[agree]' => true * ], * 'submitButton' * ); @@ -1292,25 +2151,11 @@ trait AcceptanceTesterActions * Note that "2" will be the submitted value for the "plan" field, as it is * the selected option. * - * You can also emulate a JavaScript submission by not specifying any - * buttons in the third parameter to submitForm. + * Also note that this differs from PhpBrowser, in that + * ```'user' => [ 'login' => 'Davert' ]``` is not supported at the moment. + * Named array keys *must* be included in the name as above. * - * ```php - * submitForm( - * '#userForm', - * [ - * 'user' => [ - * 'login' => 'Davert', - * 'password' => '123456', - * 'agree' => true - * ] - * ] - * ); - * ``` - * - * This function works well when paired with `seeInFormFields()` - * for quickly testing CRUD interfaces and form validation logic. + * Pair this with seeInFormFields for quick testing magic. * * ``` php * true, * // ... * ]; - * $I->submitForm('#my-form', $form, 'submitButton'); + * $I->submitForm('//form[@id=my-form]', $form, 'submitButton'); * // $I->amOnPage('/path/to/form-page') may be needed - * $I->seeInFormFields('#my-form', $form); + * $I->seeInFormFields('//form[@id=my-form]', $form); + * ?> * ``` * - * Parameter values can be set to arrays for multiple input fields + * Parameter values must be set to arrays for multiple input fields * of the same name, or multi-select combo boxes. For checkboxes, - * you can use either the string value or boolean `true`/`false` which will + * either the string value can be used, or boolean values which will * be replaced by the checkbox's value in the DOM. * * ``` php @@ -1336,7 +2182,7 @@ trait AcceptanceTesterActions * 'field1' => 'value', * 'checkbox' => [ * 'value of first checkbox', - * 'value of second checkbox', + * 'value of second checkbox, * ], * 'otherCheckboxes' => [ * true, @@ -1348,29 +2194,27 @@ trait AcceptanceTesterActions * 'second option value' * ] * ]); + * ?> * ``` * * Mixing string and boolean values for a checkbox's value is not supported * and may produce unexpected results. * - * Field names ending in `[]` must be passed without the trailing square + * Field names ending in "[]" must be passed without the trailing square * bracket characters, and must contain an array for its value. This allows * submitting multiple values with the same name, consider: * * ```php - * submitForm('#my-form', [ * 'field[]' => 'value', - * 'field[]' => 'another value', // 'field[]' is already a defined key + * 'field[]' => 'another value', // 'field[]' is already a defined key * ]); * ``` * * The solution is to pass an array value: * * ```php - * submitForm('#my-form', [ * 'field' => [ * 'value', @@ -1378,11 +2222,10 @@ trait AcceptanceTesterActions * ] * ]); * ``` - * * @param $selector * @param $params * @param $button - * @see \Codeception\Lib\InnerBrowser::submitForm() + * @see \Codeception\Module\WebDriver::submitForm() */ public function submitForm($selector, $params, $button = null) { return $this->getScenario()->runStep(new \Codeception\Step\Action('submitForm', func_get_args())); @@ -1392,856 +2235,586 @@ trait AcceptanceTesterActions /** * [!] Method is generated. Documentation taken from corresponding module. * - * Fills a text field or textarea with the given string. + * Waits up to $timeout seconds for the given element to change. + * Element "change" is determined by a callback function which is called repeatedly + * until the return value evaluates to true. * * ``` php * fillField("//input[@type='text']", "Hello World!"); - * $I->fillField(['name' => 'email'], 'jon@mail.com'); + * use \Facebook\WebDriver\WebDriverElement + * $I->waitForElementChange('#menu', function(WebDriverElement $el) { + * return $el->isDisplayed(); + * }, 100); * ?> * ``` * - * @param $field - * @param $value - * @see \Codeception\Lib\InnerBrowser::fillField() + * @param $element + * @param \Closure $callback + * @param int $timeout seconds + * @throws \Codeception\Exception\ElementNotFound + * @see \Codeception\Module\WebDriver::waitForElementChange() */ - public function fillField($field, $value) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('fillField', func_get_args())); + public function waitForElementChange($element, $callback, $timeout = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('waitForElementChange', func_get_args())); } /** * [!] Method is generated. Documentation taken from corresponding module. * - * Selects an option in a select tag or in radio button group. + * Waits up to $timeout seconds for an element to appear on the page. + * If the element doesn't appear, a timeout exception is thrown. * * ``` php * selectOption('form select[name=account]', 'Premium'); - * $I->selectOption('form input[name=payment]', 'Monthly'); - * $I->selectOption('//form/select[@name=account]', 'Monthly'); + * $I->waitForElement('#agree_button', 30); // secs + * $I->click('#agree_button'); * ?> * ``` * - * Provide an array for the second argument to select multiple options: - * - * ``` php - * selectOption('Which OS do you use?', array('Windows','Linux')); - * ?> - * ``` - * - * Or provide an associative array for the second argument to specifically define which selection method should be used: - * - * ``` php - * selectOption('Which OS do you use?', array('text' => 'Windows')); // Only search by text 'Windows' - * $I->selectOption('Which OS do you use?', array('value' => 'windows')); // Only search by value 'windows' - * ?> - + ``` - * - * @param $select - * @param $option - * @see \Codeception\Lib\InnerBrowser::selectOption() + * @param $element + * @param int $timeout seconds + * @throws \Exception + * @see \Codeception\Module\WebDriver::waitForElement() */ - public function selectOption($select, $option) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('selectOption', func_get_args())); + public function waitForElement($element, $timeout = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('waitForElement', func_get_args())); } /** * [!] Method is generated. Documentation taken from corresponding module. * - * Ticks a checkbox. For radio buttons, use the `selectOption` method instead. + * Waits up to $timeout seconds for the given element to be visible on the page. + * If element doesn't appear, a timeout exception is thrown. * * ``` php * checkOption('#agree'); + * $I->waitForElementVisible('#agree_button', 30); // secs + * $I->click('#agree_button'); * ?> * ``` * - * @param $option - * @see \Codeception\Lib\InnerBrowser::checkOption() + * @param $element + * @param int $timeout seconds + * @throws \Exception + * @see \Codeception\Module\WebDriver::waitForElementVisible() */ - public function checkOption($option) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('checkOption', func_get_args())); + public function waitForElementVisible($element, $timeout = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('waitForElementVisible', func_get_args())); } /** * [!] Method is generated. Documentation taken from corresponding module. * - * Unticks a checkbox. + * Waits up to $timeout seconds for the given element to become invisible. + * If element stays visible, a timeout exception is thrown. * * ``` php * uncheckOption('#notify'); + * $I->waitForElementNotVisible('#agree_button', 30); // secs * ?> * ``` * - * @param $option - * @see \Codeception\Lib\InnerBrowser::uncheckOption() + * @param $element + * @param int $timeout seconds + * @throws \Exception + * @see \Codeception\Module\WebDriver::waitForElementNotVisible() */ - public function uncheckOption($option) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('uncheckOption', func_get_args())); + public function waitForElementNotVisible($element, $timeout = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('waitForElementNotVisible', func_get_args())); } /** * [!] Method is generated. Documentation taken from corresponding module. * - * Attaches a file relative to the Codeception data directory to the given file upload field. + * Waits up to $timeout seconds for the given string to appear on the page. + * Can also be passed a selector to search in. + * If the given text doesn't appear, a timeout exception is thrown. * * ``` php * attachFile('input[@type="file"]', 'prices.xls'); + * $I->waitForText('foo', 30); // secs + * $I->waitForText('foo', 30, '.title'); // secs * ?> * ``` * - * @param $field - * @param $filename - * @see \Codeception\Lib\InnerBrowser::attachFile() + * @param string $text + * @param int $timeout seconds + * @param null $selector + * @throws \Exception + * @see \Codeception\Module\WebDriver::waitForText() */ - public function attachFile($field, $filename) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('attachFile', func_get_args())); + public function waitForText($text, $timeout = null, $selector = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('waitForText', func_get_args())); } /** * [!] Method is generated. Documentation taken from corresponding module. * - * If your page triggers an ajax request, you can perform it manually. - * This action sends a GET ajax request with specified params. + * Wait for $timeout seconds. * - * See ->sendAjaxPostRequest for examples. - * - * @param $uri - * @param $params - * @see \Codeception\Lib\InnerBrowser::sendAjaxGetRequest() + * @param int $timeout secs + * @throws \Codeception\Exception\TestRuntimeException + * @see \Codeception\Module\WebDriver::wait() */ - public function sendAjaxGetRequest($uri, $params = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('sendAjaxGetRequest', func_get_args())); + public function wait($timeout) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('wait', func_get_args())); } /** * [!] Method is generated. Documentation taken from corresponding module. * - * If your page triggers an ajax request, you can perform it manually. - * This action sends a POST ajax request with specified params. - * Additional params can be passed as array. + * Low-level API method. + * If Codeception commands are not enough, this allows you to use Selenium WebDriver methods directly: + * + * ``` php + * $I->executeInSelenium(function(\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) { + * $webdriver->get('http://google.com'); + * }); + * ``` + * + * This runs in the context of the + * [RemoteWebDriver class](https://github.com/facebook/php-webdriver/blob/master/lib/remote/RemoteWebDriver.php). + * Try not to use this command on a regular basis. + * If Codeception lacks a feature you need, please implement it and submit a patch. + * + * @param callable $function + * @see \Codeception\Module\WebDriver::executeInSelenium() + */ + public function executeInSelenium($function) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('executeInSelenium', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Switch to another window identified by name. + * + * The window can only be identified by name. If the $name parameter is blank, the parent window will be used. * * Example: - * - * Imagine that by clicking checkbox you trigger ajax request which updates user settings. - * We emulate that click by running this ajax request manually. - * - * ``` php - * sendAjaxPostRequest('/updateSettings', array('notifications' => true)); // POST - * $I->sendAjaxGetRequest('/updateSettings', array('notifications' => true)); // GET - * + * ``` html + * * ``` * - * @param $uri - * @param $params - * @see \Codeception\Lib\InnerBrowser::sendAjaxPostRequest() - */ - public function sendAjaxPostRequest($uri, $params = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('sendAjaxPostRequest', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * If your page triggers an ajax request, you can perform it manually. - * This action sends an ajax request with specified method and params. - * - * Example: - * - * You need to perform an ajax request specifying the HTTP method. - * * ``` php * sendAjaxRequest('PUT', '/posts/7', array('title' => 'new title')); - * - * ``` - * - * @param $method - * @param $uri - * @param $params - * @see \Codeception\Lib\InnerBrowser::sendAjaxRequest() - */ - public function sendAjaxRequest($method, $uri, $params = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('sendAjaxRequest', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Finds and returns the text contents of the given element. - * If a fuzzy locator is used, the element is found using CSS, XPath, - * and by matching the full page source by regular expression. - * - * ``` php - * grabTextFrom('h1'); - * $heading = $I->grabTextFrom('descendant-or-self::h1'); - * $value = $I->grabTextFrom('~click("Open window"); + * # switch to another window + * $I->switchToWindow("another_window"); + * # switch to parent window + * $I->switchToWindow(); * ?> * ``` * - * @param $cssOrXPathOrRegex - * - * @return mixed - * @see \Codeception\Lib\InnerBrowser::grabTextFrom() - */ - public function grabTextFrom($cssOrXPathOrRegex) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('grabTextFrom', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Grabs the value of the given attribute value from the given element. - * Fails if element is not found. + * If the window has no name, the only way to access it is via the `executeInSelenium()` method, like so: * * ``` php * grabAttributeFrom('#tooltip', 'title'); + * $I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) { + * $handles=$webdriver->getWindowHandles(); + * $last_window = end($handles); + * $webdriver->switchTo()->window($last_window); + * }); * ?> * ``` * - * - * @param $cssOrXpath - * @param $attribute - * - * @return mixed - * @see \Codeception\Lib\InnerBrowser::grabAttributeFrom() + * @param string|null $name + * @see \Codeception\Module\WebDriver::switchToWindow() */ - public function grabAttributeFrom($cssOrXpath, $attribute) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('grabAttributeFrom', func_get_args())); + public function switchToWindow($name = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('switchToWindow', func_get_args())); } /** * [!] Method is generated. Documentation taken from corresponding module. * - * Grabs either the text content, or attribute values, of nodes - * matched by $cssOrXpath and returns them as an array. - * - * ```html - * First - * Second - * Third - * ``` - * - * ```php - * grabMultiple('a'); - * - * // would return ['#first', '#second', '#third'] - * $aLinks = $I->grabMultiple('a', 'href'); - * ?> - * ``` - * - * @param $cssOrXpath - * @param $attribute - * @return string[] - * @see \Codeception\Lib\InnerBrowser::grabMultiple() - */ - public function grabMultiple($cssOrXpath, $attribute = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('grabMultiple', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * @param $field - * - * @return array|mixed|null|string - * @see \Codeception\Lib\InnerBrowser::grabValueFrom() - */ - public function grabValueFrom($field) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('grabValueFrom', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Sets a cookie with the given name and value. - * You can set additional cookie params like `domain`, `path`, `expires`, `secure` in array passed as last argument. - * - * ``` php - * setCookie('PHPSESSID', 'el4ukv0kqbvoirg7nkp4dncpk3'); - * ?> - * ``` - * - * @param $name - * @param $val - * @param array $params - * - * @return mixed - * @see \Codeception\Lib\InnerBrowser::setCookie() - */ - public function setCookie($name, $val, $params = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('setCookie', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Grabs a cookie value. - * You can set additional cookie params like `domain`, `path` in array passed as last argument. - * - * @param $cookie - * - * @param array $params - * @return mixed - * @see \Codeception\Lib\InnerBrowser::grabCookie() - */ - public function grabCookie($cookie, $params = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('grabCookie', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that a cookie with the given name is set. - * You can set additional cookie params like `domain`, `path` as array passed in last argument. - * - * ``` php - * seeCookie('PHPSESSID'); - * ?> - * ``` - * - * @param $cookie - * @param array $params - * @return mixed - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::seeCookie() - */ - public function canSeeCookie($cookie, $params = null) { - return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeCookie', func_get_args())); - } - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that a cookie with the given name is set. - * You can set additional cookie params like `domain`, `path` as array passed in last argument. - * - * ``` php - * seeCookie('PHPSESSID'); - * ?> - * ``` - * - * @param $cookie - * @param array $params - * @return mixed - * @see \Codeception\Lib\InnerBrowser::seeCookie() - */ - public function seeCookie($cookie, $params = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeCookie', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that there isn't a cookie with the given name. - * You can set additional cookie params like `domain`, `path` as array passed in last argument. - * - * @param $cookie - * - * @param array $params - * @return mixed - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::dontSeeCookie() - */ - public function cantSeeCookie($cookie, $params = null) { - return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeCookie', func_get_args())); - } - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that there isn't a cookie with the given name. - * You can set additional cookie params like `domain`, `path` as array passed in last argument. - * - * @param $cookie - * - * @param array $params - * @return mixed - * @see \Codeception\Lib\InnerBrowser::dontSeeCookie() - */ - public function dontSeeCookie($cookie, $params = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeCookie', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Unsets cookie with the given name. - * You can set additional cookie params like `domain`, `path` in array passed as last argument. - * - * @param $cookie - * - * @param array $params - * @return mixed - * @see \Codeception\Lib\InnerBrowser::resetCookie() - */ - public function resetCookie($name, $params = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('resetCookie', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the given element exists on the page and is visible. - * You can also specify expected attributes of this element. - * - * ``` php - * seeElement('.error'); - * $I->seeElement('//form/input[1]'); - * $I->seeElement('input', ['name' => 'login']); - * $I->seeElement('input', ['value' => '123456']); - * - * // strict locator in first arg, attributes in second - * $I->seeElement(['css' => 'form input'], ['name' => 'login']); - * ?> - * ``` - * - * @param $selector - * @param array $attributes - * @return - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::seeElement() - */ - public function canSeeElement($selector, $attributes = null) { - return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeElement', func_get_args())); - } - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the given element exists on the page and is visible. - * You can also specify expected attributes of this element. - * - * ``` php - * seeElement('.error'); - * $I->seeElement('//form/input[1]'); - * $I->seeElement('input', ['name' => 'login']); - * $I->seeElement('input', ['value' => '123456']); - * - * // strict locator in first arg, attributes in second - * $I->seeElement(['css' => 'form input'], ['name' => 'login']); - * ?> - * ``` - * - * @param $selector - * @param array $attributes - * @return - * @see \Codeception\Lib\InnerBrowser::seeElement() - */ - public function seeElement($selector, $attributes = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeElement', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the given element is invisible or not present on the page. - * You can also specify expected attributes of this element. - * - * ``` php - * dontSeeElement('.error'); - * $I->dontSeeElement('//form/input[1]'); - * $I->dontSeeElement('input', ['name' => 'login']); - * $I->dontSeeElement('input', ['value' => '123456']); - * ?> - * ``` - * - * @param $selector - * @param array $attributes - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::dontSeeElement() - */ - public function cantSeeElement($selector, $attributes = null) { - return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeElement', func_get_args())); - } - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the given element is invisible or not present on the page. - * You can also specify expected attributes of this element. - * - * ``` php - * dontSeeElement('.error'); - * $I->dontSeeElement('//form/input[1]'); - * $I->dontSeeElement('input', ['name' => 'login']); - * $I->dontSeeElement('input', ['value' => '123456']); - * ?> - * ``` - * - * @param $selector - * @param array $attributes - * @see \Codeception\Lib\InnerBrowser::dontSeeElement() - */ - public function dontSeeElement($selector, $attributes = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeElement', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that there are a certain number of elements matched by the given locator on the page. - * - * ``` php - * seeNumberOfElements('tr', 10); - * $I->seeNumberOfElements('tr', [0,10]); //between 0 and 10 elements - * ?> - * ``` - * @param $selector - * @param mixed $expected : - * - string: strict number - * - array: range of numbers [0,10] - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::seeNumberOfElements() - */ - public function canSeeNumberOfElements($selector, $expected) { - return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeNumberOfElements', func_get_args())); - } - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that there are a certain number of elements matched by the given locator on the page. - * - * ``` php - * seeNumberOfElements('tr', 10); - * $I->seeNumberOfElements('tr', [0,10]); //between 0 and 10 elements - * ?> - * ``` - * @param $selector - * @param mixed $expected : - * - string: strict number - * - array: range of numbers [0,10] - * @see \Codeception\Lib\InnerBrowser::seeNumberOfElements() - */ - public function seeNumberOfElements($selector, $expected) { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeNumberOfElements', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the given option is selected. - * - * ``` php - * seeOptionIsSelected('#form input[name=payment]', 'Visa'); - * ?> - * ``` - * - * @param $selector - * @param $optionText - * - * @return mixed - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::seeOptionIsSelected() - */ - public function canSeeOptionIsSelected($selector, $optionText) { - return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeOptionIsSelected', func_get_args())); - } - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the given option is selected. - * - * ``` php - * seeOptionIsSelected('#form input[name=payment]', 'Visa'); - * ?> - * ``` - * - * @param $selector - * @param $optionText - * - * @return mixed - * @see \Codeception\Lib\InnerBrowser::seeOptionIsSelected() - */ - public function seeOptionIsSelected($selector, $optionText) { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeOptionIsSelected', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the given option is not selected. - * - * ``` php - * dontSeeOptionIsSelected('#form input[name=payment]', 'Visa'); - * ?> - * ``` - * - * @param $selector - * @param $optionText - * - * @return mixed - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::dontSeeOptionIsSelected() - */ - public function cantSeeOptionIsSelected($selector, $optionText) { - return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeOptionIsSelected', func_get_args())); - } - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the given option is not selected. - * - * ``` php - * dontSeeOptionIsSelected('#form input[name=payment]', 'Visa'); - * ?> - * ``` - * - * @param $selector - * @param $optionText - * - * @return mixed - * @see \Codeception\Lib\InnerBrowser::dontSeeOptionIsSelected() - */ - public function dontSeeOptionIsSelected($selector, $optionText) { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeOptionIsSelected', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Asserts that current page has 404 response status code. - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::seePageNotFound() - */ - public function canSeePageNotFound() { - return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seePageNotFound', func_get_args())); - } - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Asserts that current page has 404 response status code. - * @see \Codeception\Lib\InnerBrowser::seePageNotFound() - */ - public function seePageNotFound() { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seePageNotFound', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that response code is equal to value provided. - * - * ```php - * seeResponseCodeIs(200); - * - * // recommended \Codeception\Util\HttpCode - * $I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK); - * ``` - * - * @param $code - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIs() - */ - public function canSeeResponseCodeIs($code) { - return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeResponseCodeIs', func_get_args())); - } - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that response code is equal to value provided. - * - * ```php - * seeResponseCodeIs(200); - * - * // recommended \Codeception\Util\HttpCode - * $I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK); - * ``` - * - * @param $code - * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIs() - */ - public function seeResponseCodeIs($code) { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeResponseCodeIs', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that response code is equal to value provided. - * - * ```php - * dontSeeResponseCodeIs(200); - * - * // recommended \Codeception\Util\HttpCode - * $I->dontSeeResponseCodeIs(\Codeception\Util\HttpCode::OK); - * ``` - * @param $code - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::dontSeeResponseCodeIs() - */ - public function cantSeeResponseCodeIs($code) { - return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeResponseCodeIs', func_get_args())); - } - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that response code is equal to value provided. - * - * ```php - * dontSeeResponseCodeIs(200); - * - * // recommended \Codeception\Util\HttpCode - * $I->dontSeeResponseCodeIs(\Codeception\Util\HttpCode::OK); - * ``` - * @param $code - * @see \Codeception\Lib\InnerBrowser::dontSeeResponseCodeIs() - */ - public function dontSeeResponseCodeIs($code) { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeResponseCodeIs', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the page title contains the given string. - * - * ``` php - * seeInTitle('Blog - Post #1'); - * ?> - * ``` - * - * @param $title - * - * @return mixed - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::seeInTitle() - */ - public function canSeeInTitle($title) { - return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInTitle', func_get_args())); - } - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the page title contains the given string. - * - * ``` php - * seeInTitle('Blog - Post #1'); - * ?> - * ``` - * - * @param $title - * - * @return mixed - * @see \Codeception\Lib\InnerBrowser::seeInTitle() - */ - public function seeInTitle($title) { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInTitle', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the page title does not contain the given string. - * - * @param $title - * - * @return mixed - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Lib\InnerBrowser::dontSeeInTitle() - */ - public function cantSeeInTitle($title) { - return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInTitle', func_get_args())); - } - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the page title does not contain the given string. - * - * @param $title - * - * @return mixed - * @see \Codeception\Lib\InnerBrowser::dontSeeInTitle() - */ - public function dontSeeInTitle($title) { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeInTitle', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Switch to iframe or frame on the page. + * Switch to another frame on the page. * * Example: * ``` html *