Cypress.io - 从 `then` 输入
Cypress.io - typing into input from `then`
我有表格要测试,我想检查输入是否有必填字段和一些其他自定义行为。
我正在这样查询输入:
cy.get('#input_id').then(($input) => {
// My assertions here
});
我的问题是,如何从传递给 .then
的函数中键入输入?
我找到了 root
方法,当我从 then
控制台记录它时,我发现 root()
是 document
本身。
如@RichardMatsen 所述,您可以使用 wrap
函数获取从 then
获得的元素。
Cypress 文档提到 wrap
on Elements 的用法为:
Wrap elements to continue executing commands
所以您需要做的就是:
cy.wrap($input).type('Input Text')
我有表格要测试,我想检查输入是否有必填字段和一些其他自定义行为。
我正在这样查询输入:
cy.get('#input_id').then(($input) => {
// My assertions here
});
我的问题是,如何从传递给 .then
的函数中键入输入?
我找到了 root
方法,当我从 then
控制台记录它时,我发现 root()
是 document
本身。
如@RichardMatsen 所述,您可以使用 wrap
函数获取从 then
获得的元素。
Cypress 文档提到 wrap
on Elements 的用法为:
Wrap elements to continue executing commands
所以您需要做的就是:
cy.wrap($input).type('Input Text')