Forum Discussion

TanyaYatskovska's avatar
9 years ago
Solved

Code Contest: Export/Importing Project Variables

Hello Community,

 

We are announcing the first Code Contest in our TestComplete Community. All of you can take part in the contest to check/improve your skills and win the main prize. I hope for fair play and serious competition :)

 

Contest Details

Create a script extension that will allow exporting/importing project variables.

 

To implement the task, you need to have basic coding skills, know how to use the TestComplete objects and be able to work with files from script.

You can use any script language to create a script extension. This is one of the advantages of using script extensions – they don’t depend on a particular script language used in a project.

 

Contest Duration

We will be waiting for your solutions till August 31. The winner will be announced shortly after that.

 

Contest Prize

The winner gets a $50 gift card.

 

Contest Storage

Once you create a ready script extension, post it as a reply to this thread. Others will be able to vote for your solution.

 

Contest Guideline

To help you create a script extension, I will specify some tips below. However, if you want to implement that task on your own – feel free to do so. You will need to post a working solution in the end.

 

Here are the steps of how this can be done:

  1. Code Creation:

You will need to declare at least two functions. You can do this in Code Editor and, then, move them to a script extension later.

* Export variables to an external storage (for example, to a file) – you will need to export their types and values via  GetVariableType and VariableByName. Here is pseudo code written by cunderw:

 

 

function outputVars() {
   var count = Project.Variables.VariableCount;
   var name, type,value;
   for(var i = 0; i < count; i++){
      name = Project.Variables.GetVariableName(i);
      value = Project.Variables.VariableByName(name);
      type = Project.Variables.GetVariableType(Project.Variables.VariableByName(name))
     //code to write to file
   }
}

 

* Import variables from the storage and add them to your project via AddVariable. Here is pseudo code written by cunderw:

 

  1. function insertVars() {
       //code to open file
      for(lines in file) {
        if(!Project.Variables.VariableExists(varNameFromFile){
          //add var and type
       }
       //set var value etc..
      }
    }
    2. Script Extension Creation:
    1. Create a script extension and move the code there
    2. Create a GUI for your script extension by using TestComplete’s User Form
  2. Adding the script extension to TestComplete’s toolbar.

You can find the detailed description of the past two steps in the Creating Actions Tutorial article.

 

Good luck and may the odds be ever in your favor!