Open SiKing opened 4 years ago
find
is a method of the PageObject. extract()
though I can't find anywhere, maybe the docs are outdated? find
only makes sense when you do actions via page objects and you don't really want that. Best practice is to decouple actions from page objects. see https://johnfergusonsmart.com/beyond-page-objects-liberate-chains-ui-think/ and https://www.infoq.com/articles/Beyond-Page-Objects-Test-Automation-Serenity-Screenplay/
I would propose something like this:
... actor.attemptsTo(LookupQuestions.labeled("Hot")) ...
class LookupQuestions extends Performable { ...
actor.attemptsTo(Open.browserOn(new QuestionsPage()))
actor.attemptsTo(Click.on(QuestionsPage.displayByLabel("Hot"))) ...
@DefautlUrl("https://stackoverflow.com/")
class QuestionsPage extends PageObject {
static Target displayByLabel(String s) {
return Target.the("button labeled" + s).locatedBy("some css locator using " +s)
You could also wrap the CSS locators in enums and have an enum value for each tab.
I eventually came up with:
public class NavigateToSection implements Task {
private String label;
public NavigateToSection(String label) {
this.label = label;
}
@Step("{0} navigates to section '#label'")
@Override
public <T extends Actor> void performAs(T actor) {
actor.should(seeThat(the(Section.labeled(label)), isCurrentlyVisible()).orComplainWith(NavigationSectionNotFound.class, label));
actor.attemptsTo(Click.on(Section.labeled(label)));
}
public static NavigateToSection labeled(String pageLabel) {
return Instrumented.instanceOf(NavigateToSection.class).withProperties(pageLabel);
}
}
public class Section {
public static Target labeled(String label) {
return Target.the("application section " + label).locatedBy("//a[contains(., '" + label + "')]");
}
}
This seems to work for my use-case, for now. I seem to be struggling more with how to express what I want in English and where are all the bits and pieces. I refactor almost everything every day, as I build up more stuff. That whole Open-Closed Principle is completely not working for me. :(
I am having problems modelling slightly complex controls, and the documentation has only trivial buttons and links.
I have a situation like this:
NavigateTo.page(String)
, as inactor.attemptsTo(NavigateTo.page("Interesting"))
.As a hint I was able to find this, but it is not clear where the
find(...)
static import comes from.I constantly find myself struggling to model something in Screenplay, that I used to whip up without a second thought using PageObjects:
Can you help?