Keywords

A keyword is a defined combination of one or more actions on a test object. The implementation of a keyword can be done with various tools and programming languages, for example Java or .NET. In Silk4NET, a keyword is a method with the attribute Keyword before the method name. Keywords are saved as keyword assets.

You can define keywords and keyword sequences during the creation of a keyword-driven test and you can then implement them as test methods. You can also mark existing test methods as keywords with the Keyword attribute.Keywords are defined as follows:
'VB .NET code
<Keyword("keyword_name")>
// C# code
[Keyword("keyword_name")]

A keyword sequence is a keyword that is a combination of other keywords. Keyword sequences bundle often encountered combinations of keywords into a single keyword, enabling you to reduce maintenance effort and to keep your tests well-arranged.

A keyword or a keyword sequence can have a combined total of 20 input and output parameters. Any parameter of the test method that implements the keyword is a parameter of the keyword. To specify a different name for a parameter of a keyword, you can use the following:
'VB .NET code
Argument("parameter_name")
// C# code
[Argument("parameter_name")]

Example

A test method that is marked as a keyword can look like the following:
'VB .NET code
<Keyword("Login")>
Public Sub Login()
    ...  // method implementation
End Sub
// C# code
[Keyword("Login")]
public void Login(){
    ... // method implementation
}
or
'VB .NET code
<Keyword("Login", Description:="Logs in with the given name and password.")>
Public Sub Login(<Argument("UserName")> username As String, <Argument("Password")> password As String)
    ... // method implementation
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
}
where the keyword logs into the application under test with a given user name and password.
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.
  • The keyword name parameter of the Keyword attribute is optional. You can use the keyword name parameter to specify a different name than the method name. If the parameter is not specified, the name of the method is used as the keyword name.
  • The Argument attribute is also optional. If a method is marked as a keyword, then all arguments are automatically used as keyword arguments. You can use the Argument attribute to specify a different name for the keyword argument, for example UserName instead of userName.