正文

function

(2011-06-27 13:13:22) 下一个
User-Defined Functions and Function LibrariesA function library is a separate QuickTest document that contains Visual Basic script. Any text file written in standard VBScript syntax can be used as a function library.Your function libraries can contain:Function definitions (function signature and code). You can call these functions from other functions or from an action in your test after you associate the function library with the test.VBScript statements. These are statements that are not contained within function definitions (for example, RegisterUserFunc statements).QuickTest runs all of these statements when it loads the function library.Loading Function Libraries: At the beginning of a run session, QuickTest loads all of the function libraries associated with your test. In addition, you can use the LoadFunctionLibrary statement to dynamically load a function library during a run session.Associated Function LibrariesAfter you create your function libraries, you can associate them with your test. This enables you to insert a call to a public function or subroutine in the associated function library from that test. (Public functions stored in function libraries can be called from any associated test, whereas private functions can be called only from within the same function library.)You do this in the Test Settings dialog box (File > Settings > Resources node).User-Defined FunctionsIf you have segments of code that you need to use several times in your tests, you may want to create a user-defined function.A user-defined function is automatically defined as a global function.Private functions are functions that can be called only by other functions within the same function library. This is useful if you need to reuse segments of code in your public functions.When you store a function in a test action, it can be called only from within that action—the function cannot be called from any other action or test. This is useful if you do not want the function to be available outside of a specific action.If the same function name exists locally within your action and within an associated function library, QuickTest uses the function defined in the action.You can also register a user-defined function as a method for a QuickTest test object class. A registered method can either override the functionality of an existing test object method for the duration of a run session, or be registered as a new method for a test object class.User-Defined Function NamesWhen deciding the name for your function, consider the following:During run-time, QuickTest first searches the test for the specified function and then searches the function libraries in the order in which they are listed in the Resources pane. If QuickTest finds more than one function that matches the function name in a specific test or function library, it uses the last function it finds in that test or function library. If QuickTest finds two functions with the same name in two different function libraries, it uses the function from the function library that has the higher priority. To avoid confusion, it is recommended that you verify that within the resources associated with a test, each function has a unique name.When you create a user-defined function, do not give it the same name as a built-in function (for example, GetLastError, MsgBox, or Print). Built-in functions take priority over user-defined functions, so if you call a user-defined function that has the same name as a built-in function, the built-in function is called instead. For a list of built-in functions, see the Built-in functions list in the Step Generator (Insert > Step Generator).User-Defined Function RegistrationYou can register a public user-defined function to a test object to instruct QuickTest to use your user-defined function as a method of a specified test object class for the duration of a test run, or until you unregister the method.RegisterUserFunc statement specifies the test object class, the name of your function, and the name of the test object method that should call your function.Unregistering Functions:RegisterUserFunc "Link", "Click", "MyClick"RegisterUserFunc "Link", "Click", "MyClick2"UnRegisterUserFunc "Link", "Click"TasksManage Function Libraries: create, associate libraries;Create the function: You can define functions manually or using the Function Definition Generator, which creates the basic function definition for you automatically.Add function generator pic: P1051
[ 打印 ]
阅读 ()评论 (0)
评论
目前还没有任何评论
登录后才可评论.