我刚开始用邮递员和下面的语言写测试,这是我花了几天时间研究后无法通过的。我会感谢你的专业知识:
以下是我迄今所做的工作。从POST请求响应中,我解析它以获取Epoch时间,然后将其转换为人类可读的日期时间。
响应机构: 1604448930 Tue 11月03 2020 18:15:30格林尼治时间-0600(中央标准时间)
下面是我在测试脚本中的内容:
jsonData = JSON.parse(responseBody)
x = jsonData[0].ScheduledAttempt.ScheduledDateTime;
epochScheduledDateTime = jsonData[0].ScheduledAttempt.ScheduledDateTime
console.log(epochScheduledDateTime)
Date = new Date ((epochScheduledDateTime) *1000);
console.log(Date)现在,如何将我的人类可读的日期与预期的min和最大日期时间进行比较。
如:2020年11月3日下午18:15 30格林尼治时间-0600(中央标准时间)介于格林尼治时间11月3日下午6:00-0600之间(中央标准时间)和Tue 11月03 2020 20:00格林尼治时间-0600(中央标准时间)之间。
感谢你的指导。谢谢Kp
发布于 2020-12-12 14:54:33
您不必将划时代时间转换为dateString,而是可以使用日期的getTime()方法将其他日期字符串和划时代时间转换为毫秒。
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime
返回值:一个数字,表示自1970年1月1日午夜以来的毫秒数
现在,您可以使用chai方法“is”来验证该值是否在指定的范围内。
pm.test("Validate date to be within the expected date range", function () {
epochScheduledDateTime = 1604448930
valueGot = 1604448930 * 1000
pm.expect(valueGot).to.be.within((new Date("Tue Nov 03 2020 18:00:00 GMT-0600 (Central Standard Time)")).getTime(), (new Date("Tue Nov 03 2020 20:00:00 GMT-0600 (Central Standard Time)")).getTime());
})或比较日期:
pm.test("Validate date to be within the expected date range", function () {
pm.expect(new Date((epochScheduledDateTime) * 1000)).to.be.within((new Date("Tue Nov 2 2020 18:00:00 GMT-0600 (Central Standard Time)")), (new Date("Tue Nov 03 2020 20:00:00 GMT-0600 (Central Standard Time)")));
}) postman expect类来自chai,支持所有chai bdd断言:
https://stackoverflow.com/questions/65259670
复制相似问题