Ask a Question

Code Contest: Export/Importing Project Variables

SOLVED
TanyaYatskovska
SmartBear Alumni (Retired)

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!

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager



51 REPLIES 51
Marsha_R
Champion Level 2

Are these going to be a straight import export or is there a merge happening too?
StevenN
Contributor

Attached an update after receiving the feedback:

 

1. Now importing from and exporting to an XML file so there should be no issues with commas. 

2. You can already select a folder to export to by double clicking the text box.

3. You can now select which variables you want to export. I used a listbox rather than checkboxes as its better for selecting multiple variables:

 

ExportUpdate.JPG

 

Any more challenges?

 

Thanks,

Steven

TanyaYatskovska
SmartBear Alumni (Retired)


@tristaanogre wrote:

Challenge accepted.


Hi @tristaanogre, you have only several days left to prepare your version of the extension. We are still waiting for it 🙂

 

@StevenN@cunderw, we have reviewed your extensions, and our team has several comments in this regard - I'll send them to you via PM.

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager



nwuser_testcomp
Occasional Contributor

Hi Tanya,

 

Though much days not left for the contest and already people have submitted their versions, still wanted to give it a try. 🙂

I am facing an error while importing the extension--it gives error invalid image size "export.bmp". Image size is 1 kb.

 

Please help in this regard.

 

TIA!!

If it's the toolbar image then it will be referring to the image size in pixels, it needs to be 16 x 16. 

TanyaYatskovska
SmartBear Alumni (Retired)

Hi Nwuser_testcomp,

 

 

You are welcome to take part in the contest 🙂

Does @StevenN's suggestion help you?

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager



Hi Tanya,

 

Yes, the solution provided by Steven worked.

@StevenN,thanks!!

 

Will post my solution probably by today.

 

Cheers!!

Have made all the suggested updates. Hopefully there are no more since the deadline is approaching!

 

Version 1.2 attached. 

 

Thanks

TanyaYatskovska
SmartBear Alumni (Retired)

Hello Community,

 

One day left before we close this contest. If you want to post your version of the extension, hurry up!

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager



New versions with minor UI tweaks and bug fixes.


Thanks,
Carson

Click the Accept as Solution button if my answer has helped
cancel
Showing results for 
Search instead for 
Did you mean: