World’s largest virtual agentic engineering & quality conference
Test your full two-factor authentication flow, TOTP codes, backup codes, lockouts, and trusted devices, in plain English. No Selenium, no Playwright, no code.

Devansh Bhardwaj
Author

Salman Khan
Reviewer
Last Updated on: July 21, 2026
Two-factor authentication is the last checkpoint between an attacker and your users' accounts, and it can fail in both directions. A code that never arrives, or a verification screen that rejects a valid code, locks legitimate users out of their own data. A second factor that can be skipped hands the account to whoever guessed the password. Both stay invisible until someone is stuck at the OTP prompt or a breach report lands.
Every SMS gateway, authenticator app, backup code, and rate limit is another place the flow can break, and it breaks differently on every browser and device your customers carry. The traditional fix is automated testing. The traditional problem is that automated testing means code.
A one-time code looks like a single extra field, but real coverage has to touch every channel, every timing edge, and every way the second factor can fail:
And that is one account. Real coverage means enrolled users vs. first-time enrollment, mobile vs. desktop, and every browser your customers actually sign in from.
Here is what verifying a sign-in with a one-time code looks like in a typical Selenium setup, with a TOTP library bolted on to produce the code:
wait = WebDriverWait(driver, 10)
driver.get("https://yourapp.com/login")
wait.until(EC.presence_of_element_located((By.ID, "email"))).send_keys("test.user@example.com")
driver.find_element(By.ID, "password").send_keys("SuperSecret123")
driver.find_element(By.CSS_SELECTOR, "button[type='submit']").click()
otp = pyotp.TOTP("JBSWY3DPEHPK3PXP").now()
code_field = wait.until(EC.presence_of_element_located((By.ID, "otp")))
code_field.send_keys(otp)
driver.find_element(By.CSS_SELECTOR, "button.verify-code").click()
wait.until(EC.url_contains("/dashboard"))
assert "Dashboard" in driver.title, f"2FA failed, still on: {driver.title}"Eleven lines, and every one is a liability. The hardcoded secret has to stay in sync with the account, the code-field selector breaks the moment the verification screen is redesigned, and the fixed timeout races the thirty-second code window. Maintenance like this is the dominant cost of a large automation suite, where engineers spend a large share of every sprint re-pointing selectors and re-wiring the code generator instead of writing new coverage. It also assumes someone on the team writes Python or JavaScript and understands how TOTP works, which is exactly the skill most manual QA teams do not have. It is the core tradeoff behind code-based vs. codeless test automation.
If you are a manual QA engineer, a PM, or a founder without a dedicated automation engineer, the code wall means 2FA usually gets tested with a phone in one hand, slowly, inconsistently, and never across every browser before a release.
With KaneAI, you write the same test in plain English:
That is the entire test. KaneAI reads each step, finds the email, password, and code fields on your live site the way a human tester would, by understanding the page rather than matching brittle CSS selectors, and runs the flow end to end. The part that normally needs a scripting library is built in: KaneAI generates the TOTP code directly from your secret key, so an MFA-protected flow is testable in a single pass with no external authenticator app or phone. When your team redesigns the verification screen or renames the code field, its self-healing re-anchors the step instead of breaking, which significantly reduces maintenance. And the generated code behaves identically across replay, exported Selenium or Playwright, and a scheduled CI run.

Once the happy path works, real coverage is just more English. Here are the two-factor scenarios worth adding, each takes about two minutes to write:
Run all of them across Chrome, Safari, Firefox, and real mobile devices from the same plain-English steps, with no per-browser rewrites.
Two-factor tests are most valuable when they run without you:
When a test fails, you do not get a stack-trace exception at line 47. You get a plain-English reason for the exact step that failed. Anyone on the team can read it, and anyone can fix the test, because the test is just English.
Your second factor is too important to test by hand and too dynamic for brittle scripts. Test it in the language you already speak. Once 2FA is covered, read how to test email workflows so the codes and reset links your users receive stay reliable, and how to test single sign-on (SSO) for the teams that reach your app through an identity provider.
Note: Test your two-factor authentication flow without writing a line of code. Start with KaneAI free.
Author
Devansh Bhardwaj is a Community Evangelist at TestMu AI with 4+ years of experience in the tech industry. He has authored 30+ technical blogs on web development and automation testing and holds certifications in Automation Testing, KaneAI, Selenium, Appium, Playwright, and Cypress. Devansh has contributed to end-to-end testing of a major banking application, spanning UI, API, mobile, visual, and cross-browser testing, demonstrating hands-on expertise across modern testing workflows.
Reviewer
Salman is a Test Automation Evangelist and Community Contributor at TestMu AI, with over 6 years of hands-on experience in software testing and automation. He has completed his Master of Technology in Computer Science and Engineering, demonstrating strong technical expertise in software development, testing, AI agents and LLMs. He is certified in KaneAI, Automation Testing, Selenium, Cypress, Playwright, and Appium, with deep experience in CI/CD pipelines, cross-browser testing, AI in testing, and mobile automation. Salman works closely with engineering teams to convert complex testing concepts into actionable, developer-first content. Salman has authored 120+ technical tutorials, guides, and documentation on test automation, web development, and related domains, making him a strong voice in the QA and testing community.
Did you find this page helpful?
More Related Blogs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance