-
Notifications
You must be signed in to change notification settings - Fork 49
Acceptance Tests
JP Barbosa edited this page Mar 14, 2016
·
4 revisions
nano tests/acceptance.suite.yml
class_name: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://localhost:8000
browser: 'firefox'
- \Helper\Acceptance
nano tests/acceptance/_bootstrap.php
<?php
// Here you can initialize variables that will be available to your tests
require 'bootstrap/autoload.php';
$app = require 'bootstrap/app.php';
$app->loadEnvironmentFrom('.env.testing');
$app->instance('request', new \Illuminate\Http\Request);
brew install selenium-server-standalone
nano tests/_support/AcceptanceTester.php
class AcceptanceTester extends \Codeception\Actor
{
use _generated\AcceptanceTesterActions;
public function haveAuthor()
{
return factory(App\Author::class)->create();
}
public function haveArticle()
{
return factory(App\Article::class)->create();
}
}
vendor/bin/codecept generate:cest acceptance Article
nano tests/acceptance/ArticleCest.php
<?php
use \Faker\Factory;
class ArticleCest
{
public function _before(AcceptanceTester $I)
{
Artisan::call('db:truncate');
$I->amOnPage('/articles');
}
public function _after(AcceptanceTester $I)
{
}
//tests
public function createAnValidArticle(AcceptanceTester $I)
{
$attributes = [
'title' => 'Article Title',
'content' => 'The new text!'
];
$this->createAnArticle($I, $attributes);
$I->waitForText('Article was stored with success', 10, '#content .alert-info');
$I->see($attributes['title'], 'a');
}
public function createAnInvalidArticle(AcceptanceTester $I)
{
$attributes = [
'title' => '12',
'content' => ''
];
$this->createAnArticle($I, $attributes);
$I->waitForText('The title must be at least 3 characters.', 10, '#modal .alert-danger');
$I->amOnPage('/articles');
$I->dontSee($attributes['title'], 'a');
}
public function editAnArticleWithValidAttributes(AcceptanceTester $I)
{
$attributes = [
'title' => Factory::create()->sentence($nbWords = 6),
'content' => 'The updated text!'
];
$this->editAnArticle($I, $attributes);
$I->waitForText('Article was updated with success', 10, '#content .alert-info');
$I->see($attributes['title'], 'a');
}
public function editAnArticleWithInvalidAttributes(AcceptanceTester $I)
{
$attributes = [
'title' => 'Invalid article',
'content' => ''
];
$this->editAnArticle($I, $attributes);
$I->waitForText('The content field is required.', 10, '#content .alert-danger');
$I->amOnPage('/articles');
$I->dontSee($attributes['title'], 'a');
}
private function createAnArticle(AcceptanceTester $I, $attributes)
{
$I->haveAuthor();
$I->click('New Article');
$this->submitTheForm($I, $attributes);
}
private function editAnArticle(AcceptanceTester $I, $attributes)
{
$I->haveAuthor();
$I->haveArticle();
$I->amOnPage('/articles');
$I->click('[href*=edit]');
$this->submitTheForm($I, $attributes);
}
private function submitTheForm(AcceptanceTester $I, $attributes)
{
$I->waitForElement('#articles-form', 10);
$I->fillField('#articles-form #title', $attributes['title']);
$I->fillField('#articles-form #content', $attributes['content']);
$I->click('#articles-form .btn-primary');
}
}
redis-server
php artisan serve --env=testing
selenium-server
vendor/bin/codecept run acceptance
Codeception PHP Testing Framework v2.1.1
Powered by PHPUnit 4.7.7 by Sebastian Bergmann and contributors.
Acceptance Tests (4) --------------------------------------------------------------------------------------------------------------
Create an valid article (ArticleCest::createAnValidArticle) Ok
Create an invalid article (ArticleCest::createAnInvalidArticle) Ok
Edit an article with valid attributes (ArticleCest::editAnArticleWithValidAttributes) Ok
Edit an article with invalid attributes (ArticleCest::editAnArticleWithInvalidAttributes) Ok
-----------------------------------------------------------------------------------------------------------------------------------
Time: 11.43 seconds, Memory: 35.25Mb
OK (4 tests, 4 assertions)
vendor/bin/codecept run
...
OK (10 tests, 10 assertions)
git add .
git commit -m "Add acceptance tests with Selenium"
Next step: Continuous Integration
- Setup
- Basic CRUD
- Validation
- Views
- Association
- Association Controller
- Association Views
- Basic Template
- Bootstrap
- Bootstrap CRUD
- Alerts
- Welcome Page
- Ajax CRUD
- Send Email
- Send Email Views
- Jobs Queue
- Captcha
- Async External Content
- Cached External Content
- Tests Setup
- Functional Tests
- Acceptance Tests
- Continuous Integration
- Deploy with Heroku
- Deploy with Forge
- Update README