@Retention(value=RUNTIME) @Target(value=FIELD) public @interface Window
By default, all page objects are running in the default browser window, but sometimes we want to open a new window from the same java thread (session) and manage another pages in there. To do this, we need to choose an identifier to that window and add this annotation (with the selected identifier) to the page object field in our step library.
public class MySteps extends StepLibrary {
// this page object will control the default browser window
private MyPage page1;
// this page object will control a new browser window
@Window("new-window")
private MyPage page2;
}
It is possible to add this annotation to a step library field (in a test class). If we do this, then all
page object referenced by that step library will be connected to the specified browser window - except
if they already have a Window annotation with a different identifier.
@Specification
public class MyTest {
// steps.page1 will control the "another-window" browser window, because it does not have an annotation
// steps.page2 will control the "new-window" browser window, because of it's explicit annotation
@Window("another-window")
private MySteps steps;
}
We can also open new tab with this annotation. If the window identifier (the parameter of the annotation) starts with colon, then it will identify a new tab in the default window. If the identifier contains a colon, then the text before the colon will be the window identifier, and the text after the colon will identify the tab in that window.
@Window(":new-tab")
private MyPage pageOnNewTab;
@Window("new-window:new-tab")
private MyPage pageOnNewWindowAndTab;
Some browsers (and webdrivers) does not support multiple windows. If those browsers all request for a new window will be implemented with a new tab in the default window.
The identifier of the controlled browser window (or tab) is inherited through references. So if a page object references another page objects and those objects are not annotated, then all of them will control the same window.
public abstract String value
Created by Kornél Simon, 2022