-
Notifications
You must be signed in to change notification settings - Fork 2
/
builder_test.go
42 lines (38 loc) · 986 Bytes
/
builder_test.go
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
package chromebot_test
import (
"testing"
"time"
"github.com/chromedp/chromedp"
"github.com/nanitefactory/chromebot"
)
func TestBuilder(t *testing.T) {
c := chromebot.NewBuilder().
WithFlags(chromebot.DefaultBuilderFlags).
WithExecAllocatorOption(
chromedp.DisableGPU,
chromedp.Flag("headless", bFlagHeadless),
).
WithBrowserOption().
WithContextOption().
NewChrome()
defer c.Close()
c.AddNewTab()
c.AddNewTab()
time.Sleep(time.Second * 1)
}
func TestBuilderDeadline(t *testing.T) {
c := chromebot.NewBuilder().WithFlags(func() chromebot.BuilderFlags {
optFlags := chromebot.DefaultBuilderFlags
optFlags.Headless = bFlagHeadless
optFlags.MuteAudio = bFlagHeadless
optFlags.HideScrollbars = bFlagHeadless
return optFlags
}()).WithDeadline(time.Now().Add(time.Second * 3)).NewChrome()
c.AddNewTab()
c.AddNewTab()
c.AddNewTab()
<-c.Dead()
if nTabs := c.CountTabs(); nTabs != 4 {
panic(nTabs)
}
}