【发布时间】:2020-11-16 20:48:01
【问题描述】:
我正在使用 Cypress 进行端到端集成测试。我有一个用例涉及从赛普拉斯自定义命令返回对象列表,但我很难这样做。这是我的代码指针:
index.ts
declare global {
namespace Cypress {
interface Chainable<Subject> {
getTestDataFromElmoDynamoDB({locale, testType}): Cypress.Chainable<JQuery<expectedData[]>> // ??? not sure what return type should be given here.
}
}
}
Cypress.Commands.add('getTestDataFromDynamoDB', ({locale, testType}) => {
// expectedData is an interface declared. My use case is to return the list of this type.
let presetList: expectedData[]
cy.task('getTestDataFromDynamoDB', {
locale: locale,
testType: testType
}).then((presetData: any) => {
presetList = presetData;
// the whole idea here is to return presetList from cypress task
return cy.wrap(presetList) //??? not sure what should be written here
})
})
sampleSpec.ts
describe('The Sample Test', () => {
it.only('DemoTest', () => {
cy.getTestDataElmoDynamoDB({
locale: env_parameters.env.locale,
testType: "ChangePlan"
}).then((presetlist) => {
// not sure on how to access the list here. Tried wrap and alias but no luck.
presetList.forEach((preset: expectedData) => {
//blah blah blah
})
})
})
})
以前有没有人研究过类似的用例?
谢谢, 萨希思
【问题讨论】:
-
Cypress 自动将任务数据传出命令,只需简单地调用任务即可。显示的其他一切都只是噪音。
标签: node.js typescript list automation cypress