Forum Discussion
Philip_Baird
11 years agoCommunity Expert
Hi, this might not be of much use but this is how we deal with Project Variables at work.
In order to provide as much flexibility as possible, except for during dev, our Projects do not contain any Project Variables, instead they are created from ini files at the discretion of the tests as they execute.
Each Project Variable is either:
1. A configuration setting
2. The name of a file which contains required data and it is the tests responsibility to process the data.
To facilitate this, we employ a standard pattern of having a setup and teardown for each test that initializes/purges Project variables as required.
This is acheived by using code similar to the following and having ini files in a common location across machines.
// Generic function for iterating through and processing an ini file
function processIniFile( fileName, optionProcessor ) {
var iniFile,
option,
optionName;
if( aqFile.Exists( fileName ) ) {
iniFile = Storages.INI( fileName );
for( var i = 0; i < iniFile.SectionCount; i++ ){
section = iniFile.GetSubSectionByIndex( i );
for( var j = 0; j < section.OptionCount; j++ ) {
optionName = section.GetOptionName( j );
option = section.GetOptionByIndex( j, "Not Specified" );
optionProcessor( optionName, option );
}
}
} else {
Log.Message( "File " + fileName + " does not exist" );
}
}
// Create Project Variables from an ini file
function initializeProjectVariables( fileName ) {
processIniFile(
fileName,
function( optionName, option ) {
if( ! Project.Variables.VariableExists( optionName ) ) {
Project.Variables.AddVariable( optionName, "String" );
} else {
Log.Warning( "Updating existing Project Variable " + optionName );
}
Project.Variables.VariableByName( optionName ) = option;
}
);
}
// Remove Project Variables for options in an ini file
function purgeProjectVariables( fileName ) {
processIniFile(
fileName,
function( optionName ) {
if( Project.Variables.VariableExists( optionName ) ) {
Project.Variables.RemoveVariable( optionName );
} else {
Log.Warning( "Could not remove Project Variable " + optionName + " as it did not exists" );
}
}
);
}
function testInitialize() {
var fileName = "C:\\Testing\\AMITestConfiguration.INI";
initializeProjectVariables( fileName );
}
function testPurge() {
var fileName = "C:\\Testing\\AMITestConfiguration.INI";
purgeProjectVariables( fileName );
}
Regards,
Phil Baird
Related Content
Recent Discussions
- 21 minutes agoSvetaG