我正在赛普拉斯中创建一个会定期运行的验收测试,并且我需要它输入从日期选择器(如果重要的话,请回答)中的日期作为创建对象(文章)之日起的1年1个月和1天。 。例如,今天是2020年4月22日,我想在今天创建的文章中获得2021年5月23日的价值,明天则是2021年5月24日的价值,等等。有人可以分享设置它的想法吗?老实说,我谷歌搜索,我自己也没有想法,因为我对赛普拉斯很陌生,只对非常简单的事情有信心。:)
我猜想大多数日期选择器都会有一个input
可以输入日期的元素。
假设应用程序使用库日期选择器(因此您不需要通过单击按钮来测试日期的选择),则可以定位该元素并使用Cypress.type()
命令输入将来的日期。
例如,Material UI日期选择器文档具有此输入元素
<input aria-invalid="false"
id="date-picker-inline"
type="text"
class="MuiInputBase-input MuiInput-input MuiInputBase-inputAdornedEnd"
value="08/18/2014">
所以这些步骤就像
cy.visit('https://material-ui.com/components/pickers');
const targetDate = Cypress.moment()
.add(1, 'year')
.add(1, 'month')
.add(1, 'day')
.format('MM/DD/YYYY') // adjust format to suit the apps requirements
cy.get('input[id="date-picker-inline"]')
.clear()
.type(`${targetDate}{enter}`) // presume you need the enter key to trigger an event
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句