我正在使用带有 BDD 语法(https://docs.cypress.io/api/cypress-api/spec)的柏树和下面的测试用例。(这是进行中的工作)
我想将行的值从“然后”行传递到“和”行。
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; })