Search This Blog

Showing posts with label Codeception. Show all posts
Showing posts with label Codeception. Show all posts

Wednesday, September 17, 2014

Codeception - Modules & Helpers

Modules

  1. Modules play an important role in Codeception framework and helps :  
    • The target user by giving a key to define their own categorize their modules/functionality
    • Defining Folder Structure
    • Specifying module specific helper method  
  2. Modules are php file which is always stored under <Project Home> : <Name of module.php> eg : CC_90_ActionsHelper.php
  3. Modules can be turned on/off from acceptance.suite.yml
     class_name: AcceptanceTester  
     modules:  
       enabled:   
         - WebDriver  
         - AcceptanceHelper  
         - CC_90_ActionsHelper  
       config:  
        WebDriver:  
          url: 'xxx'  
          browser: chrome  
          window_size: 1124x850  
          wait: 10  
          delay: 2  
          capabilities:  
            unexpectedAlertBehaviour: 'accept'  
    
  4. Modules are always inherited from \Codeception\Module class, hence structure looks like below:
     <?php  
     class CC_90_ActionsHelper extends \Codeception\Module{  
      ........  
     }  
    

Helpers

  1. Helpers are custom actions which are created to reuse them multiple of times in the test
  2. Helpers are always created in modules (/support
      /*  
        * Login to customercare  
        *   
        * Example: -  
        *   
        * $I->loginToCC(&I, 'AlliedBuilding', 'btbt', btbt);  
        *   
        *   
        * @param  String $customername  : Name of the Customer  
        * @param  String $userName    : User Name  
        * @param  String $password    : Password  
        *   
        */  
       public function loginToCC($I, $custName, $userName, $password){  
         $I->fillField(['xpath' => Locators::$cc_custName], $custName);  
         $I->fillField(['xpath' => Locators::$cc_userName], $userName);  
         $I->fillField(['xpath' => Locators::$cc_password], $password);  
         $I->click(['xpath' => Locators::$cc_signIn]);  
         return $this;  
       }  
    
  3. Build command is used to add the helper method to acceptancetester.php  
    Command : [php codecept.phar build]
  4. Once method added, it can be used in the tests as usual.

Tuesday, September 16, 2014

Headless Testing [Codeception+Phantomjs]

Installation

  • phantomjs can be downloaded from http://phantomjs.org/
  • Once downloaded,unzip it and update the path variable under 'Env Variables > user variables' to path of 'phantomjs.exe'. Eg : C:\Download\phantomjs-1.9.7-windows\phantomjs-1.9.7-windows










  • Check the installation from a command prompt using:
     phantomjs –version  








  • Start the ghost driver , it needs to run on the port on which selenium server is running using this command :
  •  phantomjs --webdriver=4444  
    






Configurations needed in Codeception

  • Change 'browser' parameter inside 'acceptance.suite.yml.template' to specify 'phantomjs'

Run Tests

  • Tests can be run as usual using :
     php codecept.php run <cept structure> --steps  
    
Note: When applications are browse via 'https' , Please include phantomjs commandline option of turning the ignore ssl errors ON. Use below command : 
 phantomjs –ignore-ssl-errors=true –webdriver=4444  

Tuesday, May 20, 2014

First Selenium Test-Codeception

Codeception is very nice and powerful tool for defining acceptance tests.Internally it uses Mink library to interact with browser.Whereas it can also run tests in headless browser mode as well.

To define our acceptance test we have to add tests under the respective folder(acceptance).

In order to generate our first test , following command can be fired : -

codecept generate:cept acceptance seleniumtest




It'll create the tests under acceptance folder as noticed below : -







Now if we edit the test seleniumtestCept.php, we can see the test definition structure.









It looks like plain English which  anyone can understand juts by looking at it.

Defining Selenium Test: -

In order to define selenium test and run under a browser, we would have to start the selenium server first : -

Step-1: - Start selenium server by the below command : -



Step-2 :- Define the test  as below using predefined codeception actions -



Step-3:-Configure acceptance.suite.yml with the Browser type,URL etc.



 Step-4:
If you'd like to run only your acceptance tests, you can use the following command:

codecept run acceptance

Additionally, you can see the full list of actions performed by using the --steps flag: 
 run acceptance --steps

I hope this helps:)
-----------------x--------------------------------x---------------------------------x----------------------

Configure & Intstall WebGuy-Codeception

Overview:

Codeception is an opensource BDD Framework developed in PHP.It has been mainly focused to 3 type of user : -

(1)WebGuy - Who writes Acceptance Test
(2)Test Guy- Who writes functional Test
(3)Code Guy-Who writes Unit Test

Configuration & Installation of TestGuy: -

Step-1: Download and Configure Composer

Desc.:- Composer is basically a dependancy management tool for PHP pretty similar to Maven for Java.

It is open source and can be downloaded from here : https://getcomposer.org/download/

And it can be installed following : https://getcomposer.org/doc/00-intro.md#installation-windows

Step-2:Once composer gets installed,As codeception is just a library we would need to download it and all its dependancy.

-Create an folder say : CodeTest
-Create an file -Composer.json and include the below content winthin it.

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


-Once the file has been created navigate to the same folder from command prompt



-Fire the composer command to download codeception library --> composer install


-Once it completes download of all dependency , a new folder would have been added under our home folder which would be "vendor" and it'll look something like below -



Step-3: Install bootstrap

Once we install bootstrap, it add various hierarchy where we can define our tests.

To install, navigate to the Codecept/vendor/bin folder and fire the command below : -

"codecept bootstrap"



After the bootstrap configuration a new folder "tests" would have been added under "bin" folder as "tests".



If we navigate into "tests" folder and closely look into it, we would be able to see the different kin of roles defines: -



Now we have completely installed and configured codeception, we will have to define our feature based tests under the respective folder. I hope u enjoyed :)