2014-05-17

How to enable/disable modules in Codeception?

 In this article, we are going to see how to enable different modules in codeception.

As we know codeception has different modules like selenium, selenium2, webdriver, PHP browser, facebook, Symfony1 etc, so when we need those, we have to activate.
Then, why we need those?. Actually these modules increases the functionality inside of Guy classes of codeception. That means, more type of function when we need, we need to active associate modules. Some modules are socially used of integration, running tests, API tests etc.

Example : if we need to apply Wait in out test case, we can not use PhpBrowser module, we have to use webdriver/selenium2/selenium which contains wait(along with different conditional wait)
Enabling a Module :
Step 1 : Include the module in configuration YML file :  As we know we have
acceptance.suite.yml , for acceptance test configuration
functional.suite.yml , for functional test configuration and
unit.suite.yml for unit test configuration.
In every YML, we will see module enable area where we can enable module by writing the module name (in Image , it is for acceptance test suit )
image

We have to remind that we need to provide configuration for specific module also. Like if we are activating selenium
enabled:
        - Selenium2
        - WebHelper
    config:
        Selenium2:
            url: 'http://google.com
            browser: firefox
            host : localhost
            port : 4444
            delay : 2000

   
Here is the full list of available modules.

image

But Before enabling module, you should read why you need the modules. Some modules are needed for better way of test execution, some are for framework specific testing and integration,  and some are for different type of testing.

Step 2 : Build the full test suit : From Command Line
php codecept.phar build

or, if you are using composer
<path to codecept>/codecept build

Disabling :
And, for deactivation , just comment it out of the module name and build the test suit again.(it is better you delete the name, but commenting is faster way) . Example : in here PhpBrowser module will be disabled
enabled:
        #- PhpBrowser
        - Selenium2
        - WebHelper



Example for enabling modules for acceptance testing (in acceptance.suite.yml  file)
1. Enabling Selenium2 module
enabled:
        - Selenium2
        - WebHelper
    config:
        Selenium2:
            url: 'http://localhost/myapp/'
            browser: firefox
            host : localhost
            port : 4444
            delay : 2000

2. Enabling PHPBrowser module
enabled:
        - PhpBrowser
        - WebHelper
    config:
        PhpBrowser:
            url: 'http://localhost/myapp/'
3. Enabling Custom module
enabled:
- YourModuleName
- WebHelper
config:
YourModuleName:
url: 'http://localhost/myapp/'

<or any extra parameter that you want>

4. Enabling Webdriver module
enabled:
    - WebDriver
   config:
      WebDriver:
         url: 'http://localhost/'
         browser: firefox
         wait: 10
         capabilities:
             unexpectedAlertBehaviour: 'accept'

If we want to active Phalcon1 module for functional test suit, it will be like this in functional.suite.yml
enabled:
    - FileSystem
    - TestHelper
    - Phalcon1
    config:
        Phalcon1
            bootstrap: 'app/config/bootstrap.php'
            cleanup: true
            savepoints: true

And , after editing the any YML file , you must build . If you do not build , it will effect on execution only but you will not get benefit for writing test case with extra functionality
Note : Among webdriver, selenium, selenium2, webdriver is latest and having most options to work with. I mainly work with webdriver module for acceptance testing.
Thanks …:)

2014-05-16

How to create PHPUnit Test Case in Codeception?

In this article we are going to see very simple command to generate PHPUnit test case in CodeCeption.
As we know, codeception build on PHP Unit, so it support all type of PHP Unit test case. That means, the test case will contain setup and teardown method for test initialization and closure functions.
And, as it is a PHP Unit format, so there will not be any Guy initialization. Just raw PHP Unit format test steps can be executed. Yes, we can use Guy Class, but should not be included as we have different format for those Guy class based test cases.
Beside, those Guy Class based test cases needs two time compilation, but PHP Unti test case need only single time compilation.
Like as other format, PHPUnit type test case In needs to use Test as post fix of a test case which is understood by codeception. That means, if our test case name is SugnUp, so if we are writing PHPUnit type test case, then it will be named as SignUpTest.php.
What is PHP Unit Format :
Like as other unit test case, PHP Unit will also have setup/tear down. Here is sample PHP Unit test case structure :
   1:  <?php
   2:  class SignUpTest extends \PHPUnit_Framework_TestCase
   3:  {
   4:      protected function setUp()
   5:      {
   6:          // Initialization methods
   7:      }
   8:      protected function tearDown()
   9:      {
  10:          //Closure activities/ methods
  11:      }
  12:      // tests
  13:      public function testMe()
  14:      {
  15:      }
  16:  }


So, now lets see the command. When we need to generate a PHP format format test case:

php codecept.phar generate:phpunit <suitename> <testname>
[if you use composer, then : <path to codecept>/codecept generate:phpunit <suitename> <testname> ]

For example, if we want to generate an Acceptance test case named as SignUp in phpunit format , then
php codecept.phar generate:phpunit acceptance SignUp

image

