【问题标题】:How to I pass Date.now to .type() in my Cypress UI spec?如何在我的赛普拉斯 UI 规范中将 Date.now 传递给 .type()?
【发布时间】:2021-01-14 09:35:53
【问题描述】:

我正在尝试将 Date.now 传递到文本字段中(因此我的测试可以使用新数据反复运行)。我添加了以下内容,但是我运气不佳。

.type() 只接受字符串。

var num = Date.now
        var n = num.toString()
cy.get('[formcontrolname="itemValue"]').type(n)

提前致谢!

【问题讨论】:

    标签: javascript automation cypress


    【解决方案1】:

    您还没有检查num 的实际值,是吗?因为它是一个函数,而不是以毫秒为单位的日期。但是,它应该将 "function now() ..." 作为字符串输出。如果不是,那么问题出在 cypress 选择器参考中。

    如果满足以上所有条件,这应该可以完成工作:

    const num = Date.now();
    const n = num.toString();
    cy.get('[formcontrolname="itemValue"]').type(n);
    

    【讨论】:

    • 你好 Samuli - 你的回答成功了!谢谢回复:)
    • 没问题,总是乐于提供帮助:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-04
    • 1970-01-01
    • 2022-11-27
    • 2023-02-18
    • 1970-01-01
    • 2022-11-17
    相关资源
    最近更新 更多