赛普拉斯(Cypress):自动进行信用卡付款测试 [英] Cypress: automatic tests for credit card payment

查看:57
本文介绍了赛普拉斯(Cypress):自动进行信用卡付款测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过信用卡进行自动测试.不幸的是,该测试在到期日期"项中未能通过我

I am doing the automatic test for payment by credit card. Unfortunately the test fails me in the Expiry Date item

我的代码:

    cy.getWithinIframe('[name="cardnumber"]').type('4242424242424242');
    cy.getWithinIframe('[name="exp-date"]').type('122024');
    cy.getWithinIframe('[name="cvc"]').type('987');

出现以下错误:

测试结束的地方

推荐答案

因此对于iframe,我们必须寻找解决方法,因为赛普拉斯不提供iframe的现成支持.

So for iframes, we have to look for workarounds as cypress doesn't provide out of the box support for iframes.

1..我们将创建一个自定义命令,该命令将帮助我们遍历iframe,并有助于代码的可重用性.在 cypress/support/command.js 下输入:

1. We will create a custom command which will help us to traverse through iframes and also helps in code reusability. Under cypress/support/command.js write:

Cypress.Commands.add('getIframe', (iframe) => {
    return cy.get(iframe)
        .its('0.contentDocument.body')
        .should('be.visible')
        .then(cy.wrap);
})

2..我看到测试有时会随机失败,因此如果我们使用

2. I saw that the tests are randomly failing sometimes, so it would be good if we use the retry option from cypress. For that go to cypress.json and write:

重试":2

此选项仅适用于cypress v5.0及更高版本.

This option will only work with cypress v5.0 and above.

3..在您的测试文件中,用于输入卡号的用途:

3. In your test file, for inputting card number use:

cy.getIframe('#stripe-card-element > .__PrivateStripeElement > iframe').click().type('4242 4242 4242 4242')

用于输入有效期的用途:

cy.getIframe('#stripe-exp-element > .__PrivateStripeElement > iframe').click().type('0921')

用于输入 CVC编号的用途:

cy.getIframe('#stripe-cvc-element > .__PrivateStripeElement > iframe').click().type('123')

这篇关于赛普拉斯(Cypress):自动进行信用卡付款测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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