[英]@badeball/cypress-cucumber-preprocessor not generating .json report
[英]Cleardown test data using @badeball/cypress-cucumber-preprocessor
我是 Cucumber 測試的新手。 我有一個可以正常工作的入門測試,但我需要在測試之間清除數據庫。
這是場景:
Scenario: Should update the stock levels
Given user is on the product page
When user updates the stock quantity
Then the new stock quantity is available on the product page
如何處理 Cucumber 中的數據庫的清除? 我已經看到了在 Node 中播種數據庫的配方,但是如何在 Cucumber 中實現它?
在您的步驟文件中,您可以像在非黃瓜賽普拉斯測試中一樣添加一個beforeEach()
掛鈎。
import { Given, When, Then } from "@badeball/cypress-cucumber-preprocessor";
beforeEach(() => {
// reset database
cy.fixture('my-data.json').then(data => {
cy.task('seed:db', data)
})
})
Given('user is on the product page', () => {
...
})
您有幾個地方可以調用該任務。
如果使用 Mocha beforeEach()
,它將首先運行 - 在 Cucumber 方法之前。
您還可以導入 Cucumber Before()
,它是 Mocha 掛鈎的包裝器,在beforeEach()
調用之后運行。
或者,您可以在Given()
方法的開頭調用數據庫種子任務。
import { When, Then, Before, Given } from "@badeball/cypress-cucumber-preprocessor";
beforeEach(() => {
// reset database
cy.fixture('dbdata.json').then(data => {
cy.task('seed:db', data)
})
})
Before(() => {
// reset database
cy.fixture('dbdata.json').then(data => {
cy.task('seed:db', data)
})
})
Given('user is on the product page', () => {
// reset database
cy.fixture('dbdata.json').then(data => {
cy.task('seed:db', data)
})
cy.visit(...)
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.