Search This Blog

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.

No comments:

Post a Comment