如何期望日期在赛普拉斯中包含另一个日期?
How to expect the date to contain another date in Cypress?
这是我在这里问的最愚蠢的问题。我正在经历赛普拉斯自动化并正在处理其中一个场景。
我想验证日期是否匹配或包含日期。
系统日期 - 11/30/2021 06:18:33 PM
和衍生申请日期 - 11/30/2021 6:18:38
我如何使用 Cypress 匹配和声明它?
expect('11/30/2021 06:18:33 PM').to.have.string('11/30/2021 6:18:38');
我遇到以下错误:-
AssertionError
expected '11/30/2021 06:18:33 PM' to contain '11/30/2021 6:18:38'
您可以使用 to.include
,例如:
expect('11/30/2021 06:18:33 PM').to.include('11/30/2021 06:18:33')
或者如果您只想匹配日期,您可以这样做。使用 split
我们只提取日期并声明它。
expect('11/30/2021 06:18:33 PM'.split(' ')[0]).to.equal(
'11/30/2021 06:18:33'.split(' ')[0]
)
这是我在这里问的最愚蠢的问题。我正在经历赛普拉斯自动化并正在处理其中一个场景。
我想验证日期是否匹配或包含日期。
系统日期 - 11/30/2021 06:18:33 PM
和衍生申请日期 - 11/30/2021 6:18:38
我如何使用 Cypress 匹配和声明它?
expect('11/30/2021 06:18:33 PM').to.have.string('11/30/2021 6:18:38');
我遇到以下错误:-
AssertionError
expected '11/30/2021 06:18:33 PM' to contain '11/30/2021 6:18:38'
您可以使用 to.include
,例如:
expect('11/30/2021 06:18:33 PM').to.include('11/30/2021 06:18:33')
或者如果您只想匹配日期,您可以这样做。使用 split
我们只提取日期并声明它。
expect('11/30/2021 06:18:33 PM'.split(' ')[0]).to.equal(
'11/30/2021 06:18:33'.split(' ')[0]
)