Skip to content

Commit

Permalink
Fix tests now that Firefox latest returns the correct expiry date
Browse files Browse the repository at this point in the history
  • Loading branch information
minusnine committed Aug 21, 2017
1 parent 988bde7 commit 1288122
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 72 deletions.
85 changes: 16 additions & 69 deletions remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,20 @@ func testFirefoxPreferences(t *testing.T, c config) {
t.Fatalf("error in new session - %s", err)
}

u, err := wd.CurrentURL()
if err != nil {
t.Fatalf("wd.Current() returned error: %v", err)
}
if u != serverURL+"/" {
t.Fatalf("wd.Current() = %q, want %q", u, serverURL+"/")
// TODO(minusnine): use the upcoming Wait API for this.
var u string
for i := 0; i < 5; i++ {
var err error
u, err = wd.CurrentURL()
if err != nil {
t.Fatalf("wd.Current() returned error: %v", err)
}
if u == serverURL+"/" {
return
}
time.Sleep(time.Second)
}
t.Fatalf("wd.Current() = %q, want %q", u, serverURL+"/")
}

func testFirefoxProfile(t *testing.T, c config) {
Expand Down Expand Up @@ -494,7 +501,6 @@ func runTests(t *testing.T, c config) {
t.Run("CSSProperty", runTest(testCSSProperty, c))
t.Run("Proxy", runTest(testProxy, c))
t.Run("SwitchFrame", runTest(testSwitchFrame, c))
t.Run("Wait", runTest(testWait, c))
t.Run("ActiveElement", runTest(testActiveElement, c))
}

Expand Down Expand Up @@ -1057,16 +1063,9 @@ func testAddCookie(t *testing.T, c config) {
want.Path = "/"
want.Domain = "127.0.0.1"

if c.browser == "firefox" && (c.seleniumVersion.Major == 3 || c.seleniumVersion.Major == 0) {
// Geckodriver does not return the valid expiration date for the cookie.
// https://github.com/mozilla/geckodriver/issues/463
t.Log("Working around https://github.com/mozilla/geckodriver/issues/463")
want.Expiry = 0

// Firefox and Geckodriver now also returns an empty string for the path.
if c.seleniumVersion.Major == 0 {
want.Path = ""
}
// Firefox and Geckodriver returns an empty string for the path.
if c.browser == "firefox" && c.seleniumVersion.Major == 0 {
want.Path = ""
}

cookies, err := wd.GetCookies()
Expand Down Expand Up @@ -1634,42 +1633,6 @@ func testSwitchFrame(t *testing.T, c config) {
}
}

func testWait(t *testing.T, c config) {
const newTitle = "Title changed."
titleChangeCondition := func(wd WebDriver) (bool, error) {
title, err := wd.Title()
if err != nil {
return false, err
}

return title == newTitle, nil
}

wd := newRemote(t, c)
defer quitRemote(t, wd)

titleURL := serverURL + "/title"

if err := wd.Get(titleURL); err != nil {
t.Fatalf("wd.Get(%q) returned error: %v", titleURL, err)
}

// Testing when the title should change.
if err := wd.Wait(titleChangeCondition); err != nil {
t.Fatalf("wd.Wait(titleChangeCondition) returned error: %v", err)
}

// Reloading the page.
if err := wd.Get(titleURL); err != nil {
t.Fatalf("wd.Get(%q) returned error: %v", titleURL, err)
}

// Testing when the Wait() should error the timeout..
if err := wd.WaitWithTimeout(titleChangeCondition, 500*time.Millisecond); err == nil {
t.Fatalf("wd.Wait(titleChangeCondition) should returned error, but it didn't.")
}
}

var homePage = `
<html>
<head>
Expand Down Expand Up @@ -1745,21 +1708,6 @@ var framePage = `
</html>
`

var titleChangePage = `
<html>
<head>
<title>Go Selenium Test Suite - Title Change Page</title>
</head>
<body>
This page will change a title after 1 second.
<script>
setTimeout(function() { document.title = 'Title changed.' }, 1000);
</script>
</body>
</html>
`

func handler(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
page, ok := map[string]string{
Expand All @@ -1768,7 +1716,6 @@ func handler(w http.ResponseWriter, r *http.Request) {
"/search": searchPage,
"/log": logPage,
"/frame": framePage,
"/title": titleChangePage,
}[path]
if !ok {
http.NotFound(w, r)
Expand Down
1 change: 1 addition & 0 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ type Service struct {

// NewSeleniumService starts a Selenium instance in the background.
func NewSeleniumService(jarPath string, port int, opts ...ServiceOption) (*Service, error) {
// TODO(minusnine): allow specifying the path to the JRE.
cmd := exec.Command("java", "-jar", jarPath, "-port", strconv.Itoa(port))
s, err := newService(cmd, port, opts...)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions vendor/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ var files = []file{
},
{
// This is a recent nightly. Update this path periodically.
url: "https://archive.mozilla.org/pub/firefox/nightly/2017/05/2017-05-08-10-02-18-mozilla-central/firefox-55.0a1.en-US.linux-x86_64.tar.bz2",
name: "firefox-55.0a1.en-US.linux-x86_64.tar.bz2",
hash: "88b08469e055014fc2e9b6c43aeacb2b52a028e16acd96854f03523fbd9a9148",
url: "https://archive.mozilla.org/pub/firefox/nightly/2017/08/2017-08-21-10-03-50-mozilla-central/firefox-57.0a1.en-US.linux-x86_64.tar.bz2",
name: "firefox-57.0a1.en-US.linux-x86_64.tar.bz2",
hash: "77c57356935f66a5a59b1b2cffeaa53b70204195e6a7b15ee828fd3308561e46",
browser: true,
rename: []string{"firefox", "firefox-nightly"},
},
Expand Down

0 comments on commit 1288122

Please sign in to comment.