diff --git a/test/testlib/browsertest/browsertest.go b/test/testlib/browsertest/browsertest.go index 761cdeb78..b929d3714 100644 --- a/test/testlib/browsertest/browsertest.go +++ b/test/testlib/browsertest/browsertest.go @@ -271,6 +271,11 @@ func (b *Browser) SendKeysToFirstMatch(t *testing.T, cssSelector string, runesTo b.runWithTimeout(t, b.timeout(), chromedp.SendKeys(cssSelector, runesToType, chromedp.NodeVisible, chromedp.NodeEnabled, chromedp.ByQuery)) } +func (b *Browser) ClearFirstMatch(t *testing.T, cssSelector string) { + t.Helper() + b.runWithTimeout(t, b.timeout(), chromedp.Clear(cssSelector, chromedp.NodeVisible, chromedp.NodeEnabled, chromedp.ByQuery)) +} + func (b *Browser) ClickFirstMatch(t *testing.T, cssSelector string) string { t.Helper() var text string @@ -449,6 +454,10 @@ func handleGithubOTPLoginPage(t *testing.T, b *Browser, upstream testlib.TestGit t.Logf("waiting for GitHub MFA page") b.WaitForVisibleElements(t, otpSelector) + // We may be in a loop where we are going to re-try entering the OTP code again on the same page, + // so first clear out any old OTP code that might be there from a previous attempt. + b.ClearFirstMatch(t, otpSelector) + // Sleep for a bit to make it less likely that we use the same OTP code twice when multiple tests are run in serial. // GitHub gets upset when the same OTP code gets reused. // GitHub seems to also get upset when any OTP codes are used often, like when all our GitHub tests run sequentially,