比较日期时间函数赛普拉斯 [英] Compare datetime function cypress

查看:79
本文介绍了比较日期时间函数赛普拉斯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格,允许用户输入日期范围,并且输出将仅具有特定日期的结果.

I have a form in which a user is allowed to enter the date range and the output will have results form that particular date alone.

我可以使用.type()函数将日期输入到表单中.但是,我不确定如何检查结果是否在指定范围内.

I am able to input the date to the form using .type() function. However, I am not sure how to check if the results are within the range specified.

例如,如果键入的日期为('17/03/2019'),我应该能够使用以下代码检查表中的结果是否在范围内

For example, if the typed date is ('17/03/2019') I should be able to check if the results in the table are within the range using a code like this,

cy.get('.table')
  .should('not.contain','18/03/2019') // This is wrong 

我想比较一下看看是否生成的结果仅在17/03/2019 00:00:00和17/03/2019 11:59:59之间.

I want to compare and see if the results produced are only between 17/03/2019 00:00:00 and 17/03/2019 11:59:59.

赛普拉斯是否提供此功能?有人可以帮忙吗?

Is this feature available in Cypress? Can somebody help, please?

谢谢,印杜(Indhu).

Thanks, Indhu.

推荐答案

只是为了让每个人都张贴在解决方案上,请到达先生回答.格莱布·巴穆托夫(Gleb Bahmutov)

Just to keep everyone posted on the solution arrived at Cypress Gitter channel. The question is originally answered by Mr. Gleb Bahmutov

此验证可以由 Cypress.moment 处理,其中 moment.js 库具有日期/时间的解析和比较方法.

This validation can be handled by Cypress.moment, where moment.js library has parsing and comparison methods for date/ time.

// 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

这篇关于比较日期时间函数赛普拉斯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