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.

0 comments:

Post a Comment

Powered by Blogger.