Forum Discussion

johnmclaughlin's avatar
johnmclaughlin
Contributor
14 years ago

Extracting Data and Using in a new Keytest

I am using Testcomplete to automatically key on insurance policies to an administration system. The last stage of the application is to "release" the policy. I wish to do the release at a later date and this is my problem. Each new application is given an Application Number which appears on the screen (attached). How can I extract this information and store it so i can use it to return to the application for "release". My aim is to set up a number of policies then "release" them all at the same time.

3 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    My suggestion would be to use an ODT.Data.Group Variable of type Array.  Then, when you run through your tests, "scrape" the number from the component on the page and stored it in an item in the array.



    When you go to close your application, you should then be able to iterate through your array, reading out the values, and then, once you're all done with all the values, dispose of the array.



    So, first pre-requisite would be to have the ODT object in your project.  Easy enough to add (right click on the project in the project explorer, click Add, and select New Item and then select the ODT object from the list.



    Now... while you're going to be using keyword tests for most of your stuff, I'd suggest doing the actual storage using piece of script code that you would just call in your keyword test.



    //JavaScript


    function AddApplicationToArray(ApplicationNumber)

    {

    var DataGroup = ODT.Data.Groups('Globals')

    if (DataGroup == null)

        {

        DataGroup = ODT.Data.AddGroup('Globals')

        }

    var ApplicationVariable = DataGroup.Variables('ApplicationArray')

    if (ApplicationVariable == null)

        {

        ApplicationVariable = DataGroup.AddVarOfArrayType('ApplicationArray')

        }

    ApplicationVariable.AddItem(ApplicationNumber)

        

    }




    Application numbers can then be retireved based upon the array, like ODT.Data.Globals.ApplicationVariable.Items[0] for the first item, [1] for the second, and so on.



    You can then remove the variable at the end so it's cleared out for the next run.
  • I'm not sure what an Array is and i don't want to dispose of it afterwards. What i want to do is record each Application Number in a spreadsheet along with a few other pieces of information from that application and then use this spreadsheet in a data driven loop for a new Keytest that "releases" them.  
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    An array is essentially an in memory object that stores a list of items.  Effectively, what I wrote for you above does what you need without having to create an Excel spreadsheet.



    The "dispose" was so that, next time you run the test you're not re-using Application Numbers from before.  What you would do is use the function I noted above during your run where you create the applications so that you can keep numbers in memory.  Then, during your tests where you are releasing the applications, you would use a "for" loop to loop through the array up to the item count and, each time through the loop, release the application number.



    If there is a particular requirement for persisting the Application Numbers after the test is complete, there's an article at http://smartbear.com/support/viewarticle/20878/ that documents how to write out to Excel.  Your usage of the information would still need to be either using a Data Driven operator in a keyword test or a DDT.ExcelDriver in a script test to loop through the records and execute some action for each one.