public abstract class StepLibrary extends WindowRelated
Superclass for step libraries. Each class sub-classing it will be automatically injected by the injector in
session-scope - there is no need for Inject annotation.
A step library defines business-level operations of a workflow. It does not describes technical functionality
- all technical-level functions should be specified in page object (see PageObject). A step library
uses page objects to construct higher-level steps. For example, to login into an application, you
should enter the user name and password into some input fields on the login page, the click the "login" button.
From business perspective, this is just one step, so the step library defining this step can be similar to this:
public class LoginSteps extends StepLibrary {
// page object will be automatically injected by the injector
private LoginPage loginPage;
public void login(String userName, String password) {
loginPage.open();
loginPage.setUserName(userName);
loginPage.setPassword(password);
loginPage.clickLoginButton();
}
}
A step library can use page objects and another step libraries. The injector automatically injects
(and initializes) all fields if the type of the field inherits the PageObject or StepLibrary
class. These fields can be referenced from all methods of the step library (but not from the constructor).
By default, the injected page objects are controlling the main browser window. With the Window annotation
we can bound a page object field to a different browser window. The annotation receives a string identifier.
If the window with that identifier already exists, the page object will be connected to that window,
otherwise a new window with that identifier will be created. In the example below the editor
page object instance will control a new browser window, which has the "editor" identifier.
public class EditorSteps extends StepLibrary {
@Window("editor")
private EditorPage editor;
private PresenterPage presenter;
}
Also step library fields may have Window annotation. The browser window can be inherited from the container class.
If a PageObject field does not have Window annotation, but the containing step library instance was injected
into another step library (or test) with a Window annotation, then the page object will use the browser window with
the injected identifier.
All public methods of a step library are considered as test steps and therefore automatically logged when called.
The log will contain the descriptive name of the methods. If the method has a Name annotation, then
the descriptive name will be the one specified by that annotation. Otherwise the descriptive name will be transformed
from the name of the method; all underscore character will be replaced by a space, and all camel-case substring
will be separated into multiple words. Method parameters are also included in the descriptive name. '$' signs in
method name are placeholders for parameters.
Examples:
public void sendErrorMessage() {
// descriptive name is "Send Error Message"
}
public void list_all_elements() {
// descriptive name is "List All Elements"
}
@Name("Logout From Application")
public void logout() {
// descriptive name is "Logout From Application"
}
@Name("Remove Message with Index ${0}")
public void removeMessage(int index) {
// the name may contain parameter substitution marker
// eg. removeMessage(5) will have descriptive name: "Remove Message with Index 5"
}
public void open_details_for_$s_job(String personName) {
// the '$' character will be replaced with the person name
// eg. open_details_for_$s_job("John") will have descriptive name: "Open Details for Johns Job"
}
A step library should have a public default constructor.
Created by Kornél Simon, 2022