Scripting a Python-based GUI-interfacing action

In Python code, implement the action that will interface with a target application.Define the function action_CheckRowCount(), which will handle the execution of the check row count action in TestArchitect.

Important: 
In Python, the indentation level of your statements (that is, the white space at the very left of your statements) is significant and it must be consistent . Also, the exact amount of indentation is important to the relative indentation of nested blocks (relative to each other).

The definition of action_CheckRowCount() remains to be implemented. Compared to the earlier action_hello() function, this involves considerably more work. In particular, the code needs to:

  1. Continue editing the file mod_TableSupport.py by declaring the method definition action_checkRowCount():

    
    
    def action_checkRowCount():
    

The first step within your method is to grab the values of the action line arguments and stuff them into variables.

  1. Enter the code lines below.

    The interpreter function NamedArgument(), which is part of the standard LIBRARY object, and which you also used in the previous exercise, is used to fetch the argument values.

    
        windowName = LIBRARY.NamedArgument("window")
        tableName = LIBRARY.NamedArgument("table")
        columnName = LIBRARY.NamedArgument("column")
        value = LIBRARY.NamedArgument("value")
        expected = LIBRARY.NamedArgument("expected")
    
  2. Assign the action’s name to a variable, for output to the results page or warning messages:

    
        checkLabel = "check row count"
    
  3. Notes: 
    Each control has its own instance (object) of the AbtElement class, which can be obtained by using the OpenElement method of ABT .

    Obtain the instance of the table object for the table specified by the values of windowName and tableName (derived from the logical TA names of the window and table arguments of the action):

    
        table = ABT.OpenElement(windowName, tableName)
        if table == None:
            LIBRARY.ReportWarning(checkLabel + ": Unable to identify table '" + tableName + "'")
            return
    

If the OpenElement() is successful (meaning, if it does indeed find the window and table it’s told to look for), it returns an object of class AbtTable, a sub-class of AbtElement. Of this class, you will make use of the following functions:

  1. Use GetColumnIndex() to get the number of the column specified by the column name argument:

    
        column = table.GetColumnIndex(columnName)
        if column == None:
            LIBRARY.ReportWarning(checkLabel + ": Unable to locate column '" + columnName + "' in table '" + tableName + "'")
            return
    
  2. Next, use GetRowCount() to determine the number of rows in the table:

    
        rowCount = table.GetRowCount()
    
  3. Cycle through all rows of the table, using GetCellText() in each case to get the contents of the cell of interest. Increment the tally every time a match is found with the value of the value argument of the action.

    
        count = 0
        for i in range(1, rowCount):
            if table.GetCellText(i, column) == value :
                count += 1
    
  4. Determine whether the actual count of matching rows is equal to the number expected (as given by the action’s expected argument). Depending on the result, use the AdministerCheck() function to send either a PASS or FAIL report to the TestArchitect results page:

    
        if expected == format(count):
            LIBRARY.AdministerCheck(checkLabel, expected, format(count), 1)
        else:
            LIBRARY.AdministerCheck(checkLabel, expected, format(count), 0)
    

    Notes: 
    TestArchitect functions always work with strings. Therefore, integer results like count must be converted to strings. This is handled by the format() function in Python.

Your entire action definition for action_checkRowCount() should now look similar to this:




# check row count <window> <table> <column> <value> <expected> action implementation
# verify the number of rows with a given value in a specified column
def action_checkRowCount():
    # get the arguments and assign a label for this check
    windowName = LIBRARY.NamedArgument("window")
    tableName = LIBRARY.NamedArgument("table")
    columnName = LIBRARY.NamedArgument("column")
    value = LIBRARY.NamedArgument("value")
    expected = LIBRARY.NamedArgument("expected")
    checkLabel = "check row count"
    
    # identify the window and the table on screen
    table = ABT.OpenElement(windowName, tableName)
    if table == None:
        LIBRARY.ReportWarning(checkLabel + ": Unable to identify table '" + tableName + "'")
        return
    
    # determine the column of interest
    column = table.GetColumnIndex(columnName)
    if column == None:
        LIBRARY.ReportWarning(checkLabel + ": Unable to locate column '" + columnName + "' in table '" + tableName + "'")
        return
    
    # get the number of table rows
    rowCount = table.GetRowCount()
    
    # count the number of rows matching the column value
    count = 0
    for i in range(1, rowCount):
        if table.GetCellText(i, column) == value :
            count += 1
    
    if expected == format(count):
        LIBRARY.AdministerCheck(checkLabel, expected, format(count), 1)
    else:
        LIBRARY.AdministerCheck(checkLabel, expected, format(count), 0)

                
            

Ensure that your Python files, mod_TableSupport.py and ta_main.py are saved. Next, you’ll take care of hings on the TestArchitect client side.


Copyright © 2024 LogiGear Corporation. All rights reserved. LogiGear is a registered trademark, and Action Based Testing and TestArchitect are trademarks of LogiGear Corporation. All other trademarks contained herein are the property of their respective owners.

LogiGear Corporation

1730 S. Amphlett Blvd. Suite 200, San Mateo, CA 94402

Tel: +1 (650) 572-1400