我使用以下函数从应用程序中获取值并将其与预期值进行比较。但它在以下方面失败了。请帮我解决这个问题。
getEleAttribute = async function(ele, attr) {
var attribute = await ele.getAttribute(attr);
return attribute;
}
enterTodayDate= function(){
return moment(Date.now()).format('YYYY-MM-DD');
}
this.verifyProp = async function () {
var fetchDate = getEleAttribute(verifyDate, "value").toString().substring(0, 10);
console.log(fetchDate); // this is printing -- [object Pr
var today=enterTodayDate().toString();
assert.equal(fetchDate, today, "Expected Date is not same as Actual Date");
}
输出:
AssertionError: Expected Date is not same as Actual Date: expected '[object Pr' to equal '2020-06-18'
+ expected - actual
-[object Pr
+2020-06-18
代码看起来不错,但你的逻辑有问题。
调用getEleAttribute(verifyDate, "value").toString()
返回对象的名称,而不是包含日期的字符串。将断言与使用moment
方法生成的日期字符串进行比较时,断言失败。
您需要调试代码并查看getEleAttribute
函数返回的内容。
以下更改后的问题已解决:
var fetchDate = getEleAttribute(verifyDate, "value");
var actualDate= String(fetchDate).substr(0, 10);
console.log(actualDate); //printed -- 2020-06-19