We can see a file generated SignUpTest.php in the tests/acceptance/ folder and it will follow the configuration of acceptance.suite.yml

So, we can generate phpunit format test case and we can ready to write codes.

Note : Usually, we create PHP Unit test cases for Unit Testing, not acceptance testing. And, php unit test is more familiar to developer rather than traditional tester or BDD testers.

Thanks…:)







What is Cest Test Case format in Codeception? How to create Cest Test Case?

In this article we are going to see How can we create Cest test case in codeception?

As we know , codeception has 3 type of tests, we have to define what type of test we are going to build.

What is Cest format ?
This actually traditional PHPUnit/Junit format. It is better for developer or unit testers to read. Even, personally I like this type of test case as I am habituated in writing Unit Tests cases. We can group test steps, having a private function as common test steps. This is helpful when you have long test steps.

When we need to create PHPUnit type test case In codeception, we need to use Cest as post fix of a test which is understand by codeception command. That means, if our test case name is SugnUp, so if we are writing BDD type test case, then it will be named as SignUpCest.php.

Cest Format :
This type of test cases takes the Guy ( either WebGuy/ TestGuy/ TestGuy) class as parameter inside of a test method.

Like :
   1:  <?php
   2:  use \WebGuy; 
   3:  class SignUpCest
   4:  {
   5:      public function _before()
   6:      {
   7:          //similar to setup/initial of phpunit or Junit 
   8:      }
   9:      public function _after()
  10:      {
  11:          //similar to teardown/closure of phpunit/junit 
  12:      }
  13:      // tests
  14:      public function tryToTest(WebGuy $I) {
  15:          $I->wantTo("Test Registration Page");
  16:          $I->amOnPage('/');
  17:      }
  18:  } 



So, now lets move on to command. When we need to generate a Cest format Acceptance test case(acceptance is a type of test suit) :
php codecept.phar generate:cest <suitename> <testname>

[if you use composer, then : <path to codecept>/codecept generate:cest <suitename> <testname> ]

For example, if we want to generate an Acceptance test case named as SignUp in cest format , then

php codecept.phar generate:cest acceptance SignUp


image


We can see a file generated SignUpCest.php in the tests/acceptance/ folder and it will follow the configuration of acceptance.suite.yml
So, we can generate cest format test case and we can ready to write codes.

Note : It is more of developer friendly test case format, some time feels complex in reading but it eliminates repetitive test steps.

Thanks…:)







What is Cept format test case in Codeception? How to create Cept Test cases?

In this article we are going to see How can we create Cept test case in codeception?
As we know , codeception has 3 type of tests, we have to define what type of test we are going to build.
So, what is Cept format ?
In codeception, we use BDD type test steps to write test case. What is BDD type? BDD refers to Behavior Driven Development. BDD type test first introduced in Gherkin with Cucumber. But in here, we will write similar test cases so, we are referring that as BDD type test case.
In codeception, when we need to declare BDD type test case, we need to use Cept as post fix of a test which is understand by codeception command. That means, if our test case name is SugnUp, so if we are writing BDD type test case, then it will be named as SignUpCept.php.

Cept Format :
This type of test case start with Guy ( either WebGuy/ TestGuy/ TestGuy).
Like :
$I = new WebGuy($scenario);
$I->wantTo('travelling through site');
$I->amOnPage('/”);

So, now lets move on to command. When we need to generate a Cept format Acceptance test case(acceptance is a type of test suit) :

php codecept.phar generate:cept <suitename> <testname>

[if you use composer, then : <path to codecept>/codecept generate:cept <suitename> <testname> ]

For example, if we want to generate an Acceptance test case named as SignUp in cept format , then

php codecept.phar generate:cept acceptance SignUp 

image

Then,  a file will be create SignUpCept.php in the tests/acceptance/ folder and it will follow the configuration of acceptance.suite.yml

So, we can generate cept format test case and we can ready to write codes.

Thanks…:)

2014-04-24

How to initiate CodeCeption Test Suite?

In this article we are going to see commands on how to start CodeCeption Test by initiating Test Suit. In this part we will see
A. How to install codeception? and
B. How to generate test suite ? in Two ways.

As we know, in codeception test, a Test Suite will contain, Acceptance Test case, Functional Test Case and Unit Test Case. So, when we initiate the suite, a folder structure will be generated where these there type of test will be there. I will make a separate post on what are those folder structure.

I am using PHPstorm as IDE. We must have PHP installed and set in environment path(see this post)
So, We can generate in 2 ways.

1. Using codecept.phar : (If we download this phar and then try to make the suit) : (download link)

a. Keep the downloaded codecept.phar in root of the project
b. Open Command Line and go to the root of the project
c. Write Command : php codecept.phar bootstrap
image

We will see a new folder inside of the project root tests and a configuration settings yml file codeception.yml
So, we have created the test suite for codeception test.

2. Using composer package manager: Install composer and keep composer in path variable(you can use my this post)

