su - worker
cd /home/worker/volume/artifact/current
mkdir tests/codeception -p; cd ./tests/codeception
codecept bootstrap
This command generates codeception.yml
global configuration file and tests folder where the test suites (unit, functional, and acceptance) stored.
https://codeception.com/install
https://codeception.com/docs/01-Introduction
codeception.yml
has preconfigured settings you can change.
https://codeception.com/docs/reference/Configuration
Suites are independent groups of tests with a common purpose. A “unit suite” for all unit tests, a “functional suite” for all functional tests, and an “acceptance suite” for all acceptance tests.
https://codeception.com/docs/02-GettingStarted
https://codeception.com/docs/01-Introduction
codecept generate:suite api API_Tester
Requires suite name and optional actor name codecept generate:suite [suite name] [actor name]
.
Creates Helper ../_support/Helper/Api.php
, Actor ../_support/API_Tester.php
and Suite config api.suite.yml
.
https://codeception.com/docs/02-GettingStarted#Actors
actor: API_Tester
lint: true
modules:
enabled:
- \Helper\Api
- REST:
url: http://localhost
depends: PhpBrowser
part: Json
https://codeception.com/docs/06-ModulesAndHelpers#Standard-Modules
https://codeception.com/docs/modules/REST
codecept generate:cest api baseUrl
Codeception has its own testing format called Cest (Codecept + Test). To start writing a test we need to create a new Cest file. We can do that by running the following command: codecept generate:cest [suite name] [class name]
creates api/baseUrlCest.php
https://codeception.com/docs/02-GettingStarted#Generators
<?php
class baseUrlCest
{
public function _before(API_Tester $I)
{
}
// tests
public function tryToTest(API_Tester $I)
{
$I -> sendGET ( '/' );
$I -> seeResponseCodeIs ( \Codeception\Util\HttpCode::OK );
$I -> haveHttpHeader ( 'Content-Type', 'application/json' );
$I -> haveHttpHeader ( 'Content-Type', 'charset=UTF-8' );
$I -> seeResponseIsJson ();
$I -> seeResponseMatchesJsonType ( [ 'status' => 'string', 'code' => 'integer' ] );
$I -> seeResponseJsonMatchesJsonPath ( '$.code' );
$I -> seeResponseJsonMatchesJsonPath ( '$.status' );
$I -> seeResponseContainsJson ( [ 'status' => 'ok', 'code' => 200 ] );
}
}
codecept run --debug -vvv
To see all the available options, run the following command:
codecept help run
api.suite.yml
api/baseUrlCest.php
https://codeception.com/docs/modules/REST
mkdir test && cd test
Download Selenium Standalone Server
https://docs.seleniumhq.org/download/
curl -sSL http://selenium-release.storage.googleapis.com/3.141/selenium-server-standalone-3.141.59.jar --output selenium-server-standalone-3.141.59.jar
Download ChromeDriver - WebDriver for Chrome
https://sites.google.com/a/chromium.org/chromedriver/downloads
curl -sSL https://chromedriver.storage.googleapis.com/76.0.3809.68/chromedriver_win32.zip --output chromedriver_win32.zip
unzip chromedriver_win32.zip
Download codeception
curl -sSL http://codeception.com/codecept.phar --output codecept.phar
Initialize testing environment
php codecept.phar bootstrap
Create first acceptance test
php codecept.phar generate:cest acceptance First
Set the browser and the url
nano .\tests\acceptance.suite.yml
# Codeception Test Suite Configuration
#
# Suite for acceptance tests.
# Perform tests in browser using the WebDriver or PhpBrowser.
# If you need both WebDriver and PHPBrowser tests - create a separate suite.
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: 'https://gist.github.com/szabacsik/91c514dde683a5f18f95cea8bceaf74f'
browser: chrome
- \Helper\Acceptance
step_decorators: ~
Create tests
nano .\tests\acceptance\FirstCest.php
<?php
class FirstCest
{
public function _before(AcceptanceTester $I)
{
}
// tests
public function tryToTest(AcceptanceTester $I)
{
$I->amOnPage('/');
$I->see('Codeception quickstart guide');
$I->click('Back to GitHub');
$I->see('Repositories');
}
}
Launch the Selenium Server
java -Dwebdriver.gecko.driver=chromedriver.exe -jar selenium-server-standalone-3.141.59.jar
Run the test
php codecept.phar run --steps
https://codeception.com/docs/03-AcceptanceTests