【发布时间】:2020-09-09 05:31:06
【问题描述】:
我正在尝试获取跨度标记的文本并将其更改为数字,然后在此数字上使用断言
这是我的command.js 文件:
function num(){
// this is the span text "Published August 27th, 2020"
cy.get("span_text").then(function($el){
var actualText = $el.text()
var split = actualText.split(" ")
var year = split[split.length - 1];
var x = parseInt(year)
return cy.wrap(x); // 2020
})
}
Cypress.Commands.add('year', num)
这就是我在测试文件中调用它的方式,然后使用断言:
// test.js
const newProject = cy.year().then((value) => value
console.log(value) // 2020 -> OK
);
console.log(newProject) // [Object] here is my question, why is an Object in here ??? I expect to be be a same as 2020
expect(newProject).to.be.greaterThan(2019) // expected [object Object] to be a number or a date
但我在赛普拉斯日志中收到此错误消息:
expected [object Object] to be a number or a date
我发现我不能断言对象而不是数字。但我不知道如何用另一个数字断言这个对象的返回值。谁能帮助我,让我知道我的测试出了什么问题,我该如何解决?
【问题讨论】:
标签: javascript node.js automation cypress