a. Go to project Root folder and create a composer.json file(I use empty text file and rename). This is actually composer package definition file. We will add our codeception package here.
b. open that composer.json file with text editor and add following in this file
{
    "require": {
        "codeception/codeception": "*"
    }
}
image
c. Open command prompt and go to Root of the project.
image
d. Write Command (for updating package, this will install codeception) :  composer update
We will see a folder named vendor. It contains codeception executable along with all necessary packages(from method 1, our codecept.phar contains all in zipped format)
image
e. From command prompt write and run the command : 
For Windows .\vendor\bin\codecept bootstrap
For Linux : ./vendor/bin/codecept bootstrap

image
This will do the the same thing like as previous method. It will create tests folder that contain three type of tests along with codeception.yml.
 So, test suit created. Now we are ready for writing test cases.

Thanks …:) 

2014-04-12

How to install GIT in Windows

In this article, we are going to learn about how to install GIT system in windows. Specifically Git and GitHub Client. The main goal is to make a software development environment with GIT.

As we know, GIT is a file management system with version controlling. We will use git to manage our developed source files. And, as Git maintain repository(public free, private paid), we will use them. I will make separate posts for GIT architecture and Git Commands.

So, For installing GIT System( lets call is system because it consists of more than one software). we need to download these two installers.

A. Git Environment Installer : We need that to support git commands in the system . Use latest build. I will use 1.9
B. Git- Hub windows client : We will use the GUI to manage out repository(folder in git hub & Local)
And, dont’ forget to have a account in github.com. Its free. Now, lets get started with following steps.

Step 1.
Run Git-1.9.0-preview20140217.exe installer in windows( I am using windows 7x64). Follow the full process of installation. In the process you have to take care of following things.

a. Select the advance context menu
image
b.  I like to use Windows Command Prompt rather than others
image

c. I prefer windows style for checking & commit.
image

d. Though the application will include in the path but make sure that you have this in your path variable.
image

Please check that you have installed Git. To do that, open command prompt and type git –version
And you will see git version number

image

We will get Git-Bash and Git Gui in program files. Git Gui is gui control of git command. We can create SSH key , repository using GUI also.  We will use Git hub client to do that.
So, we have successfully Installed Git in the system. Now, it is time to install Git Hub client.

Step 2.
Run Git hub windows client (GitHubSetup.exe). And follow steps that required to complete setup.

a. Log in with exist username /password or create a new account in GitHub.
image

b, After log in, We will see that our Windows Client has already add a SSH key with PC Name. If we go to this link with our account , we see a new entry. I will provide another post for how to create and use custom SSH key with key generation tool.

image

c. Now, we have define the Local directory where our repository will be downloaded. To do that,image

we have to go to Tools –> Option, Then we get the default location and PowerShell as default shell. This part is fully optional, I like Git Bash, so I use GitBash(some time I use Cmd also).
image
Now, press Update and we have completed the Github Windows Client setup.
We can Get our repositories from left panel of client and select the project/repository and click Clone. (actually cloning the repository)
image image

I will provide a separate blog for Git Architecture, Terms as well as Commands. 

Note : We may use TortoiseGIT which is very handy. If you are too much familiar with TortoiseSVN, I would recommend to use TortoiseGIT.

Thanks.. :)

2014-03-14

What is composer? How to install composer in windows?

In this article we are going know about Composer and how to use composer. I am writing this because we will need composer for installing dependency packages for Codeception.

What is Composer? 
Composer is a PHP dependency manager. You may find similar to Maven for java. The main difference is , Maven use XML where Composer use JSON file to write dependencies. And, in Maven we can manage the package but composer deals with framework/libraries.

Composer finds out specific version of a package needs to be installed and install it with its dependent packages.

Requirements : 
Composer needs minimum PHP 5.3.2.
PC should have cUrl with PHP installed(not only for composer, other tools also)

How to install ?
Step 1 : There are several ways to download, but as I use Windows, I download this and install in windows. 
Step 2 : Set installed folder location (C:\ProgramData\ComposerSetup\bin) in system's path variable.( get help from this post) 

How to Declare Dependencies? 
Declaring composer is very simple. In the project root, create a file composer.json . Edit that json file with text editor start like this .
{
"require" : {

                   }
{

Then we add our dependency packages along with version number in the require braces. Ex: for installing codeception, we have to write like this
{
    "require": {
        "codeception/codeception": "*"
    }
}

 
To write package, we have to follow JSON way. Like "Vendor Name/Package Name" : "Version Number".  In version number ,
* = any version,
1.3.*=  any version start with 1.3.

And , to install that dependencies, we need write this in command line
cd <project folder where composer.json is present>
composer update


Note : Here we have manually added composer.json. If we use composer init in command prompt, we will get a wizard in command line to create composer.json file with specific package. 
 
 
We can use Auto loading(before launching application)  with composer

When we use? 
1. When we have a project which is dependent on a number of Libraries
2. Some of those libraries are dependent on other libraries.
3. We might have our own custom dependent libraries


To get more detail, you may read this PDF.

Thanks..:)