Codeception: Codeception is PHP testing framework in BDD stype,It is easy to setup and use, not required any dependency except php. It has three sections for testing
Following are few exceptions what you will get during execution
Exception 1: if you get below error:
Solution: Open ini file and update line “;extension= php_curl.dll” to “extension=ext/php_curl.dll”
Exception 2: If you are getting below exception:
Solution: Open ini file and update line “;extension=php_mbstring.dll” to “extension=ext/php_mbstring.dll”
Exception 3: If you are getting exception for time zone:
Solution: Open ini file and set time zone like “date.timezone = "America/New_York"”
- Acceptance Testing
- Functional Testing
- API testing
Features:
- Can be integrated with selenium Webdriver
- Supported Symphony2, Laravel4, YII, Phalcon, Zend framework integration.
- BDD style data set.
- API testing Rest, Soap, XML-RPC
- Report in HTML, XML, JSON.
- Parallel execution
Setup:
- Download PHP from http://windows.php.net/download/
- Extract in PHP folder and save in your machine like I saved “D:\Program Files\PHP”
- Setup PHP path in your system environment variable.
- Open command prompt and check php version.
5. Download Codecep.phar file from location http://codeception.com/builds as per your PHP version.
6. Save this file into your created project root directory.
7. Open command prompt and run below command.
8. You should see that “tests” folder and “codeception.yml” file generated under project directory
Script Creation:
1. To create your first test just runs below command:
php codecept.phar generate:cept
acceptance MyFirstTest
You should see that test is generated under “tests\acceptance” directory.
2. Open file “acceptance.suite.yml” and set your application url like below:
class_name: AcceptanceTester
modules:
enabled:
- PhpBrowser
- AcceptanceHelper
config:
PhpBrowser:
url: 'https://www.google.com'
3. Write your acceptance code into file “tests\acceptance\MyfirstTestCept.php” in created file like I have created google search
$I = new AcceptanceTester($scenario);
$I->wantTo('Google search testing
keyword');
$I->fillField('q','testing');
$I->click('btnG');
?>
Run Test:
Run below commands to execute test.
php codecept.phar run
For detail steps output on console run command:
php codecept.phar run acceptance
--steps
To run only acceptance test:
php codecept.phar run acceptance
To run exactly one test
php codecept.phar run acceptance MyfirstTestCept.php
Report:
To generate report in html format run command:
php codecept.phar run --html
You should see report is generated into “tests\_output” directory
Following are few exceptions what you will get during execution
Exception 1: if you get below error:
[Exception]
Codeception requires CURL extension
installed to make tests run
If you are not sure, how to install
CURL, please refer to StackOverflow
Solution: Open ini file and update line “;extension= php_curl.dll” to “extension=ext/php_curl.dll”
Exception 2: If you are getting below exception:
PHP Fatal error: Call to undefined function
Codeception\mb_strpos() in phar://E
:/Automation-WorkArea/Codespection/Codecept/codecept.phar/src/Codeception/Config
uration.php on line 305
Fatal error: Call to undefined
function Codeception\mb_strpos() in phar://E:/Aut
omation-WorkArea/Codespection/Codecept/codecept.phar/src/Codeception/Configurati
on.php on line 305
Exception 3: If you are getting exception for time zone:
GuzzleHttp\Exception\RequestException:
strtotime(): It is not safe to rely on th
e system's timezone settings. You are
*required* to use the date.timezone settin
g or the date_default_timezone_set()
function. In case you used any of those met
hods and you are still getting this
warning, you most likely misspelled the time
zone identifier. We selected the
timezone 'UTC' for now, but please set date.tim
ezone to select your timezone.
Solution: Open ini file and set time zone like “date.timezone = "America/New_York"”
Don´t word this test. Try:
ReplyDeletewantTo('Google search testing keyword');
$I->amOnPage('/');
$I->fillField('q','testing');
$I->click('btnG');
?>