OTP Verification in Playwright Without Regex (opens in new tab)
Every developer who has written a Playwright test for OTP verification has written this line: const otp = email.body.match(/\b\d{6}\b/)?.[0]; It works. Until it doesn't. The email body changes format. The OTP appears inside an HTML table. The sending service wraps it in a . Your regex matches a phone number instead of the code. The test fails intermittently and you spend an hour debugging something that has nothing to do with the feature you're testing. The regex problem OTP extraction ...
Read the original article