In this post I will show you how to create global variable which can be use in any codeception test scripts file. Suppose that we have user name and password which need to be use in all test scripts for login to application. This is good practices to put these values in one place instead of passing in multiple test case.
You should see that “_bootstrap.php” files are generated in folder “acceptance”, “functional” , “unit” and at root of test folder.
You can create a variable in this files with any desire values and can be use in corresponding folders scripts.
You should see that “_bootstrap.php” files are generated in folder “acceptance”, “functional” , “unit” and at root of test folder.
You can create a variable in this files with any desire values and can be use in corresponding folders scripts.
How to create variables:
define ('UserName',
"road");
define ('SerachKey',
"RoadToAutomation");
Create a variable in “_bootstrap” file like above
How to use:
use \AcceptanceTester;
class GoogleSearchCest
{
public function _before(AcceptanceTester $I)
{
}
public function _after(AcceptanceTester $I)
{
}
// tests
public function tryToTest(AcceptanceTester $I)
{
$I->wantTo('Google
search testing keyword');
$I->amOnPage('/');
$I->fillField('q',SerachKey);
$I->click('btnG');
}
}
Run the code you should see that variables parametrize and test run successfully with same value
No comments:
Post a Comment
Leave your comments, queries, suggestion I will try to provide solution