Saturday, 26 December 2015

Project & Project Suite Variable in TestComplete

Project & Project Suite variables are special type of variables in TestComplete that can be accessed by all TestUnit (Script unit) , Keyword Test, Network Suite and Events. These are the global variable, If you want to use some variable globallyin your test, you have to declare those variable as Project/Project Suite in TestComplete. If we declare as local variable in number of tests, modification very dificult.

Let's have an example - Your test data is file paths that are specific to the computer, on which the project is opened,suppose if your test is runing on several machines (Network Suite or One another machine) , In this case it would be good if the file path is get from the computer where the test is running. You have to create a global script variable and change its value in the source code before running the test on each computer and this can be achived by Project/Project suite variable in TestComplete. Project/Project Suite variables can store their values between test run.

Project Variable : - Project variables only work for the current project. You can use them to share data between tests of various types included in your project, for instance, between scripts and keyword tests.

Project Suite Variable : - Project suite variables are similler to project variable, The only difference is that their values are shared with all projects belonging to the project suite.

1- Adding Project/Project suite variable - Select Project/Project suite from project explorer -> Right Click on it -> Go to Edit option -> Select Variables


Or Double click on Project/Project suite -> Select Variables tab

Here you can add your variable by following below step or code -  Go to Variables tab -> Right click on Temparary or Persistent variable Section -> Select New Item



Once you select "New Item" a row is added into the variables section where you can specify Variable Name, Variable Type, Variable Default Value, local Value and description.

Once you specify all the required details, your Project/Project suite variables are added. You can achived these by using below code (VBScript)

Project Suite Variable Syntax -

ProjectSuite.Variables.AddVariable "VarName","VarType"

Project Variable Syntax -

Project.Variables.AddVariable "VarName","VarType"
 
Example -

here we are adding a project/project suite variable named "DatasheetPath" and variable type is String.
 
ProjectSuite.Variables.AddVariable "DatasheetPath","String"

Project.Variables.AddVariable "DatasheetPath","String"

Similar you can add multiple variables -