Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenmcgruer committed Mar 26, 2021
1 parent 7b0e007 commit afa9e81
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions webdriver/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,93 @@ package webdriver
import (
"fmt"
"testing"
"strings"

mapset "github.com/deckarep/golang-set"
"github.com/stretchr/testify/assert"
"github.com/tebeka/selenium"
"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.
Expand Down

0 comments on commit afa9e81

Please sign in to comment.