From 879525faac9aed4be45d6175028d604efa056eba Mon Sep 17 00:00:00 2001 From: Matt Moyer Date: Wed, 2 Dec 2020 17:20:24 -0600 Subject: [PATCH] Clean up the browsertest package a bit. Signed-off-by: Matt Moyer --- test/library/browsertest/browsertest.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/test/library/browsertest/browsertest.go b/test/library/browsertest/browsertest.go index 9a50e780..d7da8142 100644 --- a/test/library/browsertest/browsertest.go +++ b/test/library/browsertest/browsertest.go @@ -15,6 +15,11 @@ import ( "go.pinniped.dev/test/library" ) +const ( + operationTimeout = 10 * time.Second + operationPollingInterval = 100 * time.Millisecond +) + // Open a webdriver-driven browser and returns an *agouti.Page to control it. The browser will be automatically // closed at the end of the current test. It is configured for test purposes with the correct HTTP proxy and // in a mode that ignore certificate errors. @@ -53,7 +58,8 @@ func Open(t *testing.T) *agouti.Page { // to occur and times out, failing the test, if they never appear. func WaitForVisibleElements(t *testing.T, page *agouti.Page, selectors ...string) { t.Helper() - require.Eventually(t, + + require.Eventuallyf(t, func() bool { for _, sel := range selectors { vis, err := page.First(sel).Visible() @@ -63,8 +69,10 @@ func WaitForVisibleElements(t *testing.T, page *agouti.Page, selectors ...string } return true }, - 10*time.Second, - 100*time.Millisecond, + operationTimeout, + operationPollingInterval, + "expected to have a page with selectors %v, but it never loaded", + selectors, ) } @@ -84,8 +92,8 @@ func WaitForURL(t *testing.T, page *agouti.Page, pat *regexp.Regexp) { } return false }, - 10*time.Second, - 100*time.Millisecond, + operationTimeout, + operationPollingInterval, "expected to browse to %s, but never got there", pat, )