seleniumpage-refreshui-testingserenity-bdd

How to refresh page using Serenity Screenplay pattern?


I need to refresh the page using the Serenity screenplay pattern. I tried to apply

user.attemptsTo(Hit.the(Keys.F5).into(element));

But it didn't work of course.


Solution

  • Serenity Screenplay does not have a convenience function for refresh, but it should be trivial to roll your own.

    public class Refresh implements Task {
    
        public Refresh() { }
    
        public static Refresh thePage() {
    
            return Tasks.instrumented(Refresh.class);
        }
    
        @Override
        @Step("{0} refreshes the browser")
        public <T extends Actor> void performAs(T actor) {
    
            WebDriver driver = BrowseTheWeb.as(actor).getDriver();
            driver.navigate().refresh();
        }
    }