Search code examples
javaselenium-webdrivercucumberserenity-bdd

Serenity-Cucumber PageObject @DefaultURL no longer getting url from serenity.config file after upgrading to version 3.4.2


After upgrading my Serenity-Cucumber project to version 3.4.2 I receive this error when running.

java.lang.AssertionError: Invalid URL: page:signin.url
at net.serenitybdd.core.pages.PageUrls.verified(PageUrls.java:80)

It was working prior to the update and all of my syntax looks correct, I wonder if this feature changed or the syntax changed. After trying to google search around for some answers I have come here. 🙂

Page file

@DefaultUrl("page:signin.url")
public class SigninPage extends PageObject { ... }

serenity.config file

environments {
prod { signin.url = "https://signin.com" }
dev { signin.url = "https://dev-signin.com" }
default { signin.url = "https://dev-signin.com" }
all { admin.signin.url = "#{signin.url}/admin" }
}

If I instead change the Page file to contain a static url, that works and I don't get an error.

@DefaultUrl("https://dev-signin.com")

But, I need it to reference my serenity.config file instead.


Solution

  • I found some code to directly reference the serenity.conf file.

    @Step("Open sign in page")
    public void openSigninPage() {
       EnvironmentVariables variables = SystemEnvironmentVariables.createEnvironmentVariables();
       
       getDriver().get(EnvironmentSpecificConfiguration.from(variables)
           .getProperty(pageObjectFileHere.getClass()
           .getAnnotation(DefaultUrl.class).value()));
    }
    

    It requires me to pass in an environment variable from mvn command (or will use default)

    mvn clean verify -Denvironment=dev"
    

    It also needs the Page file.

    @DefaultUrl("signin.url")
    public class PageObjectFileHere extends PageObject { ... }
    

    And of course the serenity.conf file. (The env passed into the mvn command matches the environments here)

    environments {
      prod { 
        signin.url = "https://signin.com" 
      }
      dev { 
        signin.url = "https://dev-signin.com" 
      }
      default { 
        signin.url = "https://dev-signin.com" 
      }
      all { 
        admin.signin.url = "#{signin.url}/admin" 
      }
    }