collapse a few Navigate actions in the tests

This commit is contained in:
Daniel Martí 2019-03-20 12:05:04 +00:00
parent 24decf54d3
commit 92bfcc3c8d
2 changed files with 15 additions and 47 deletions

View File

@ -11,13 +11,9 @@ import (
func TestNavigate(t *testing.T) { func TestNavigate(t *testing.T) {
t.Parallel() t.Parallel()
ctx, cancel := testAllocate(t, "") ctx, cancel := testAllocate(t, "image.html")
defer cancel() defer cancel()
expurl, exptitle := testdataDir+"/image.html", "this is title"
if err := Run(ctx, Navigate(expurl)); err != nil {
t.Fatal(err)
}
if err := Run(ctx, WaitVisible(`#icon-brankas`, ByID)); err != nil { if err := Run(ctx, WaitVisible(`#icon-brankas`, ByID)); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -27,7 +23,7 @@ func TestNavigate(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
if !strings.HasPrefix(urlstr, expurl) { if !strings.HasSuffix(urlstr, "image.html") {
t.Errorf("expected to be on image.html, at: %s", urlstr) t.Errorf("expected to be on image.html, at: %s", urlstr)
} }
@ -36,6 +32,7 @@ func TestNavigate(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
exptitle := "this is title"
if title != exptitle { if title != exptitle {
t.Errorf("expected title to contain google, instead title is: %s", title) t.Errorf("expected title to contain google, instead title is: %s", title)
} }
@ -92,15 +89,11 @@ func TestNavigationEntries(t *testing.T) {
func TestNavigateToHistoryEntry(t *testing.T) { func TestNavigateToHistoryEntry(t *testing.T) {
t.Parallel() t.Parallel()
ctx, cancel := testAllocate(t, "") ctx, cancel := testAllocate(t, "image.html")
defer cancel() defer cancel()
var entries []*page.NavigationEntry var entries []*page.NavigationEntry
var index int64 var index int64
if err := Run(ctx, Navigate(testdataDir+"/image.html")); err != nil {
t.Fatal(err)
}
time.Sleep(50 * time.Millisecond) time.Sleep(50 * time.Millisecond)
if err := Run(ctx, NavigationEntries(&index, &entries)); err != nil { if err := Run(ctx, NavigationEntries(&index, &entries)); err != nil {
t.Fatal(err) t.Fatal(err)
@ -130,12 +123,8 @@ func TestNavigateToHistoryEntry(t *testing.T) {
func TestNavigateBack(t *testing.T) { func TestNavigateBack(t *testing.T) {
t.Parallel() t.Parallel()
ctx, cancel := testAllocate(t, "") ctx, cancel := testAllocate(t, "form.html")
defer cancel() defer cancel()
if err := Run(ctx, Navigate(testdataDir+"/form.html")); err != nil {
t.Fatal(err)
}
time.Sleep(50 * time.Millisecond) time.Sleep(50 * time.Millisecond)
var exptitle string var exptitle string
@ -167,12 +156,8 @@ func TestNavigateBack(t *testing.T) {
func TestNavigateForward(t *testing.T) { func TestNavigateForward(t *testing.T) {
t.Parallel() t.Parallel()
ctx, cancel := testAllocate(t, "") ctx, cancel := testAllocate(t, "form.html")
defer cancel() defer cancel()
if err := Run(ctx, Navigate(testdataDir+"/form.html")); err != nil {
t.Fatal(err)
}
time.Sleep(50 * time.Millisecond) time.Sleep(50 * time.Millisecond)
if err := Run(ctx, Navigate(testdataDir+"/image.html")); err != nil { if err := Run(ctx, Navigate(testdataDir+"/image.html")); err != nil {
t.Fatal(err) t.Fatal(err)
@ -208,25 +193,18 @@ func TestNavigateForward(t *testing.T) {
func TestStop(t *testing.T) { func TestStop(t *testing.T) {
t.Parallel() t.Parallel()
ctx, cancel := testAllocate(t, "") ctx, cancel := testAllocate(t, "form.html")
defer cancel() defer cancel()
if err := Run(ctx, Navigate(testdataDir+"/form.html")); err != nil {
t.Fatal(err)
}
if err := Run(ctx, Stop()); err != nil { if err := Run(ctx, Stop()); err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }
func TestReload(t *testing.T) { func TestReload(t *testing.T) {
t.Parallel() t.Parallel()
ctx, cancel := testAllocate(t, "") ctx, cancel := testAllocate(t, "form.html")
defer cancel() defer cancel()
if err := Run(ctx, Navigate(testdataDir+"/form.html")); err != nil {
t.Fatal(err)
}
time.Sleep(50 * time.Millisecond) time.Sleep(50 * time.Millisecond)
@ -254,11 +232,8 @@ func TestReload(t *testing.T) {
func TestCaptureScreenshot(t *testing.T) { func TestCaptureScreenshot(t *testing.T) {
t.Parallel() t.Parallel()
ctx, cancel := testAllocate(t, "") ctx, cancel := testAllocate(t, "image.html")
defer cancel() defer cancel()
if err := Run(ctx, Navigate(testdataDir+"/image.html")); err != nil {
t.Fatal(err)
}
time.Sleep(50 * time.Millisecond) time.Sleep(50 * time.Millisecond)
@ -330,13 +305,8 @@ func TestRemoveOnLoadScript(t *testing.T) {
func TestLocation(t *testing.T) { func TestLocation(t *testing.T) {
t.Parallel() t.Parallel()
expurl := testdataDir + "/form.html" ctx, cancel := testAllocate(t, "form.html")
ctx, cancel := testAllocate(t, "")
defer cancel() defer cancel()
if err := Run(ctx, Navigate(expurl)); err != nil {
t.Fatal(err)
}
time.Sleep(50 * time.Millisecond) time.Sleep(50 * time.Millisecond)
@ -345,7 +315,7 @@ func TestLocation(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
if urlstr != expurl { if !strings.HasSuffix(urlstr, "form.html") {
t.Fatalf("expected to be on form.html, got: %s", urlstr) t.Fatalf("expected to be on form.html, got: %s", urlstr)
} }
} }
@ -353,13 +323,8 @@ func TestLocation(t *testing.T) {
func TestTitle(t *testing.T) { func TestTitle(t *testing.T) {
t.Parallel() t.Parallel()
expurl, exptitle := testdataDir+"/image.html", "this is title" ctx, cancel := testAllocate(t, "image.html")
ctx, cancel := testAllocate(t, "")
defer cancel() defer cancel()
if err := Run(ctx, Navigate(expurl)); err != nil {
t.Fatal(err)
}
time.Sleep(50 * time.Millisecond) time.Sleep(50 * time.Millisecond)
@ -368,6 +333,7 @@ func TestTitle(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
exptitle := "this is title"
if title != exptitle { if title != exptitle {
t.Fatalf("expected title to be %s, got: %s", exptitle, title) t.Fatalf("expected title to be %s, got: %s", exptitle, title)
} }

View File

@ -946,6 +946,8 @@ func TestFileUpload(t *testing.T) {
// parallel // parallel
//t.Parallel() //t.Parallel()
// TODO: check why moving the Navigate action below to
// testAllocate makes this test hang.
ctx, cancel := testAllocate(t, "") ctx, cancel := testAllocate(t, "")
defer cancel() defer cancel()