Forum Discussion

MrDysprosium's avatar
MrDysprosium
Contributor
8 years ago

Just started, how would I create a variable that changes every time I run a test?

I want to create a test that runs many times, and each time the test is run the input from the test should be slightly different.

For instance, I want to create many records in my software, and the name of each record will just be "1", then "2", then "3"...

I know how to do this programmatically, but how do I tell TestComplete to run my script and use this new value, and retain the current value of the variable so that it may change again for the next loop?


EDIT: To further clarify, I want the highlighted "SetText" value to be the result of a python function that generates a unique string each time. It's not very clear on how to do that.

9 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Just to clarify, you essentially want to do a for loop through around your code where you would use the index of the for loop within the name of the data record, yes?

     

    So...do a for loop. :)


    https://support.smartbear.com/testcomplete/docs/keyword-testing/reference/statements/for-loop.html

     

    There are code analogues in keyword tests to do what you want.  So, for loops, while loops, etc., are present and available.

    As for the second part of your question, what I would do is use the "Run Script Routine" operation that runs your Python function that returns the value.  Then, in that SetText field, click the ellipses button.  In the resulting screen, in the drop down that probably currently says "Variable", change that to "Last Operation Result".  That will take the value returned from your function and put it in the SetText field.

    • MrDysprosium's avatar
      MrDysprosium
      Contributor

      So many questions. The documentation does a great job of explaining "why", but not "how".

      How do I use the "Run Script Routine" operation?
      How do I tell SmartBear that my script is Python?

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        To answer your second question first, when you created your automation project, you were prompted to select a scripting language.  If you selected Python then the assumption, even in Keyword tests, is that the syntax of everything is Python.  

        As for how to use the "Run Script Routine", drag the operation over into your keyword test and let the wizard do it's work. :)  Basically, you'll be prompted first to select the code unit and then the script routine to execute, if the script routine has parameters, you'll be prompted to provide them as values.  Honestly, it's really that simple. :)