Monday, September 22, 2014

Codeception:At once how to run tests with WebDriver and PHPBrowser

we can  run tests with webdriver and PHPBrowser at once by setting the environment.
 
The configurations can be achieved by modifying acceptance suite.yml

The configuration can be defined as follows:

class_name: AcceptanceTester
modules:
    enabled:
        - PhpBrowser
        - AcceptanceHelper
    config:
        PhpBrowser:
            url: 'http://your app url'
env:
    browser:
        modules:
             enabled: [WebDriver, AcceptanceHelper]
             config:
                 WebDriver:
                     url: 'http://your app url'
                     browser: chrome

Sunday, September 14, 2014

Installation and Configuration of Codeception with Composer

Installation and Configuration of Codeception with Composer:

What is Composer: Basically composer is dependency manager for php.If you have ever worked with PHP you must have got the feeling that for some of the common tasks you need to look for the dependencies for various frameworks like zend, laravel or symphony etc.
This is where Composer comes into play.
It will manage all the dependencies required for different frameworks.
Composer will pull all the required stuffs(libraries,dependencies) and put them all in a common place.


1. Install composer to your projects root folder.
You can download the composer here.

2. Then we need to download all the codeception libraries and dependencies.

3. So create a new test folder say MyFirstTest and within this folder create a new json file called Composer.json.
Include the below lines od code within the Composer.json

{
"require-dev": {
"codeception/codeception": "*"
}
}


4. Now navigate to the MyFirstTest test folderand fire the below command.

composer install

You will notice a new folder called 'vendor' is added within our test folder.

5. Now to initialize our testing environment we need to install bootstrap.
Simply navigate to the path Codecept/vendor/bin and fire the below command.

codecept bootstrap

6. A new folder called tests should be added under bin folder after bootstrap installation.

7. Navigate to tests folder and you will see all unit,functional and acceptance folder has been created to define our tests.

Now we are ready to define our first acceptance test.

I have already discussed in my previous post. Please find it here.

Installation and Configuration of Codeception with PHAR file

Installation and Configuration of Codeception with PHAR file:

Codeception is basically a PHP testing framework to perform unit,functional and acceptance types of testings.It's installation is pretty simple and only requires minimal steps. PHP needs to be installed on the machine where we need to test our web application.

PHP Dependencies: Codeception 2.0 and higher requires PHP 5.4 installed. Download latest version of Codeception 1.8.x if you run PHP 5.3
We can install PHP in our system by XAMP or WAMP.


Lets start installing codeception in our system in order to run our first acceptance test.

1. We need to download the codeception PHAR file and we need to put it under root of our web             application.
    We can also download it from console.simply fire the below command in console.
    wget http://codeception.com/codecept.phar
2. Then we need to install the PHAR file.
     In console navigate to the directory we have kept the PHAR file and fire the below command:
    php codecept.phar bootstrap
   This will create a tests directory which will contain all type unit, functional and acceptance tests          and codeception.yml file.
3. Let's go ahead and create our first Acceptance test.To generate our first acceptance test simply fire the below command in console:
   php codecept.phar generate:cept acceptance Test
  Cept: cept are generally codeception scenarios.
4. Now is the time to write our first acceptance test.
  Suppose we need to test that we are currently in App's home page.
  So we need to write the test like below format:

 <?php
$I = new AcceptanceTester($scenario);
$I->wantTo('ensure that frontpage works');
$I->amOnPage('/');
$I->see('Home');
?>

5. Now time to configure our Acceptance test
Please make sure your local dev server is running.
In acceptance suite.yml file put the web app url.

class_name: AcceptanceGuy
modules:
enabled: [PhpBrowser, AcceptanceHelper]
config:
PhpBrowser:
url: '{YOUR WEB APP'S URL}'

6. Now time for running our first acceptance test.Just execute the run command

php codecept.phar run

This command will execute test cept file with phpbrowser.
If you have did everything correct and your web app has a home page then you will see your test as passed in following format in console.

Suite acceptance started 
Trying to ensure that frontpage works (WelcomeCept.php) - Ok
Suite functional started
Suite unit started
Time: 1 second, Memory: 7.00Mb
OK (1 test, 1 assertions)





Powered by Blogger.