0

In tests with Serenity I'm starting my Spring Boot application with a random port.

At some point I need to use a PageObject like this:

@DefaultUrl("http://localhost:8080")
public class GreetPage extends PageObject {
}

The question is: how can I inject a random port number in the PageObject?

I want to somehow replace the 8080 (which is the default port) with the random port provided by Spring Boot test.

Jorge Viana
  • 396
  • 5
  • 12

1 Answers1

1

You could set the proper URL in the constructor of your Page Object using setDefaultBaseUrl().

John Smart
  • 969
  • 1
  • 5
  • 5
  • I tried that but it didn't worked... until I annotated the field that was holding the page object (in a class that implements Task) with '@Steps'. What is still confusing to me is that when I used the '@DefaultUrl' in the page object I didn't needed the '@Steps' in the Task implementation. But I guess this is due to my limited knowledge of the framework. – Jorge Viana Dec 12 '16 at 22:18
  • You shouldn't need to annotate a Page Object with @Steps, it's only for step libraries. Serenity will inject any Page Object as long as it extends PageObject. – John Smart Jan 19 '17 at 21:49