2 cypress
<g class="ABC" transform="translate(786.9,53)" score="1.3">
Run Code Online (Sandbox Code Playgroud)
如何查询此示例 HTML 标记的分数值?
我正在编写一个测试来查询 score 属性(在上面的示例中为1.3)并将其与我的测试中的正确数字进行比较。
我不确定如何获得分数属性值。cy.get()没有给我我需要的东西。
谢谢。
Cypress 让您可以直接访问 DOM。如果您想以 DOM 对象为目标并直接对其进行操作,您将需要使用该then()函数。
这是一个应该适用于您的情况的示例:
cy.get("g.ABC").then(elem => {
let score = elem.attr("score");
cy.log(score);
// etc...
});
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请参阅此文档页面。
如果要直接对值执行 mocha 断言,请使用should()自动重试:
cy.get("g.ABC").should(elem => {
let score = elem.attr("score");
// If this assertion fails, the entire block will retry until it doesn't.
expect(score).to.equal("1.3");
});
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请参阅此文档页面。
| 归档时间: |
|
| 查看次数: |
3482 次 |
| 最近记录: |