Forum Discussion

tgeesa's avatar
tgeesa
Occasional Contributor
13 years ago

Automated Text For Forms

First off, I am new so I apologize if this comes up a lot.  I've read most of the user guide and watched a lot of the videos (which are great, btw) but still in a bind here.



I am doing both web and Windows program validation. We have an online support system, where engineers handle tickets via a Windows program.  Tickets are submitted online by our users.  I am developing test scripts and need some help.  I need to generate random data that is inserted into an online form then submitted.  For example, a random variable will generate a random description of a problem before submission.  Once submitted, I will validate that the "typed" random info matches what the online/program ticket profile displays.  I do not want to use the same Ticket Title and Problem Description for each ticket generated, this need for random variable.



I am sure this will involve the Data Generator.  I played around with it and thought I had a decent custom script saved as a variable, but it won't insert as text (using both keys and textContent (Set) function).  It just ends up blank...I also tried saving the variable as the table option but no luck either.  What am I missing here?



If someone could walk me through this or point me in the right direction I would greatly appreciate it.



Sincerely,

Tyler

6 Replies

  • ravisangam's avatar
    ravisangam
    Occasional Contributor
    What you want to say is, your script is not inserting the text(stored in a variable) in a text filed in a web page.. Am i right?
  • tgeesa's avatar
    tgeesa
    Occasional Contributor
    Sort of.  It could also be a joint problem of me not using the Data Generator correctly (amazing, I know...) as well.  I'll clairfy:



    I want to use the data generator (custom string) to create random text variables that can be subbed into a problem description.  When the description is submitted for that problem, I will check it from a different view to make sure it was submitted properly  and displayed in the right place.



    I can't have the same description over and over for each problem ticket submitted;  if the description doesn't change, then the variable won't change from problem to problem (with multiple tests).   Anyway, I am mainly using the UI of TestComplete, no custom scripting.



    I am confident this is something simple that I am missing.  Thank you for looking into this for me and I appreciate any support!
  • tgeesa's avatar
    tgeesa
    Occasional Contributor
    Ok, I have an update.  So, I have figured out Data Generator and have a table of values that were automatically generated.



    My question is now, how can I assign a random value from a column in the Data Generator table to a field on our web application?
  • tgeesa's avatar
    tgeesa
    Occasional Contributor
    Has anyone had a similar problem as above that could help me out?
  • tgeesa's avatar
    tgeesa
    Occasional Contributor
    I am very close!  I need a little more input then I think we can figure this out. 



    If you look at the picture, I am assigning a SetText property to a field on our website.  I am setting a value to the SetText property of " Project.Variables.GeneratedDescriptions.Item("Description", Random(1000)) " , which is an entry from my table GeneratedDescriptions.



    This generates blank text.  The key lies in the Row Index (I have Random(1000)).  If I remove the Random function and add an integer, it will work fine and populate the field as I need to. 



    How can I randomize the Row Index value in this case??



    Thanks you to everyone for your time and support.

  • tgeesa's avatar
    tgeesa
    Occasional Contributor

    Sorry for the swarm of posts but I figured it out.



    Hopefully this solution can help someone else down the road trying to do what I am doing.



    The solution of my problem was to use VBScript to randomly generate a integer. The script is:



    ==============

    Public Sub RandomVarGen


    Randomize

    P
    roject.Variables.rand = CInt(Int((1000 - 1 + 1) * Rnd() + 1))


    End Sub

    =============



    Changing the underlined  1000 to X, you can randomly generate an Integer X and assign it to the variable rand.



    From here, I can assign my RowIndex for Table.Item to Project.Variables.rand and have a randomly generated RowIndex. So:



    For those looking to randomly assign a value to a field:



    1) Use the Data Generator to generate a table of strings that can be assigned to a field.  Generate as many as needed.

    2) Create a variable to store an integer

    3) Create the script above

    4) Before each random field, run the script

    5) Use Project.Variables.[YourTableName].Item("[YourColumnName]", Project.Variables.[RandomVariableIntegerName]) as a code expression, assigned to the text property.

    6) Enjoy.



    Phew.