Calling script functions from Keyword Tests

Sometimes, it is easier to write up a simple function with the help of a programming language than implement the same functionality with the help of the keywords in the Keyword Tests.

In this recipe we will consider how to call an ordinary function from the Keyword Test.

Getting ready

Create the following function in the module of Unit1:

function testRunFromKeywordTest(param1)
{
  Log.Message("Parameter: " + param1);
}

How to do it...

To evoke the function, it is necessary to do the following actions:

  1. In the Operation list, select the Test Actions element and drag-and-drop the Run Script Routine element to the spot, where you plan to call the created function.
    How to do it...
  2. In the opened Select Test window, select the necessary function and click on OK:
    How to do it...
  3. If the function accepts parameters, a new Operation Parameters window will open up, where it is necessary to signify the values of the parameters of the called function, and then click on OK again:
    How to do it...
  4. In the result, the call of the function will be added to the test.

If the test should be launched, the log would contain the following message: Parameter: test string.

How it works...

With the help of the Run Script Routine operation, we can call any function from the current project.

If it's necessary to call the function from a different project, we must add the respective module to the current project by beforehand right-clicking on the Script element, and navigating to Add | Existing Item menu item.

There's more...

Besides calling the ordinary functions, Keyword Tests allow us to call code snippets, without creating individual functions (the Run Code Snippet operation), as well as the methods of screen objects (the Call Object Method operation). It is also possible to call other Keyword Tests by using the Run Keyword Test action from the Test Action group.

If you want to use values calculated earlier as parameters, you can use Project variables or Script variables to store the value and then specify it by clicking on the button with three dots next to the Value field.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.83.151