forked from go-rod/rod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_test.go
More file actions
60 lines (46 loc) · 1.2 KB
/
setup_test.go
File metadata and controls
60 lines (46 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package rod_test
import (
"path/filepath"
"testing"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/suite"
"github.com/ysmood/kit"
"github.com/ysmood/rod"
)
var slash = filepath.FromSlash
// S test suite
type S struct {
suite.Suite
browser *rod.Browser
page *rod.Page
}
func Test(t *testing.T) {
s := new(S)
s.browser = rod.New().Trace(true).Client(nil).Connect()
defer s.browser.Close()
s.page = s.browser.Page("")
s.page.Viewport(800, 600, 1, false)
suite.Run(t, s)
}
// get abs file path from fixtures folder, return sample "file:///a/b/click.html"
func srcFile(path string) string {
return "file://" + file(path)
}
// get abs file path from fixtures folder, return sample "/a/b/click.html"
func file(path string) string {
f, err := filepath.Abs(slash(path))
kit.E(err)
return f
}
func ginHTML(body string) gin.HandlerFunc {
return func(ctx kit.GinContext) {
ctx.Header("Content-Type", "text/html;")
kit.E(ctx.Writer.WriteString(body))
}
}
func serve() (string, *gin.Engine, func()) {
srv := kit.MustServer("127.0.0.1:0")
go func() { kit.Noop(srv.Do()) }()
url := "http://" + srv.Listener.Addr().String()
return url, srv.Engine, func() { kit.E(srv.Listener.Close()) }
}