首页 > 解决方案 > 赛普拉斯 - 根据值使用自定义命令

问题描述

我需要编写一个自定义命令来根据通过 spec.ts 文件提供的元素值执行某些步骤。我无法弄清楚如何将值 A 和 B 传递给自定义命令,如何根据 A 或 B 存储定位器值,然后使用 then 命令打印值

Spec.ts 文件

cy.writetemp(A)
cy.writetemp(B)

自定义命令

cypress.command.add(writetemp,(A) => {
cy.get("select[name='Type']").should('have.value', 'A'), then print Apple
cy.get("select[name='Type']").should('have.value', 'B'), then print Banana

标签: cypress

解决方案


我想基于定位器构建逻辑,但意识到这是处理它的不好方法。我切换到属性值并且它起作用了。感谢大家的时间。


推荐阅读