Using a script to add/remove variable
Looking for suggestions on the best way to handle this.
I have an excel file I want to set as a ProjectSuite variable but the path to the local file will be different for different team members so I wanted to set the file as a variable using the Project.ConfigPath property.
I have this script which adds the variable:
function AddVariable() {
var path = Project.ConfigPath + "WorksheetName.xlsx";
ProjectSuite.Variables.AddVariable("Translations", "String");
ProjectSuite.Variables.Translations = path;
}
But once added, the script will fail when run again so I have this script which removes the variable:
function DeleteVariable() {
ProjectSuite.Variables.RemoveVariable("Translations");
}
My question is regarding how to implement the scripts in the execution plan/suite.
Should I just run the AddVariable script at the beginning of the execution plan and then the Delete at the end? What if I don't run from the execution plan but from an individual test or subfolder? Then it would fail.
Just looking for suggestions the best approach here- thanks
If for whatever reason there's a failure, it may not call DeleteVariable(). So the variable may not get deleted.
If it's the same file that's being accessed by different teams. Why not just include the file within the project and use the Project.Path property
var ExcelPath = Project.Path + "\\WorksheetName.xlsx";