@@ -9,13 +9,94 @@ package webdriver
99import (
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_AddEdgeAnchor (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+ // when expected, and that clicking it has the desired effect.
24+ runWebdriverTest (t , func (t * testing.T , app AppServer , wd selenium.WebDriver ) {
25+ t .Run ("Shown" , func (t * testing.T ) {
26+ testEdgeAnchor (t , app , wd , true )
27+ })
28+
29+ t .Run ("Hidden" , func (t * testing.T ) {
30+ testEdgeAnchor (t , app , wd , false )
31+ })
32+ })
33+ }
34+
35+ func testEdgeAnchor (t * testing.T , app AppServer , wd selenium.WebDriver , shouldBeShown bool ) {
36+ // Navigate to the wpt.fyi homepage.
37+ url := "/results"
38+ if ! shouldBeShown {
39+ url += "?product=chrome&product=firefox"
40+ }
41+
42+ var err error
43+ if err = wd .Get (app .GetWebappURL (url )); err != nil {
44+ assert .FailNow (t , fmt .Sprintf ("Failed to load %s: %s" , url , err .Error ()))
45+ }
46+
47+ // Wait for the page to load.
48+ var e selenium.WebElement
49+ loaded := func (wd selenium.WebDriver ) (bool , error ) {
50+ e , err = wd .FindElement (selenium .ByTagName , "wpt-app" )
51+ if err != nil {
52+ return false , err
53+ }
54+ return e != nil , nil
55+ }
56+ if err = wd .WaitWithTimeout (loaded , LongTimeout ); err != nil {
57+ assert .FailNow (t , fmt .Sprintf ("Error waiting for wpt-app to load: %s" , err .Error ()))
58+ }
59+
60+ // Find the 'add Edge' anchor.
61+ anchors , err := FindShadowElements (wd , e , "info-banner > a" )
62+ if err != nil {
63+ assert .FailNow (t , fmt .Sprintf ("Error when locating info-banner anchors: %s" , err .Error ()))
64+ }
65+ var edgeAnchor selenium.WebElement
66+ foundEdgeAnchor := false
67+ for _ , anchor := range anchors {
68+ text , err := anchor .Text ()
69+ if err != nil {
70+ assert .FailNow (t , fmt .Sprintf ("Error when loading Text() for element: %s" , err .Error ()))
71+ }
72+
73+ if strings .Contains (text , "add Microsoft Edge back" ) {
74+ edgeAnchor = anchor
75+ foundEdgeAnchor = true
76+ break
77+ }
78+ }
79+
80+ // Verify that it either is or is not shown depending on expectation.
81+ if ! shouldBeShown {
82+ assert .False (t , foundEdgeAnchor )
83+ return
84+ }
85+ assert .True (t , foundEdgeAnchor )
86+
87+ // Now click on the anchor and make sure it loads the page with params.
88+ err = edgeAnchor .Click ()
89+ if err != nil {
90+ assert .FailNow (t , fmt .Sprintf ("Error when clicking on anchor: %s" , err .Error ()))
91+ }
92+
93+ newUrl , err := wd .CurrentURL ()
94+ if err != nil {
95+ assert .FailNow (t , fmt .Sprintf ("Error when getting current url: %s" , err .Error ()))
96+ }
97+ assert .Contains (t , newUrl , "product=edge" )
98+ }
99+
19100func TestQueryBuilder_MasterCheckedForMasterLabelQuery (t * testing.T ) {
20101 runWebdriverTest (t , func (t * testing.T , app AppServer , wd selenium.WebDriver ) {
21102 // Navigate to the wpt.fyi homepage.
0 commit comments