-
Notifications
You must be signed in to change notification settings - Fork 10
/
playwright_test.go
108 lines (94 loc) · 2.53 KB
/
playwright_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package playwright
import (
"fmt"
"math/rand"
"strconv"
"testing"
"github.com/playwright-community/playwright-go"
)
var tests = []func(t *testing.T){
TestPlaywright,
TestPlaywright2,
TestCookies,
TestPersistentContext,
}
func TestPlaywright(t *testing.T) {
var pw Playwright
headless := true
opts := playwright.BrowserTypeLaunchOptions{
Headless: &headless,
}
var opts2 playwright.PageGotoOptions
var opts3 playwright.PageWaitForSelectorOptions
pw.Launch(opts)
pw.NewPage()
pw.Goto("https://www.github.com", opts2)
pw.WaitForSelector(".search-input", opts3)
pw.Kill()
}
func TestPlaywright2(t *testing.T) {
var pw Playwright
headless := true
opts := playwright.BrowserTypeLaunchOptions{
Headless: &headless,
}
var opts2 playwright.PageGotoOptions
var opts3 playwright.PageWaitForSelectorOptions
var opts4 playwright.PageTypeOptions
pw.Launch(opts)
pw.NewPage()
pw.Goto("https://www.github.com", opts2)
pw.WaitForSelector(".search-input", opts3)
pw.Type(".search-input", "how to measure real user metrics with the xk6-playwright extension for k6?", opts4)
fp := pw.FirstPaint()
fcp := pw.FirstContentfulPaint()
ttmi := pw.TimeToMinimallyInteractive()
fid := pw.FirstInputDelay()
fmt.Printf("First Paint: %v \n", fp)
fmt.Printf("First Contentful Paint: %v \n", fcp)
fmt.Printf("Time to Minimally Interactive: %v \n", ttmi)
fmt.Printf("First Input Delay: %v \n", fid)
pw.Kill()
}
func TestPlaywright3(t *testing.T) {
var pw Playwright
opts := playwright.BrowserTypeConnectOverCDPOptions{}
var opts2 playwright.PageGotoOptions
pw.Connect("http://localhost:9222", opts)
pw.Goto("https://www.github.com", opts2)
}
func TestPersistentContext(t *testing.T) {
var pw Playwright
headless := true
opts := playwright.BrowserTypeLaunchPersistentContextOptions{
Headless: &headless,
}
var opts2 playwright.PageGotoOptions
var opts3 playwright.PageWaitForSelectorOptions
pw.LaunchPersistent("./tmp/context-"+strconv.Itoa(rand.Intn(1000)), opts)
pw.NewPage()
pw.Goto("https://www.github.com", opts2)
pw.WaitForSelector(".search-input", opts3)
pw.Kill()
}
func TestCookies(t *testing.T) {
var pw Playwright
headless := true
opts := playwright.BrowserTypeLaunchOptions{
Headless: &headless,
}
var opts2 playwright.PageGotoOptions
pw.Launch(opts)
pw.NewPage()
pw.Goto("https://www.google.com", opts2)
cookies := pw.Cookies()
for _, bccr := range cookies {
fmt.Printf(bccr.Name + ": " + bccr.Value + "\n")
}
pw.Kill()
}
func TestAll(t *testing.T) {
for i, test := range tests {
t.Run(strconv.Itoa(i), test)
}
}