Forum Discussion

judyh's avatar
judyh
Occasional Contributor
7 years ago
Solved

I am using a CSV for a Data-Driven loop but it's not working with a numeric option list

I'm testing a web application and I've created a csv for my Data-Driven loop. It was working great until I tried to populate a numeric option list (a list of about 60 four digit branch numbers).  Instead of using the value from the csv to set the option list text, it is attempting to set the option list index. As a result it throws an index out of bounds error.

 

For example: if the branch number in the csv is 1500, rather than selecting 1500 from the option list values, it tries to set the index to 1500. This happens in both IE and Chrome.  I haven't tested Firefox yet, but I suspect it will do the same thing.

 

If I use a variable, parameter or a constant rather than using the csv, it selects the numeric value. It only fails when loading data from a csv.

 

Any ideas how to get around this?

 

Thanks,

Judy

  • Hi Judy,

     

    You did not mention how you are trying to set the value to the options list, but some methods provided by TestComplete can accept both a string and an integer as parameters. And if the integer is provided as a parameter then the method selects an item by the index. This is documented in the relevant help topics.

    So I would suggest to convert the parameter to string (e.g. using the aqConvert.VarToStr()) and check if it helps.

    Alternatively, you may explicitly provide a string parameter (e.g. like .<Method>('"' + aqConvert.VarToStr(<parameter>) + "'") )

  • Ah, right... because it's not being called as a "table data" mode, you need to call it a bit differently...

     

    try.  

     

    aqConvert.IntToStr(KeywordTests.Checkin.Variables.POData.Value("Branch"))

8 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi Judy,

     

    You did not mention how you are trying to set the value to the options list, but some methods provided by TestComplete can accept both a string and an integer as parameters. And if the integer is provided as a parameter then the method selects an item by the index. This is documented in the relevant help topics.

    So I would suggest to convert the parameter to string (e.g. using the aqConvert.VarToStr()) and check if it helps.

    Alternatively, you may explicitly provide a string parameter (e.g. like .<Method>('"' + aqConvert.VarToStr(<parameter>) + "'") )

    • judyh's avatar
      judyh
      Occasional Contributor

      That's probably a good answer if I could figure out how to implement it. :)  I am VERY new to this software (started using it last week) so I'm probably phrasing my question wrong.  I'm using a Data-driven loop and have specified POData.csv as my data source:

      This csv contains, among other things, the branch number

        I've set up the test step to populate the branch number from the csv:

      What I can't figure out is how to convert the value from the csv to a string.  Where would I do that? I will dig through the documentation some more and see if I can find the 'relevant help topics' you mentioned.

       

      Regards,

      Judy

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Probably an easier way to do it would be to edit the CSV file and wrap the text in that column with double quotes to indicate they are strings and not integers.

         

        Alternatively, you're third screenshot, I would change mode to "Code Expression" and then, in the resulting field, enter:

         

        aqConvert.VarToStr(KeywordTests.Checkin.Variables.PODData("Branch"))

        That SHOULD do the necessary conversion.

    • judyh's avatar
      judyh
      Occasional Contributor

      Thanks for the info.  After looking at your response again, I figured out that, rather than passing the value from the csv directly into the test, I needed to create a string variable and a corresponding function to convert the value from the csv into a string, populate the string variable and pass that value to the test.

       

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        That's the long way around, yes. ;)  You don't need the variable if you do the code expression as I indicated but the general effect is the same.