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.
acceptance.suite.yml)modules:
enabled: [Selenium2]
config:
Selenium2:
url: 'http://localhost/'
browser: firefox
capabilities:
unexpectedAlertBehaviour: 'accept'
Accept alert or confirm popup
Example:
<?php
$I->click('Show alert popup');
$I->acceptPopup();
Opens the 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/
?>
Attaches file from Codeception data directory to upload field.
Example:
<?php
// file is stored in 'tests/data/tests.xls'
$I->attachFile('prices.xls');
?>
Removes focus from link or button or any node found by CSS or XPath XPath or CSS selectors are accepted.
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');
?>
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');
?>
Clicks with right button on link or button or any node found by CSS or XPath
Check if current page doesn't contain the text specified. Specify the css selector to match only specific region.
Examples:
<?php
$I->dontSee('Login'); // I can suppose user is already logged in
$I->dontSee('Sign Up','h1'); // I can suppose it's not a signup page
$I->dontSee('Sign Up','//body/h1'); // with XPath
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.
not documented
Checks that current url is not equal to value.
Unlike dontSeeInCurrentUrl performs a strict check.
<?php // current url is not root $I->dontSeeCurrentUrlEquals('/'); ?>
Checks that current url does not match a RegEx value
<?php // to match root url $I->dontSeeCurrentUrlMatches('~$/users/(\d+)~'); ?>
Checks if element does not exist (or is visible) on a page, matching it by CSS or XPath
<?php
$I->dontSeeElement('.error');
$I->dontSeeElement(//form/input[1]);
?>
Checks that current uri does not contain a value
<?php
$I->dontSeeInCurrentUrl('/users/');
?>
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');
?>
Check if popup don't contains the $text
Example:
<?php
$I->click();
$I->dontSeeInPopup('Error message');
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
Checks if option is not selected in select field.
<?php
$I->dontSeeOptionIsSelected('#form input[name=payment]', 'Visa');
?>
Double clicks on link or button or any node found by CSS or XPath
Drag first element to second XPath or CSS selectors are accepted.
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.
Executes any JS code.
Fills a text field or textarea with value.
Moves focus to link or button or any node found by CSS or XPath
not documented
not documented
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();
?>
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');
?>
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']');
?>
Moves back in history
Moves forward in history
Moves mouse over link or button or any node found by CSS or XPath
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');
?>
Presses key down on element found by CSS or XPath.
For example see 'pressKey'.
Presses key up on element found by CSS or XPath.
For example see 'pressKey'.
Reloads current page
not documented
Resize current window
Example:
<?php
$I->resizeWindow(800, 600);
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
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]');
not documented
Checks that current url is equal to value.
Unlike seeInCurrentUrl performs a strict check.
<?php // to match root url $I->seeCurrentUrlEquals('/'); ?>
Checks that current url is matches a RegEx value
<?php // to match root url $I->seeCurrentUrlMatches('~$/users/(\d+)~'); ?>
Checks element visibility. Fails if element exists but is invisible to user. Eiter CSS or XPath can be used.
Checks that current uri contains a value
<?php
// to match: /home/dashboard
$I->seeInCurrentUrl('home');
// to match: /users/1
$I->seeInCurrentUrl('/users/');
?>
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');
?>
Checks if popup contains the $text
Example:
<?php
$I->click('Show alert popup');
$I->seeInPopup('Error message');
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="/logout">Logout</a>
Checks if option is selected in select field.
<?php
$I->seeOptionIsSelected('#form input[name=payment]', 'Visa');
?>
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');
?>
not documented
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();
Switch to another 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();
Unticks a checkbox.
Example:
<?php
$I->uncheckOption('#notify');
?>
Wait for x milliseconds
Waits for x milliseconds or until JS condition turns true.