Home > Back-end >  Cannot automate Playwright tests with GitHub authentication - prompted to email code verification
Cannot automate Playwright tests with GitHub authentication - prompted to email code verification

Time:02-04

I'm writing automation tests for my web application. One of the step is to complete authentication in my app. To do so, there is a button for GitHub authentication. I'm using GitHub OAuth app.

When my automation test runs, I successfully fill the account details: username & password. However, after completing this step, it requires me to enter verification code sent to my email from GitHub. This prevents me from completing the test.

If I take a look in this documentation: enter image description here

CodePudding user response:

This is pretty much standard when you're logging into GitHub and you haven't enabled two-factor authentication. The reason is that some people reuse passwords or pick commonly used passwords and this makes it harder to brute-force things.

You have a couple of choices here. First, you could create an account with 2FA using TOTP and use a TOTP library to generate the code. In all likelihood, you'll have to extract the key from the QR code, though. Note that in any case, you should avoid checking the credentials (username, password, TOTP secret) into your codebase, because if your code is ever accidentally exposed (which is quite common), your credentials will as well.

You could also set up some sort of IMAP access to the email account and read the email from the account, and fill that in.

Either way, you're going to need more than just a username and password to log into GitHub these days.

  • Related