Forum Discussion

vondie's avatar
vondie
Contributor
9 years ago
Solved

Python Script Odd List Behavior

I am fairly new to writing in Python and working with TestComplete. I need help understanding some odd behavior I am seeing in one of my scripts.

 

A little background: Just last week, I was given a new laptop. I created my Python scripts on my old laptop and all of my files were copied to the new laptop. On the old laptop, each of my scripts ran as expected. When I try to run them on the new computer, I am seeing a different result. This script is verifying that data added in a Keyword test (Client Name) appears in a dynamic table. I am taking the text items that display ina column on a list and comparing them to the Variable that was added in the Keyword test. If they match, the test was successful because the record exists in the table. If it does not exist, the test fails. 

 

Code (Edited to Protect my Company's Privacy): 

 

def Search_Text():
  Sys.Browser("firefox").BrowserWindow(0).SetFocus()
  browser = Aliases.browser
  clientTable = browser.pageapps.tableClientlisttable

  rowTotal = clientTable.GetUnderlyingObject().RowCount

  rowCount = rowTotal - 1

  Log.Checkpoint("The total number of rows in the Client table is: %s" % rowCount)

  rowsLst = range(1, int(rowTotal))
  rowsText = []

  for n in rowsLst:
    y = clientTable.GetUnderlyingObject().Cell(n,0).contentText
    rowsText.append(y) 
    Log.Checkpoint("The Client Name values in the table are: %s" % y)

    Log.Checkpoint(str(rowsText))

  if Project.Variables.VarArchive in rowsText:
    Log.Checkpoint("The Test was successful!")
    return
  else:
    Log.Error("The test failed. Please open a bug in JIRA.")
    return

 

 

In my results, I am getting all passes (good according to the table data that is displayed in my Firefox browser). However, the checkpoint where I am printing my rowsText list shows no values (empty) when I do not convert it to a string (    Log.Checkpoint(rowsText). When I convert it to a string, it displays what looks like a memory location for each list item ([<__main__.aqPyScriptMemberWrapper object at 0x1DE23A50>, <__main__.aqPyScriptMemberWrapper object at 0x1DE23A70>, <__main__.aqPyScriptMemberWrapper object at 0x1DE23A90>, <__main__.aqPyScriptMemberWrapper object at 0x1DE23AB0>, <__main__.aqPyScriptMemberWrapper object at 0x1DE23AD0>, <__main__.aqPyScriptMemberWrapper object at 0x1DE23AF0>, <__main__.aqPyScriptMemberWrapper object at 0x1DE23B10>, <__main__.aqPyScriptMemberWrapper object at 0x1DE23B30>, <__main__.aqPyScriptMemberWrapper object at 0x1DE23B50>, <__main__.aqPyScriptMemberWrapper object at 0x1DE23B70>, <__main__.aqPyScriptMemberWrapper object at 0x1DE23B90>] 10:24:08 Normal). 

 

On my old laptop, the list would show all of the values that were obtained in the For loop.

 

So this post has two questions: 

1. Why is the list blank when I do not convert the list to a string?

2. Why is the list showing memory instances instead of printing the values of the rowsText list?

 

Can anyone explain what is going on in the background?

 

 

I am currently using the newest version of Test Complete (11.20.1491.7), which was the same version on the old laptop.  

 

Any help is appreciated! Thank you.

 

vondie

 

Edit: Added purpose of the script and an image attachment of test results. 

  • I figured out this issue by writing it in a different way, for anyone that might have this issue in the future. 

     

    rowsText.append(str(y)) 
    .......
    Log.Checkpoint(" ".join(rowsText))

4 Replies

  • baxatob's avatar
    baxatob
    Community Hero

    Hi Vondie,

     

    Try to change your code this way:

     

    ...
    
    for n in rowsLst:
    
        y = clientTable.GetUnderlyingObject().Cell(n,0).contentText
        rowsText.append(str(y)) # <-------------- make type conversion here
        Log.Checkpoint("The Client Name values in the table are: %s" % y)
        Log.Checkpoint(rowsText)
    
    ...

    I faced the similar troubles with Python string type in the latest vesion of TC. Support Team said that they are aware and working on it.

     

    • vondie's avatar
      vondie
      Contributor

      Thank you for the reply! I tried this and the list prints as if it were empty. The only way I have found to get it to print any values is to convert the list to a string and print... which worked in the past but now is giving me memory locations.

      • baxatob's avatar
        baxatob
        Community Hero

        I only have an idea to downgrade TC to the previous version (11.1) and check on it.