document
获取当前活动页面的 window.document
对象。
语法
cy.document()
cy.document(options)
用法
正确用法
cy.document() // 返回 window.document 对象
参数
options (Object)
传入一个选项对象来改变 cy.document()
的默认行为。
选项 | 默认值 | 描述 |
---|---|---|
log | true | 在命令日志中显示该命令 |
timeout | defaultCommandTimeout | 等待 cy.document() 解析的超时时间,超过则超时 |
生成结果
cy.document()
返回window.document
对象。cy.document()
是一个查询命令,可以安全地链式调用其他命令。
示例
无参数
获取 document 并执行操作
cy.document().then((doc) => {
// 操作 document 元素
})
对 document 进行断言
cy.document().its('contentType').should('eq', 'text/html')
规则
要求
cy.document()
必须通过cy
链式调用。
断言
cy.document()
会自动 重试 直到所有链式断言通过
超时设置
cy.document()
可能会因等待添加的断言通过而超时。
命令日志
获取 document
cy.document()
上述命令在命令日志中显示为:

当点击命令日志中的 document
时,控制台会输出以下内容:
