测试-在Cypress中访问种子数据

时间:2020-09-30 14:39:04

标签: ruby-on-rails cypress e2e-testing seeding

我想在测试期间访问种子数据库

我的设置:

我要测试的种子包含:

FactoryBot.create_list(:user, 10)

我的用户工厂如下:

  factory :user { email { Faker::Internet.unique.email } }

(因此,我无法提前知道他们的电子邮件地址)

我的目标

在测试的某一时刻,我很想做类似的事情:

    cy.get('body')
      .should('contain', `${user.last.email}`)

有没有一种方法可以在赛普拉斯测试中达到该结果?

1 个答案:

答案 0 :(得分:1)

Cypress Real World Appa payment application to demonstrate real-world usage of Cypress testing methods, patterns, and workflows演示了如何通过以与语言和框架无关的方式实现的远程命令来访问种子数据。

使用赛普拉斯命令cy.database(称为Cypress Task depending upon the operation (filter or find))完成

任务向test API endpointonly exposed for the test environment发出API请求。

该技术可用于从远程或本地实例访问种子数据,并可用于驱动测试,如the notifications spec所示。