Forum Discussion

DaleHooper's avatar
DaleHooper
New Contributor
7 years ago
Solved

Accessing a list of strings (created in a python script) from a keyword test

Please forgive me since this may be a newbie question. I've tried to check the documentation and consulted "the Google" and I haven't been able to locate an answer.  I am generating a list of strings within a python script that I then want to pass back to a keyword test.  I can work with the list within scripts, but I would like to understand how to get it back into a keyword test for use.

 

So basically,

 

versionList = []

...

s = logFile.Readline()

versionList.append(s)

...

return versionList

 

I've been trying LastResult and I defined the local variable in the keyword test as an object, but on return the object doesn't contain anything.  I suspect that I am just missing a step or two.  Any help or pointers to documentation links would be greatly appreciated.

 

Hopefully the screenshot below can give you an idea of what I am trying.  I attempted to return the array list in strArr.

 

Thanks,

Dale.

 

 

 

  • DaleHooper's avatar
    DaleHooper
    7 years ago

    I'm guessing that there is something that I am doing wrong because on the keyword test side the object doesn't show anything.  It doesn't indicate that it knows anything about the methods of the list, etc.  

     

    I had tried turning it into a comma separated string and that worked.  But I had certainly missed usage of aqString.GetListItem so that would do the trick.  If you have any insight concerning what I might be doing wrong as far as "connecting" the object that would be great.  Should I use "accept as solution" for this, because it certainly should work?

     

    I appeciate the help from you and baxatob!

5 Replies

  • baxatob's avatar
    baxatob
    Community Hero

    Hi,

     

    TestComplete does not have a builtin variable type like Python's <list>, so you can't assign TC variables with this type.


    If you tell us your requirements (why do you need to call a list from a Keyword test), probably we can find a workaround.

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      strArray is being returned as an object so most likely whatever object properties and methods are available to a Python array list would be accessible there as well.  That's my guess.

       

      The alternative is that, rather than using the Python list type, you could return it as a delimited string and then use the aqString.GetListItem method to get the specific element from your list.

      • DaleHooper's avatar
        DaleHooper
        New Contributor

        I'm guessing that there is something that I am doing wrong because on the keyword test side the object doesn't show anything.  It doesn't indicate that it knows anything about the methods of the list, etc.  

         

        I had tried turning it into a comma separated string and that worked.  But I had certainly missed usage of aqString.GetListItem so that would do the trick.  If you have any insight concerning what I might be doing wrong as far as "connecting" the object that would be great.  Should I use "accept as solution" for this, because it certainly should work?

         

        I appeciate the help from you and baxatob!

    • DaleHooper's avatar
      DaleHooper
      New Contributor

      Basically, I am reading a log file which has a list of part version numbers.  I then want to compare entries in that list with labels on-screen which should have those same numbers for the various parts.

       

      I'm very new to TestComplete so to some extent I was trying to figure out what "could" be done in the keyword test as opposed to within the script.  It does seem apparent to me that it is probably best for me to do the bulk of this within the script.

      • baxatob's avatar
        baxatob
        Community Hero

        DaleHooper wrote:

        It does seem apparent to me that it is probably best for me to do the bulk of this within the script.

        For me, too. It is faster to implement such complex requirements inside the script using all power of coding language. Anytime you can call your script from the Keyword test or from another script.