Example: Keywords with Parameters

This topic provides an example of how you can use keywords with parameters. A keyword or a keyword sequence can have a combined total of 20 input and output parameters.

As a first step, create a keyword-driven test which contains the keywords that you want to use. You can do this by recording an entire keyword-driven test, or by creating a new keyword-driven test and by adding the keywords in the keyword-driven test editor.

In this example, the keyword-driven test includes the following keywords:
Start application
This is the standard keyword that starts the AUT and sets the base state.
Login
This keyword logs into the AUT with a specific user, identified by a user name and a password.
GetCurrentUser
This keyword returns the name of the user that is currently logged in to the AUT.
AssertEquals
This keyword compares two values.
Logout
This keyword logs the user out from the AUT.

The next step is to add the parameters to the keywords. To do this, open the test scripts of the keywords and add the parameters to the methods.

To add the input parameters UserName and Password to the keyword Login, change
' VB .NET code
<Keyword>
public Sub Login()
  ...
End Sub
to
' VB .NET code
<Keyword>
public Sub Login(UserName As String, Password As String)
  ...
End Sub
To add the output parameter UserName to the keyword GetCurrentUser, change
' VB .NET code
<Keyword>
public Sub GetCurrentUser()
  ...
End Sub
to
' VB .NET code
<Keyword>
public Sub GetCurrentUser(ByRef CurrentUser As String)
  ...
End Sub

The keyword-driven test in the Keyword-Driven Test Editor should look similar to the following:


Now you can specify actual values for the input parameters in the Keyword-Driven Test Editor. To retrieve the value of the output parameter UserName of the keyword GetCurrentUser, provide a variable, for example ${current user}. You can then pass the value that is stored in the variable to subsequent keywords.