我有一个表单,允许用户输入日期范围,并且输出将仅包含该特定日期的结果。
我可以使用 .type() 函数将日期输入到表单中。但是,我不确定如何检查结果是否在指定的范围内。
例如,如果输入的日期是('17/03/2019'),我应该能够使用这样的代码检查表中的结果是否在范围内,
cy.get('.table')
.should('not.contain','18/03/2019') // This is wrong
我想比较一下产生的结果是否仅在 17/03/2019 00:00:00 和 17/03/2019 11:59:59 之间。
赛普拉斯中有此功能吗?有人可以帮忙吗?
谢谢,
因杜。
只是为了让每个人都了解所得出的解决方案赛普拉斯 Gitter 频道 https://gitter.im/cypress-io/cypress。该问题最初的回答者是格列布·巴穆托夫先生 https://twitter.com/bahmutov
此验证可以通过以下方式处理赛普拉斯时刻, where moment.js
库具有日期/时间的解析和比较方法。
// the time in the element should be between 3pm and 5pm
const start = Cypress.moment('3:00 PM', 'LT')
const end = Cypress.moment('5:00 PM', 'LT')
cy.get('.utility-moment .badge')
.should(($el) => {
// parse American time like "3:38 PM"
const m = Cypress.moment($el.text().trim(), 'LT')
// display hours + minutes + AM|PM
const f = 'h:mm A'
expect(m.isBetween(start, end),
`${m.format(f)} should be between ${start.format(f)} and ${end.format(f)}`).to.be.true
})
相关文档补充:https://github.com/cypress-io/cypress-example-kitchensink/pull/225 https://github.com/cypress-io/cypress-example-kitchensink/pull/225
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)