Skip to content

Commit e1e0544

Browse files
Add a test
1 parent 7b0e007 commit e1e0544

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

webdriver/builder_test.go

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,120 @@ package webdriver
99
import (
1010
"fmt"
1111
"testing"
12+
"strings"
1213

1314
mapset "github.com/deckarep/golang-set"
1415
"github.com/stretchr/testify/assert"
1516
"github.com/tebeka/selenium"
1617
"github.com/web-platform-tests/wpt.fyi/shared"
1718
)
1819

20+
func TestQueryBuilder_AddEdgeShown(t* testing.T) {
21+
// Tests that the 'add Edge' button added for
22+
// https://github.com/web-platform-tests/wpt.fyi/issues/1519 is shown
23+
// and that clicking it has the desired effect.
24+
runWebdriverTest(t, func(t *testing.T, app AppServer, wd selenium.WebDriver) {
25+
// Navigate to the wpt.fyi homepage.
26+
url := "/results"
27+
var err error
28+
if err = wd.Get(app.GetWebappURL(url)); err != nil {
29+
assert.FailNow(t, fmt.Sprintf("Failed to load %s: %s", url, err.Error()))
30+
}
31+
32+
// Wait for the page to load.
33+
var e selenium.WebElement
34+
loaded := func(wd selenium.WebDriver) (bool, error) {
35+
e, err = wd.FindElement(selenium.ByTagName, "wpt-app")
36+
if err != nil {
37+
return false, err
38+
}
39+
return e != nil, nil
40+
}
41+
if err = wd.WaitWithTimeout(loaded, LongTimeout); err != nil {
42+
assert.FailNow(t, fmt.Sprintf("Error waiting for wpt-app to load: %s", err.Error()))
43+
}
44+
45+
// Make sure the 'add Edge' link is shown.
46+
anchors, err := FindShadowElements(wd, e, "info-banner > a")
47+
if err != nil {
48+
assert.FailNow(t, fmt.Sprintf("Error when locating info-banner anchors: %s", err.Error()))
49+
}
50+
var edgeAnchor selenium.WebElement
51+
foundEdgeAnchor := false
52+
for _, anchor := range anchors {
53+
text, err := anchor.Text()
54+
if err != nil {
55+
assert.FailNow(t, fmt.Sprintf("Error when loading Text() for element: %s", err.Error()))
56+
}
57+
58+
if strings.Contains(text, "add Microsoft Edge back") {
59+
edgeAnchor = anchor
60+
foundEdgeAnchor = true
61+
break
62+
}
63+
}
64+
assert.True(t, foundEdgeAnchor)
65+
66+
// Now click on the anchor and make sure it loads the page with params.
67+
err = edgeAnchor.Click()
68+
if err != nil {
69+
assert.FailNow(t, fmt.Sprintf("Error when clicking on anchor: %s", err.Error()))
70+
}
71+
72+
newUrl, err := wd.CurrentURL()
73+
if err != nil {
74+
assert.FailNow(t, fmt.Sprintf("Error when getting current url: %s", err.Error()))
75+
}
76+
assert.Contains(t, newUrl, "product=edge")
77+
})
78+
}
79+
80+
func TestQueryBuilder_AddEdgeHidden(t* testing.T) {
81+
// Tests that the 'add Edge' button added for
82+
// https://github.com/web-platform-tests/wpt.fyi/issues/1519 is not
83+
// shown when a product is selected.
84+
runWebdriverTest(t, func(t *testing.T, app AppServer, wd selenium.WebDriver) {
85+
// Navigate to the wpt.fyi homepage.
86+
url := "/results?product=chrome&product=firefox"
87+
var err error
88+
if err = wd.Get(app.GetWebappURL(url)); err != nil {
89+
assert.FailNow(t, fmt.Sprintf("Failed to load %s: %s", url, err.Error()))
90+
}
91+
92+
// Wait for the page to load.
93+
var e selenium.WebElement
94+
loaded := func(wd selenium.WebDriver) (bool, error) {
95+
e, err = wd.FindElement(selenium.ByTagName, "wpt-app")
96+
if err != nil {
97+
return false, err
98+
}
99+
return e != nil, nil
100+
}
101+
if err := wd.WaitWithTimeout(loaded, LongTimeout); err != nil {
102+
assert.FailNow(t, fmt.Sprintf("Error waiting for wpt-app to load: %s", err.Error()))
103+
}
104+
105+
// Make sure the 'add Edge' link is not shown.
106+
anchors, err := FindShadowElements(wd, e, "info-banner > a")
107+
if err != nil {
108+
assert.FailNow(t, fmt.Sprintf("Error when locating info-banner anchors: %s", err.Error()))
109+
}
110+
foundEdgeAnchor := false
111+
for _, anchor := range anchors {
112+
text, err := anchor.Text()
113+
if err != nil {
114+
assert.FailNow(t, fmt.Sprintf("Error when loading Text() for element: %s", err.Error()))
115+
}
116+
117+
if strings.Contains(text, "add Microsoft Edge back") {
118+
foundEdgeAnchor = true
119+
break
120+
}
121+
}
122+
assert.False(t, foundEdgeAnchor)
123+
})
124+
}
125+
19126
func TestQueryBuilder_MasterCheckedForMasterLabelQuery(t *testing.T) {
20127
runWebdriverTest(t, func(t *testing.T, app AppServer, wd selenium.WebDriver) {
21128
// Navigate to the wpt.fyi homepage.

0 commit comments

Comments
 (0)