rewrite TestReload without a sleep
This commit is contained in:
parent
f742f327a7
commit
2b925df0fb
30
nav_test.go
30
nav_test.go
|
@ -2,11 +2,13 @@ package chromedp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/chromedp/cdproto/emulation"
|
"github.com/chromedp/cdproto/emulation"
|
||||||
"github.com/chromedp/cdproto/page"
|
"github.com/chromedp/cdproto/page"
|
||||||
|
@ -188,19 +190,33 @@ func TestStop(t *testing.T) {
|
||||||
func TestReload(t *testing.T) {
|
func TestReload(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
ctx, cancel := testAllocate(t, "form.html")
|
count := 0
|
||||||
|
// create test server
|
||||||
|
mux := http.NewServeMux()
|
||||||
|
mux.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
|
||||||
|
fmt.Fprintf(res, `<html>
|
||||||
|
<head>
|
||||||
|
<title>Title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="count%d"></div>
|
||||||
|
</body></html`, count)
|
||||||
|
count++
|
||||||
|
})
|
||||||
|
s := httptest.NewServer(mux)
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
|
ctx, cancel := testAllocate(t, "")
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
var title, exptitle string
|
var title, exptitle string
|
||||||
if err := Run(ctx, Tasks{
|
if err := Run(ctx, Tasks{
|
||||||
WaitVisible(`#form`, ByID), // for form.html
|
Navigate(s.URL),
|
||||||
|
WaitReady(`#count0`, ByID),
|
||||||
Title(&exptitle),
|
Title(&exptitle),
|
||||||
|
|
||||||
Reload(),
|
Reload(),
|
||||||
// TODO: rewrite test to change the content after a reload, so
|
WaitReady(`#count1`, ByID),
|
||||||
// we can wait on a selector.
|
|
||||||
Sleep(10 * time.Millisecond),
|
|
||||||
WaitVisible(`#form`, ByID), // for form.html
|
|
||||||
Title(&title),
|
Title(&title),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
|
@ -960,8 +960,6 @@ 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()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user