【发布时间】:2021-06-30 10:56:18
【问题描述】:
我正在使用带有 BDD 语法 (https://docs.cypress.io/api/cypress-api/spec) 的 cypress,测试用例如下。 (正在进行中)
我想将“Then”行中的行值传递给“And”行。
Scenario: Table contains correct data
Given I am on page "status overview"
Then the "1" row "ID" should display "1"
And "items" column should display "1"
And "cost" column should display "2"
Then the "2" row "ID" should display "1"
And "items" column should display "1"
And "cost" column should display "2"
我的测试定义步骤
Then('the {string} row {string} should display {string}', (index, column, value) => {
column = column.toLowerCase();
cy.task('setRowId',index);
getRow(index)
.find(`[data-testid="${column}"]`)
.should('have.text', value)
})
And('{string} column should display {string}',(column, value)=>{
column = column.toLowerCase();
var index = (cy.task('getRowId')).toString();
// index should be loaded with correct id from previous test
getRow(index)
.find(`[data-testid="${column}"]`)
.should('have.text', value)
})
然后我添加了自定义柏树步骤
Cypress.Commands.add('setRowId',(val) => { return (rowId = val); })
Cypress.Commands.add('getRowId',() => { return rowId; })
【问题讨论】:
标签: cypress cypress-cucumber-preprocessor