2

我想登录一个帐户,但我收到 2FA 并确认新设备,我在收件箱中收到电子邮件,但我无法登录帐户。

任何人,您能告诉我如何处理这个问题,或者我是否可以在 Cypress 中使用 MailSlurp 做点什么?

简而言之,我想打开网站,填写用户名,密码,然后在弹出 2FA 对话框后成功登录帐户,其中 2FA 确认电子邮件正在进入我的电子邮件收件箱。

在此先感谢您的帮助。

最好的,Preeti D

4

1 回答 1

3

MailSlurp 很好,但您也可以使用Twilio,这是我的工作示例源代码

const accountSid = 'AC793683c4982a14f01714321bd3f90ca7';
const authToken = '819068e54369ac58bb8aad976fa517bc';
const githubEmail = 'your_github_email'
const githubPassword = 'your_github_password'

describe('Login with github credentials', () => {
    beforeEach(()=>{
        cy.visit('https://github.com/login');
        cy.get('#login_field').type(githubEmail);
        cy.get('#password').type(githubPassword);
        cy.get('input[type="submit"]').click()
    })
    it('Get SMS and apply it in 2FA form', () => {
        cy.request({
            method: 'GET',
            url: `https://api.twilio.com/2010-04-01/Accounts/${accountSid}/Messages.json`,
            auth: {
                username: accountSid,
                password: authToken,
                AuthMethod: 'BasicAuth',
            }
        })
            .its('body').then((res) => {
            cy.wait(1500) //wait for SMS
            const otpcode = res.messages[0].body.substring(0, 6)
            cy.get('#otp').type(otpcode);
            cy.url().should('eq', 'https://github.com/');
        })
    });
});

于 2021-12-17T19:31:11.523 回答