From afa9e81768bf65633b01a3c319c8ace5e493be07 Mon Sep 17 00:00:00 2001 From: Stephen McGruer Date: Fri, 26 Mar 2021 15:45:12 -0400 Subject: [PATCH] Add a test --- webdriver/builder_test.go | 80 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/webdriver/builder_test.go b/webdriver/builder_test.go index b1a2ff873ad..eaec8968020 100644 --- a/webdriver/builder_test.go +++ b/webdriver/builder_test.go @@ -9,6 +9,7 @@ package webdriver import ( "fmt" "testing" + "strings" mapset "github.com/deckarep/golang-set" "github.com/stretchr/testify/assert" @@ -16,6 +17,85 @@ import ( "github.com/web-platform-tests/wpt.fyi/shared" ) +func TestQueryBuilder_AddEdgeAnchor(t* testing.T) { + // Tests that the 'add Edge' button added for + // https://github.com/web-platform-tests/wpt.fyi/issues/1519 is shown + // and that clicking it has the desired effect. + runWebdriverTest(t, func(t *testing.T, app AppServer, wd selenium.WebDriver) { + t.Run("Shown", func(t* testing.T) { + testEdgeAnchor(t, app, wd, true) + }) + + t.Run("Hidden", func(t* testing.T) { + testEdgeAnchor(t, app, wd, false) + }) + }) +} + +func testEdgeAnchor(t *testing.T, app AppServer, wd selenium.WebDriver, shouldBeShown bool) { + // Navigate to the wpt.fyi homepage. + url := "/results" + if !shouldBeShown { + url += "?product=chrome&product=firefox" + } + + var err error + if err = wd.Get(app.GetWebappURL(url)); err != nil { + assert.FailNow(t, fmt.Sprintf("Failed to load %s: %s", url, err.Error())) + } + + // Wait for the page to load. + var e selenium.WebElement + loaded := func(wd selenium.WebDriver) (bool, error) { + e, err = wd.FindElement(selenium.ByTagName, "wpt-app") + if err != nil { + return false, err + } + return e != nil, nil + } + if err = wd.WaitWithTimeout(loaded, LongTimeout); err != nil { + assert.FailNow(t, fmt.Sprintf("Error waiting for wpt-app to load: %s", err.Error())) + } + + // Find the 'add Edge' anchor. + anchors, err := FindShadowElements(wd, e, "info-banner > a") + if err != nil { + assert.FailNow(t, fmt.Sprintf("Error when locating info-banner anchors: %s", err.Error())) + } + var edgeAnchor selenium.WebElement + foundEdgeAnchor := false + for _, anchor := range anchors { + text, err := anchor.Text() + if err != nil { + assert.FailNow(t, fmt.Sprintf("Error when loading Text() for element: %s", err.Error())) + } + + if strings.Contains(text, "add Microsoft Edge back") { + edgeAnchor = anchor + foundEdgeAnchor = true + break + } + } + + if !shouldBeShown { + assert.False(t, foundEdgeAnchor) + return + } + assert.True(t, foundEdgeAnchor) + + // Now click on the anchor and make sure it loads the page with params. + err = edgeAnchor.Click() + if err != nil { + assert.FailNow(t, fmt.Sprintf("Error when clicking on anchor: %s", err.Error())) + } + + newUrl, err := wd.CurrentURL() + if err != nil { + assert.FailNow(t, fmt.Sprintf("Error when getting current url: %s", err.Error())) + } + assert.Contains(t, newUrl, "product=edge") +} + func TestQueryBuilder_MasterCheckedForMasterLabelQuery(t *testing.T) { runWebdriverTest(t, func(t *testing.T, app AppServer, wd selenium.WebDriver) { // Navigate to the wpt.fyi homepage.