|Working with the Python harness / User-scripted Python harness action that interacts with GUI|
Create a new Python module, and provide the code overhead required to access your new user-scripted action.
We'll begin by creating a new code file, similar in nature to mod_Example.py, used in the earlier exercise. This code file, or module, will contain Python-implemented actions relating to tables.
# import the functions of TestArchitect from lib_abt import * # set module name moduleName = "table support" # declare the actions for the module def SetActions(): LIBRARY.SetActionScript("check row count", moduleName, 1) # map an action to its function def Divert(actionName): result = True if actionName == "check row count": action_checkRowCount() else: result = False LIBRARY.ReportError("Don't know action: " + actionName) return resultAs in the previous exercise, there is a SetActions() function, which in this case declares those actions that are part of the mod_TableSupport module. (Only one action, check row count, is so declared, in this case.) The Divert() function, also seen previously, is called from the main module and directs the action to the Python function that implements it.
import lib_interpret as Interpreter import mod_Example as Example import mod_TableSupport as TableSupport
# register actions (add your "setActions" functions here) Example.SetActions() TableSupport.SetActions()
# divert the action to a script module # note: this function is called by the interpreter, it should return: # - True to tell the interpreter that the custom action has been consumed # - False if it cannot handle action from the module def DivertToModule(moduleName, actionName): if moduleName == Example.moduleName: return Example.Divert(actionName) elif moduleName == TableSupport.moduleName: return TableSupport.Divert(actionName) else: Interpreter.LIBRARY.ReportError("Don't know action: " + actionName) return False