Marking a Test Method in a Script as a Keyword

Mark an existing test method in a script as a keyword to reuse the method in keyword-driven tests.

  1. Open the script which includes the test method that you want to mark as a keyword.
  2. Add <Keyword()> or [Keyword], depending on whether you are editing a VB .NET or a C# script, to the start of the test method. By default, the keyword name is the name of the test method.
  3. Optional: You can set a different name for the keyword by adding <Keyword("KeywordName")> or [Keyword("KeywordName")], depending on whether you are editing a VB .NET or a C# script, to the start of the test method.
You can now use the test method as a keyword in a keyword-driven test.

Examples

To mark the test method Login as a new keyword with the name Login, type the following before the start of the test method:
'VB .NET code
<Keyword("Login")>
// C# code
[Keyword("Login")]
To mark the test method Login as a new keyword with the name Login and with the two input parameters UserName and PassWord, type the following:
// VB .NET code
<Keyword("Login", Description="Logs in with the given name and password.")>
Public Sub Login(Argument("UserName") As String, Argument("PassWord") As String)
    ...    // 
End Sub
// C# code 
[Keyword("Login", Description:="Logs in with the given name and password.")]
public void Login([Argument("UserName")] string UserName, [Argument("PassWord")] string PassWord)
{
    ...    // method implementation
}
Note: If you are viewing this help topic in PDF format, this code sample might include line-breaks which are not allowed in scripts. To use this code sample in a script, remove these line-breaks.