...
1 package playwright_test
2
3 import (
4 "path/filepath"
5 "testing"
6
7 "github.com/playwright-community/playwright-go"
8 "github.com/stretchr/testify/require"
9 )
10
11 func TestBrowserContextOutputTrace(t *testing.T) {
12 BeforeEach(t)
13 defer AfterEach(t)
14 context, err := browser.NewContext()
15 require.NoError(t, err)
16 defer context.Close()
17 require.NoError(t, context.Tracing().Start(playwright.TracingStartOptions{
18 Screenshots: playwright.Bool(true),
19 Snapshots: playwright.Bool(true),
20 }))
21 page, err := context.NewPage()
22 require.NoError(t, err)
23 defer page.Close()
24 _, err = page.Goto(server.PREFIX + "/grid.html")
25 require.NoError(t, err)
26 dir := t.TempDir()
27 err = context.Tracing().Stop(playwright.TracingStopOptions{
28 Path: playwright.String(filepath.Join(dir, "trace.zip")),
29 })
30 require.NoError(t, err)
31 require.FileExists(t, filepath.Join(dir, "trace.zip"))
32 }
33
34 func TestBrowserContextMultipleChunks(t *testing.T) {
35 BeforeEach(t)
36 defer AfterEach(t)
37 context, err := browser.NewContext()
38 require.NoError(t, err)
39 defer context.Close()
40 require.NoError(t, context.Tracing().Start(playwright.TracingStartOptions{
41 Screenshots: playwright.Bool(true),
42 Snapshots: playwright.Bool(true),
43 }))
44 page, err := context.NewPage()
45 require.NoError(t, err)
46 defer page.Close()
47 _, err = page.Goto(server.PREFIX + "/frames/frame.html")
48 require.NoError(t, err)
49 require.NoError(t, context.Tracing().StartChunk())
50 require.NoError(t, page.SetContent("<button>Click</button>"))
51 require.NoError(t, page.Click("button"))
52 dir := t.TempDir()
53 require.NoError(t, context.Tracing().StopChunk(playwright.TracingStopChunkOptions{
54 Path: playwright.String(filepath.Join(dir, "trace.zip")),
55 }))
56 require.FileExists(t, filepath.Join(dir, "trace.zip"))
57 }
58
View as plain text