| layout | doc |
|---|---|
| title | Codeception - Documentation |
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
- session - contains Mink Session
Accept alert or confirm popup
Example: {% highlight php %}
click('Show alert popup'); $I->acceptPopup(); {% endhighlight %} #### amOnPage Opens the page. * param $page #### attachFile Attaches file from Codeception data directory to upload field. Example: {% highlight php %} attachFile('prices.xls'); ?>{% endhighlight %}
- 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: {% highlight php %}
click('Show confirm popup'); $I->cancelPopup(); {% endhighlight %} #### checkOption Ticks a checkbox. For radio buttons use `selectOption` method. Example: {% highlight php %} checkOption('#agree'); ?>{% endhighlight %}
- 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.
Examples:
{% highlight php %}
click('Logout'); // button of form $I->click('Submit'); // CSS button $I->click('#form input[type=submit]'); // XPath $I->click('//form/*[@type=submit]') ?>{% endhighlight %}
- param $link
Clicks with right button on link or button or any node found by CSS or XPath
- param $link
Check if current page doesn't contain the text specified. Specify the css selector to match only specific region.
Examples:
{% highlight php %}
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 {% endhighlight %} * param $text * param null $selector #### dontSeeCheckboxIsChecked Assert if the specified checkbox is unchecked. Use css selector or xpath to match. Example: {% highlight php %} 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. {% endhighlight %} * param $checkbox #### dontSeeInField Checks that an input field or textarea doesn't contain value. Example: {% highlight php %} 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'); ?>{% endhighlight %}
- param $field
- param $value
Check if popup don't contains the $text
Example: {% highlight php %}
click(); $I->dontSeeInPopup('Error message'); {% endhighlight %} * param string $text #### dontSeeLink Checks if page doesn't contain the link with text specified. Specify url to narrow the results. Examples: {% highlight php %} dontSeeLink('Logout'); // I suppose user is not logged in {% endhighlight %} * param $text * param null $url #### doubleClick Double clicks on link or button or any node found by CSS or XPath * param $link #### dragAndDrop Drag first element to second XPath or CSS selectors are accepted. * param $el1 * param $el2 #### executeJs Executes any JS code. * param $jsCode #### fillField Fills a text field or textarea with value. * param $field * param $value #### focus Moves focus to link or button or any node found by CSS or XPath * param $el #### grabAttribute __not documented__ #### grabTextFrom Finds and returns text contents of element. Element is searched by CSS selector, XPath or matcher by regex. Example: {% highlight php %} grabTextFrom('h1'); $heading = $I->grabTextFrom('descendant-or-self::h1'); $value = $I->grabTextFrom('~{% endhighlight %}
- param $cssOrXPathOrRegex
- return mixed
Finds and returns field and returns it's value. Searches by field name, then by CSS, then by XPath
Example:
{% highlight php %}
grabValueFrom('Name'); $name = $I->grabValueFrom('input[name=username]'); $name = $I->grabValueFrom('descendant-or-self::form/descendant::input[@name = 'username']'); ?>{% endhighlight %}
- 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:
{% highlight php %}
pressKey('#page','u'); $I->pressKey('#page','u','ctrl'); $I->pressKey('descendant-or-self::*[@id='page']','u'); ?>{% endhighlight %}
- 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
Check if current page contains the text specified. Specify the css selector to match only specific region.
Examples:
{% highlight php %}
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 {% endhighlight %} * param $text * param null $selector #### seeCheckboxIsChecked Assert if the specified checkbox is checked. Use css selector or xpath to match. Example: {% highlight php %} 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]'); {% endhighlight %} * param $checkbox #### seeElement Checks element visibility. Fails if element exists but is invisible to user. Eiter CSS or XPath can be used. * param $selector #### seeInCurrentUrl Checks that current uri contains value * param $uri #### seeInField Checks that an input field or textarea contains value. Example: {% highlight php %} 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'); ?>{% endhighlight %}
- param $field
- param $value
Checks if popup contains the $text
Example: {% highlight php %}
click('Show alert popup'); $I->seeInPopup('Error message'); {% endhighlight %} * param string $text #### seeLink Checks if there is a link with text specified. Specify url to match link with exact this url. Examples: {% highlight php %} seeLink('Logout'); // matches Logout $I->seeLink('Logout','/logout'); // matches Logout {% endhighlight %} * param $text * param null $url #### selectOption Selects an option in select tag or in radio button group. Example: {% highlight php %} selectOption('form select[name=account]', 'Premium'); $I->selectOption('form input[name=payment]', 'Monthly'); $I->selectOption('//form/select[@name=account]', 'Monthly'); ?>{% endhighlight %}
- param $select
- param $option
Switch to another frame
Example: {% highlight html %}
<iframe name="another_frame" src="http://example.com">{% endhighlight %}
{% highlight php %}
switchToIFrame("another_frame"); # switch to parent page $I->switchToIFrame(); {% endhighlight %} * param string|null $name #### switchToWindow Switch to another window Example: {% highlight html %} {% endhighlight %} {% highlight php %} click("Open window"); # switch to another window $I->switchToWindow("another_window"); # switch to parent window $I->switchToWindow(); {% endhighlight %} * param string|null $name #### uncheckOption Unticks a checkbox. Example: {% highlight php %} uncheckOption('#notify'); ?>{% endhighlight %}
- param $option
Wait for x miliseconds
- param $miliseconds
Waits for x miliseconds or until JS condition turns true.
- param $miliseconds
- param $jsCondition