Forum Discussion

kyle_mciver's avatar
kyle_mciver
Occasional Contributor
11 years ago

keyword test data driven loop dropping leading zero

I have a keyword test recorded against a web page, when I run this using hard coded values the script runs flawlsly.



When i try to use data from an external spreadsheet the first value retrieved from the spreadsheet is a date in the format mm/dd/yyyy.  It is in this format in the spreadsheet.  But if the month is < 10, as most months are, the import will always be entered into my online application as m/dd/yyyy.  The application throws an error and the script stops running.



Why is the leading zero beind dropped?  How do I fix it?

6 Replies

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3
    I got around several of those sort of issues by making all my fields in Excel of format Text, even if  the content is a date or an integer or whatever.  
  • dfarr's avatar
    dfarr
    Occasional Contributor
    I encountered a similar problem in the past also and found the solution to be the same: force the test data to text so TestComplete will interpret it as a string. But also, my understanding is that setting Excel pages or columns to be of type text still does not guarantee that TestComplete will interpret a cell value as a string. The only way to force this reliably is to precede the value in the cell with a ' (single quote). So Kyle could force the test data to text this way instead of using .csv file if Excel is preferable.
  • kyle_mciver's avatar
    kyle_mciver
    Occasional Contributor




    This is deffinetely TestComplete not reading the .xls correctly.



    I was able to work around it by changing the file layout to .csv.



  • kyle_mciver's avatar
    kyle_mciver
    Occasional Contributor
    I don't see an option to quote responses so here goes...



    Marsha - I did try changing the data type to text and there were a couple issues with it.  The first and worst was that the script would then throw an error "type mismatch" and stop execution.  Second being I had to generate the file which was several thousand lines long.  If I used date or num I can drag down to populate vs. typing every value in.





    Donald - do you mean prepopulate the cell in excel with the single quote or in the test script?



    Tanya - that help artice has good examples for including that in script based tests, anyhwere I can find an example of integrating it into a keyword driven test?
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Kyle,


     


    There are several ways to call the method from a keyword test:


     - you can create a script function that will perform the needed conversion and call it from your test via the Run Script Routine operation.


     - you can call the method from the keyword test via the Run Code Snippet operation.


     - call the conversion method when the test is filling in fields in your app. For this, you will need to use the Code Expression mode. Look into the image I posted here. To learn more information about this mode, refer to this article.