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 Silk4J, a keyword is an annotated test method (@Keyword). 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 annotation. In Java, keywords are defined with the following annotation:
@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:
// Java code
@Argument("parameter_name")

By default a parameter is an input parameter in Silk4J. To define an output parameter, use the class OutParameter.

Note: To specify an output parameter for a keyword in the Keyword-Driven Test Editor, use the following annotation:
${parameter_name}
In the Keyword-Driven Test Editor, you can use the same annotation to use an output parameter of a keyword as an input parameter for other keywords.

Example

A test method that is marked as a keyword can look like the following:
// Java code
@Keyword("Login")
public void login(){
    ... // method implementation
}
or
// Java code
@Keyword(value="Login", description="Logs in with the given name and password.")
public void login(@Argument("UserName") String userName, 
  @Argument("Password") String password, 
  @Argument("Success") OutParameter success) {
    ... // method implementation
}
where the keyword logs into the application under test with a given user name and password and returns whether the login was successful. To use the output parameter as an input parameter for other keywords, set the value for the output parameter inside the keyword.
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 annotation 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 annotation 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 annotation to specify a different name for the keyword argument, for example UserName instead of userName.