【问题标题】:How do I make tests repeatable in Cypress?如何在 Cypress 中使测试可重复?
【发布时间】:2019-07-16 06:45:26
【问题描述】:

我有一个包含各种用户类型(例如管理员、客户端等)的站点,虽然它们都具有特定于其用户类型的功能,但也有一些共享的功能。如何定义一组测试,以便在以一种用户类型登录时运行它们,然后在以另一种用户类型登录时再次运行?

我知道 Cypress.Commands.add(),但我还没有找到将它用于大量可重复测试的方法,仅用于重复单个测试的内部内容。

【问题讨论】:

    标签: testing integration-testing cypress end-to-end


    【解决方案1】:

    根据您有多少常见场景,您可以使用数据驱动的方法,例如:

    context('common scenarios', () => {
        const credentials = [
            {userName: "user1", password: "password1", userType: "admin"},
            {userName: "user2", password: "password2", userType: "client"}
        ]
    
        credentials.forEach(cr => {
            it(`should be able to login as ${cr.userType}`, () => {
                // ...
                // use cr.userName, etc...
                // ...
            })
        })
    })
    

    【讨论】:

    • 感谢您的回复,但这不适用于我的用例,因为每种用户类型都有不同的步骤来获取共享部分,而且我也不希望所有内容都集中在一个大文件。
    猜你喜欢
    • 2022-06-29
    • 1970-01-01
    • 2022-10-21
    • 1970-01-01
    • 2019-08-17
    • 1970-01-01
    • 2023-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多