| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [View Raw Code] [Original HTTPS Page] |
| layout | doc |
|---|---|
| title | Laravel4 Module - Codeception - Documentation |
For additional reference, please review the source
This module allows you to run functional tests for Laravel 4. Module is very fresh and should be improved with Laravel testing capabilities. Please try it and leave your feedbacks. If you want to maintain it - connect Codeception team.
Uses 'bootstrap/start.php' to launch.
https://github.com/Codeception/sample-l4-app
When submitting form do not use Input::all to pass to store (hope you won't do this anyway). Codeception creates internal form fields, so you get exception trying to save them.
Authenticates user for HTTP_AUTH
Set the currently logged in user for the application.
Opens the page. Requires relative uri as parameter
Example:
{% highlight php %}
amOnPage('/'); // opens /register page $I->amOnPage('/register'); ?>{% endhighlight %}
Attaches file from Codeception data directory to upload field.
Example:
{% highlight php %}
attachFile('input[@type="file"]', 'prices.xls'); ?>{% endhighlight %}
Ticks a checkbox. For radio buttons use selectOption method.
Example:
{% highlight php %}
checkOption('#agree'); ?>{% endhighlight %}
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:
{% highlight 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'); ?>{% endhighlight %}
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 %}
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 %}
Checks that current url is not equal to value. Unlike dontSeeInCurrentUrl performs a strict check.
{% highlight php %}
dontSeeCurrentUrlEquals('/'); ?>{% endhighlight %}
Checks that current url does not match a RegEx value
{% highlight php %}
dontSeeCurrentUrlMatches('~$/users/(\d+)~'); ?>{% endhighlight %}
Checks if element does not exist (or is visible) on a page, matching it by CSS or XPath
Example:
{% highlight php %}
dontSeeElement('.error'); $I->dontSeeElement('//form/input[1]'); ?>{% endhighlight %}
Checks that current uri does not contain a value
{% highlight php %}
dontSeeInCurrentUrl('/users/'); ?>{% endhighlight %}
Checks that an input field or textarea doesn't contain value. Field is matched either by label or CSS or Xpath Example:
{% highlight php %}
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'); ?>{% endhighlight %}
Checks that page title does not contain text.
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 %}
Checks if option is not selected in select field.
{% highlight php %}
dontSeeOptionIsSelected('#form input[name=payment]', 'Visa'); ?>{% endhighlight %}
Checks that record does not exist in database.
{% highlight php %}
$I->dontSeeRecord('users', array('name' => 'davert'));
{% endhighlight %}
Fills a text field or textarea with value.
Example:
{% highlight php %}
fillField("//input[@type='text']", "Hello World!"); ?>{% endhighlight %}
not documented
Takes a parameters from current URI by RegEx. If no url provided returns full URI.
{% highlight php %}
grabFromCurrentUrl('~$/user/(\d+)/~'); $uri = $I->grabFromCurrentUrl(); ?>{% endhighlight %}
Retrieves record from database
{% highlight php %}
$category = $I->grabRecord('users', array('name' => 'davert'));
{% endhighlight %}
Return an instance of a class from the IoC Container. (http://laravel.com/docs/ioc)
Example {% highlight php %}
grabService('foo'); // Will return an instance of FooBar, also works for singletons. ?>{% endhighlight %}
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 %}
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 %}
Inserts record into the database.
{% highlight php %}
haveRecord('users', array('name' => 'Davert')); ?>{% endhighlight %}
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 %}
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 %}
Checks that current url is equal to value. Unlike seeInCurrentUrl performs a strict check.
{% highlight php %}
seeCurrentUrlEquals('/'); ?>{% endhighlight %}
Checks that current url is matches a RegEx value
{% highlight php %}
seeCurrentUrlMatches('~$/users/(\d+)~'); ?>{% endhighlight %}
Checks if element exists on a page, matching it by CSS or XPath
{% highlight php %}
seeElement('.error'); $I->seeElement('//form/input[1]'); ?>{% endhighlight %}
Checks that current uri contains a value
{% highlight php %}
seeInCurrentUrl('home'); // to match: /users/1 $I->seeInCurrentUrl('/users/'); ?>{% endhighlight %}
Checks that an input field or textarea contains value. Field is matched either by label or CSS or Xpath
Example:
{% highlight php %}
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'); ?>{% endhighlight %}
Assert that the session has a given list of values.
Checks that page title contains text.
{% highlight php %}
seeInTitle('Blog - Post #1'); ?>{% endhighlight %}
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 %}
Checks if option is selected in select field.
{% highlight php %}
seeOptionIsSelected('#form input[name=payment]', 'Visa'); ?>{% endhighlight %}
Asserts that current page has 404 response status code.
Checks that record exists in database.
{% highlight php %}
$I->seeRecord('users', array('name' => 'davert'));
{% endhighlight %}
Checks that response code is equal to value provided.
Assert that Session has error messages The seeSessionHasValues cannot be used, as Message bag Object is returned by Laravel4
Useful for validation messages and generally messages array e.g. return Redirect::to('register')->withErrors($validator);
Example of Usage
{% highlight php %}
seeSessionErrorMessage(array('username'=>'Invalid Username')); ?>{% endhighlight %}
Assert that the session has errors bound.
Assert that the session has a given list of values.
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 %}
Can select multiple options if second argument is array:
{% highlight php %}
selectOption('Which OS do you use?', array('Windows','Linux')); ?>{% endhighlight %}
If your page triggers an ajax request, you can perform it manually. This action sends a GET ajax request with specified params.
See ->sendAjaxPostRequest for examples.
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.
Example:
Imagine that by clicking checkbox you trigger ajax request which updates user settings. We emulate that click by running this ajax request manually.
{% highlight php %}
sendAjaxPostRequest('/updateSettings', array('notifications' => true)); // POST $I->sendAjaxGetRequest('/updateSettings', array('notifications' => true)); // GET {% endhighlight %} * param $uri * param $params #### sendAjaxRequest 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. {% highlight php %} sendAjaxRequest('PUT', /posts/7', array('title' => 'new title'); {% endhighlight %} * param $method * param $uri * param $params #### submitForm Submits a form located on page. Specify the form by it's css or xpath selector. Fill the form fields values as array. Skipped fields will be filled by their values from page. You don't need to click the 'Submit' button afterwards. This command itself triggers the request to form's action. Examples: {% highlight php %} submitForm('#login', array('login' => 'davert', 'password' => '123456')); {% endhighlight %} For sample Sign Up form: {% highlight html %} Login:{% endhighlight %}
| Back | FazBrowse Home | New Git URL |