Pre*_*i D 3 authentication cypress
我想要登录帐户,但我收到了 2FA,为了确认新设备,我的收件箱中收到了电子邮件,但我无法登录帐户。
任何人,你能告诉我如何处理这个问题,或者我是否可以在 Cypress 中使用 MailSlurp 做一些事情吗?
简而言之,我想打开网站,填写用户名、密码,并成功登录帐户,即使弹出 2FA 对话框,其中 2FA 确认电子邮件正在进入我的电子邮件收件箱。
预先致谢,感谢您的帮助。
最好的,Preeti D
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/');
})
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1485 次 |
| 最近记录: |