【问题标题】:serenity bdd default url with spring boot random port number带有spring boot随机端口号的serenity bdd默认url
【发布时间】:2017-04-22 11:03:12
【问题描述】:

在使用 Serenity 进行测试时,我使用随机端口启动 Spring Boot 应用程序。

有时我需要像这样使用 PageObject:

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

问题是:如何在PageObject中注入随机端口号?

我想以某种方式将 8080(这是默认端口)替换为 Spring Boot 测试提供的随机端口。

【问题讨论】:

    标签: spring-boot serenity-bdd


    【解决方案1】:

    您可以使用setDefaultBaseUrl() 在页面对象的构造函数中设置正确的 URL。

    【讨论】:

    • 我试过了,但没有成功……直到我用“@Steps”注释了保存页面对象(在实现任务的类中)的字段。让我感到困惑的是,当我在页面对象中使用“@DefaultUrl”时,我在任务实现中不需要“@Steps”。但我想这是由于我对框架的了解有限。
    • 您不需要使用@Steps 注释页面对象,它仅适用于步骤库。只要 Serenity 扩展了 PageObject,它就会注入任何 Page Object。
    猜你喜欢
    • 2021-03-13
    • 2020-02-20
    • 2015-12-05
    • 1970-01-01
    • 2016-12-13
    • 2019-05-21
    • 2019-05-01
    • 2019-03-10
    • 1970-01-01
    相关资源
    最近更新 更多