For additional reference, please review the source
Uses Mink to manipulate Selenium2 WebDriver
Note that all method take CSS selectors to fetch elements.
On test failure the browser window screenshot will be saved to log directory
Download Selenium2 WebDriver
Launch the daemon: java -jar selenium-server-standalone-2.xx.xxx.jar
Don't forget to turn on Db repopulation if you are using database.
- Maintainer: davert
- Stability: stable
- Contact: codecept@davert.mail.ua
- relies on Mink
- url required - start url for your app
- browser required - browser that would be launched
- host - Selenium server host (localhost by default)
- port - Selenium server port (4444 by default)
- delay - set delay between actions in milliseconds (1/1000 of second) if they run too fast
- capabilities - sets Selenium2 desired capabilities. Should be a key-value array.
modules:
enabled: [Selenium2]
config:
Selenium2:
url: 'http://localhost/'
browser: firefox
capabilities:
unexpectedAlertBehaviour: 'accept'
- session - contains Mink Session
- webDriverSession - contains webDriverSession object, i.e. $session from php-webdriver
Accept alert or confirm popup
Example:
<?php
$I->click('Show alert popup');
$I->acceptPopup();Opens the page.
- param $page
Sets 'url' configuration parameter to hosts subdomain.
It does not open a page on subdomain. Use amOnPage for that
<?php
// If config is: 'http://mysite.com'
// or config is: 'http://www.mysite.com'
// or config is: 'http://company.mysite.com'
$I->amOnSubdomain('user');
$I->amOnPage('/');
// moves to http://user.mysite.com/
?>- param $subdomain
- return mixed
Attaches file from Codeception data directory to upload field.
Example:
<?php
// file is stored in 'tests/_data/prices.xls'
$I->attachFile('input[@type="file"]', 'prices.xls');
?>- param $field
- param $filename
Removes focus from link or button or any node found by CSS or XPath XPath or CSS selectors are accepted.
- param $el
Dismiss alert or confirm popup
Example:
<?php
$I->click('Show confirm popup');
$I->cancelPopup();Ticks a checkbox.
For radio buttons use selectOption method.
Example:
<?php
$I->checkOption('#agree');
?>- param $option
Perform a click on link or button. Link or button are found by their names or CSS selector. Submits a form if button is a submit type.
If link is an image it's found by alt attribute value of image. If button is image button is found by it's value If link or button can't be found by name they are searched by CSS selector.
The second parameter is a context: CSS or XPath locator to narrow the search.
Examples:
<?php
// simple link
$I->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');
?>- param $link
- param $context
Clicks with right button on link or button or any node found by CSS or XPath
- param $link
-
param string $text
-
param string $selector
-
return void
Assert if the specified checkbox is unchecked. Use css selector or xpath to match.
Example:
<?php
$I->dontSeeCheckboxIsChecked('#agree'); // I suppose user didn't agree to terms
$I->seeCheckboxIsChecked('#signup_form input[type=checkbox]'); // I suppose user didn't check the first checkbox in form.
?>- param $checkbox
Checks that cookie doesn't exist
- param $cookie
- return mixed
Checks that current url is not equal to value.
Unlike dontSeeInCurrentUrl performs a strict check.
<?php
// current url is not root
$I->dontSeeCurrentUrlEquals('/');
?>- param $uri
Checks that current url does not match a RegEx value
<?php
// to match root url
$I->dontSeeCurrentUrlMatches('~$/users/(\d+)~');
?>- param $uri
Checks if element does not exist (or is visible) on a page, matching it by CSS or XPath
Example:
<?php
$I->dontSeeElement('.error');
$I->dontSeeElement('//form/input[1]');
?>- param $selector
Checks that current uri does not contain a value
<?php
$I->dontSeeInCurrentUrl('/users/');
?>- param $uri
Checks that an input field or textarea doesn't contain value. Field is matched either by label or CSS or Xpath Example:
<?php
$I->dontSeeInField('Body','Type your comment here');
$I->dontSeeInField('form textarea[name=body]','Type your comment here');
$I->dontSeeInField('form input[type=hidden]','hidden_value');
$I->dontSeeInField('#searchform input','Search');
$I->dontSeeInField('//form/*[@name=search]','Search');
?>- param $field
- param $value
Check if popup don't contains the $text
Example:
<?php
$I->click();
$I->dontSeeInPopup('Error message');- param string $text
Checks that page title does not contain text.
- param $title
- return mixed
Checks if page doesn't contain the link with text specified. Specify url to narrow the results.
Examples:
<?php
$I->dontSeeLink('Logout'); // I suppose user is not logged in
?>- param $text
- param null $url
Checks if option is not selected in select field.
<?php
$I->dontSeeOptionIsSelected('#form input[name=payment]', 'Visa');
?>- param $selector
- param $optionText
- return mixed
Double clicks on link or button or any node found by CSS or XPath
- param $link
Drag first element to second XPath or CSS selectors are accepted.
- param $el1
- param $el2
Low-level API method. If Codeception commands are not enough, use Selenium WebDriver methods directly
$I->executeInSelenium(function(\WebDriver\Session $webdriver) {
$webdriver->back();
});Use WebDriver Session API Not recommended this command too be used on regular basis. If Codeception lacks important Selenium methods implement then and submit patches.
- param callable $function
Executes any JS code.
- param $jsCode
Fills a text field or textarea with value.
Example:
<?php
$I->fillField("//input[@type='text']", "Hello World!");
?>- param $field
- param $value
Moves focus to link or button or any node found by CSS or XPath
- param $el
not documented
Grabs a cookie value.
- param $cookie
- return mixed
Takes a parameters from current URI by RegEx. If no url provided returns full URI.
<?php
$user_id = $I->grabFromCurrentUrl('~$/user/(\d+)/~');
$uri = $I->grabFromCurrentUrl();
?>- param null $uri
- internal param $url
- return mixed
Finds and returns text contents of element. Element is searched by CSS selector, XPath or matcher by regex.
Example:
<?php
$heading = $I->grabTextFrom('h1');
$heading = $I->grabTextFrom('descendant-or-self::h1');
$value = $I->grabTextFrom('~<input value=(.*?)]~sgi');
?>- param $cssOrXPathOrRegex
- return mixed
Finds and returns field and returns it's value. Searches by field name, then by CSS, then by XPath
Example:
<?php
$name = $I->grabValueFrom('Name');
$name = $I->grabValueFrom('input[name=username]');
$name = $I->grabValueFrom('descendant-or-self::form/descendant::input[@name = 'username']');
?>- param $field
- return mixed
Moves back in history
Moves forward in history
Moves mouse over link or button or any node found by CSS or XPath
- param $link
Presses key on element found by css, xpath is focused A char and modifier (ctrl, alt, shift, meta) can be provided.
Example:
<?php
$I->pressKey('#page','u');
$I->pressKey('#page','u','ctrl');
$I->pressKey('descendant-or-self::*[@id='page']','u');
?>- param $element
- param $char char can be either char ('b') or char-code (98)
- param null $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
Presses key down on element found by CSS or XPath.
For example see 'pressKey'.
- param $element
- param $char char can be either char ('b') or char-code (98)
- param null $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
Presses key up on element found by CSS or XPath.
For example see 'pressKey'.
- param $element
- param $char char can be either char ('b') or char-code (98)
- param null $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
Reloads current page
Unsets cookie
- param $cookie
- return mixed
Resize current window
Example:
<?php
$I->resizeWindow(800, 600);- param int $width
- param int $height
- author Jaik Dean jaik@jaikdean.com
Check if current page contains the text specified. Specify the css selector to match only specific region.
Examples:
<?php
$I->see('Logout'); // I can suppose user is logged in
$I->see('Sign Up','h1'); // I can suppose it's a signup page
$I->see('Sign Up','//body/h1'); // with XPath
?>- param $text
- param null $selector
Assert if the specified checkbox is checked. Use css selector or xpath to match.
Example:
<?php
$I->seeCheckboxIsChecked('#agree'); // I suppose user agreed to terms
$I->seeCheckboxIsChecked('#signup_form input[type=checkbox]'); // I suppose user agreed to terms, If there is only one checkbox in form.
$I->seeCheckboxIsChecked('//form/input[@type=checkbox and * name=agree]');
?>- param $checkbox
Checks that cookie is set.
- param $cookie
- return mixed
Checks that current url is equal to value.
Unlike seeInCurrentUrl performs a strict check.
<?php
// to match root url
$I->seeCurrentUrlEquals('/');
?>- param $uri
Checks that current url is matches a RegEx value
<?php
// to match root url
$I->seeCurrentUrlMatches('~$/users/(\d+)~');
?>- param $uri
Checks element visibility. Fails if element exists but is invisible to user. Eiter CSS or XPath can be used.
Example:
<?php
$I->seeElement("//input[@type='button']");
?>- param $selector
Checks that current uri contains a value
<?php
// to match: /home/dashboard
$I->seeInCurrentUrl('home');
// to match: /users/1
$I->seeInCurrentUrl('/users/');
?>- param $uri
Checks that an input field or textarea contains value. Field is matched either by label or CSS or Xpath
Example:
<?php
$I->seeInField('Body','Type your comment here');
$I->seeInField('form textarea[name=body]','Type your comment here');
$I->seeInField('form input[type=hidden]','hidden_value');
$I->seeInField('#searchform input','Search');
$I->seeInField('//form/*[@name=search]','Search');
?>- param $field
- param $value
Checks if popup contains the $text
Example:
<?php
$I->click('Show alert popup');
$I->seeInPopup('Error message');- param string $text
Checks that page title contains text.
<?php
$I->seeInTitle('Blog - Post #1');
?>- param $title
- return mixed
Checks if there is a link with text specified. Specify url to match link with exact this url.
Examples:
<?php
$I->seeLink('Logout'); // matches <a href="#">Logout</a>
$I->seeLink('Logout','/logout'); // matches <a href="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/logout">Logout</a>
?>- param $text
- param null $url
Checks if option is selected in select field.
<?php
$I->seeOptionIsSelected('#form input[name=payment]', 'Visa');
?>- param $selector
- param $optionText
- return mixed
Selects an option in select tag or in radio button group.
Example:
<?php
$I->selectOption('form select[name=account]', 'Premium');
$I->selectOption('form input[name=payment]', 'Monthly');
$I->selectOption('//form/select[@name=account]', 'Monthly');
?>Can select multiple options if second argument is array:
<?php
$I->selectOption('Which OS do you use?', array('Windows','Linux'));
?>- param $select
- param $option
Sets a cookie.
- param $cookie
- param $value
- return mixed
Switch to another frame
Example:
<iframe name="another_frame" src="http://example.com"><?php
# switch to iframe
$I->switchToIFrame("another_frame");
# switch to parent page
$I->switchToIFrame();- param string|null $name
Switch to another window identified by its name.
The window can only be identified by its name. If the $name parameter is blank it will switch to the parent window.
Example:
<input type="button" value="Open window" onclick="window.open('http://example.com', 'another_window')"><?php
$I->click("Open window");
# switch to another window
$I->switchToWindow("another_window");
# switch to parent window
$I->switchToWindow();
?>If the window has no name, the only way to access it is via the executeInSelenium() method like so:
<?php
$I->executeInSelenium(function (\Webdriver\Session $webdriver) {
$handles=$webdriver->window_handles();
$last_window = end($handles);
$webdriver->focusWindow($last_window);
});
?>
- param string|null $name
Unticks a checkbox.
Example:
<?php
$I->uncheckOption('#notify');
?>- param $option
Wait for x milliseconds
Example:
<?php
$I->wait(1000); // waits 1000 milliseconds (one second)
?>- param $milliseconds
Waits for x milliseconds or until a given JS condition turns true. The function will keep asserting the javascript condition, but will continue regardless of its validity once the x milliseconds time has been passed.
See the example below on how to embed javascript functions as the condition.
Example:
<?php
$I->waitForJS(1000, "(function myJavascriptFunction() {
// Javascript function code
if (some statement) {
return true; // waitForJS() function will finish
} else {
return false; // keep asserting (some statement)
}
})()");
?>- param $milliseconds
- param $jsCondition