Monday, October 13, 2014

Codeception:Variables for UI Elements

As we know we can write complex tests using codeception.Think of a scenario of a login page.
We have generally 3 fields in login page.

1.User id fiels
2.Password field
3.Sign in button.

We have created a test using codeception to login and that worked fine.
But think in future if we have to login to the same website multiple times using different user ids and passwords and the credentials are changing frequently.
So if we want a solid automation script, we need to consider the use of variables in the script.


let see the following example of a login page with different credentials:


<?php

/**
 * @var AcceptanceTester
 */

$I = new AcceptanceTester($scenario);

/************************
 * Cept Data Declaration
 * **********************/

//User Credential

$FirstUname='FirstUser';
$FirstPwd='FirstPassword';
$SecondUname='SecondUser';
$SecondPwd='SecondPassword';


/**
 
 * Login to the page using First User's credential

 */

$I->click('Login');
$I->fillField('signin_username', $FirstUname);
$I->fillField('signin_password',$FirstPwd);
$I->click('signin_signin');

//Signout from page for the current user and relogin using a different user

$I->click('Login');
$I->fillField('signin_username', $SecondUname);
$I->fillField('signin_password',$SecondPwd);
$I->click('signin_signin');


In this way we can login to same page using different credentials and we can change the variables declared at top of script if required in future.

Related Posts:

  • Repopulation of database using mysql instead of db module What is DB module: The DB module is used to cleaning database before each test. So this module was added into codeception.yml. To have your database properly cleaned you should configure it to access the database. Also pro… Read More
  • Codeception Modules In Codception various modules are comes as packages initially. Some of them are Webdriver,symphony,Laravel etc. Modules allow you to choose the actions and assertions that can be performed in tests. All actions and assertion… Read More
  • Codeception Helpers Codeception has always the flexibilty to add the add the custom actions to the test suite. It just doesn't restrict to add custom actions. 'bootstrap' is the command to that codeception generates these modules. These modules… Read More
  • Codeception:Variables for UI Elements As we know we can write complex tests using codeception.Think of a scenario of a login page. We have generally 3 fields in login page. 1.User id fiels 2.Password field 3.Sign in button. We have created a test using codecep… Read More
  • Creation Of Cest Ever wanted a structure as classes for your Cepts! Then Cest format should be your choice. The biggest advantage is that it is very simple and compatibility with Cept scenarios. So if your script/test is bit lengthy and you … Read More

0 comments:

Post a Comment

Powered by Blogger.