MCPcopy Create free account
hub / github.com/tebeka/selenium / TestFrameBuffer

Function TestFrameBuffer

service_test.go:77–147  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

75}
76
77func TestFrameBuffer(t *testing.T) {
78 // Note on FrameBuffer and xgb.Conn:
79 // There appears to be a race condition when closing a Conn instance before
80 // a FrameBuffer instance. A short sleep solves the problem.
81 t.Run("Default behavior", func(t *testing.T) {
82 // The default Xvfb screen size is "1280x1024x8".
83 frameBuffer, err := NewFrameBuffer()
84 if err != nil {
85 t.Fatalf("Could not create frame buffer: %s", err.Error())
86 }
87 defer frameBuffer.Stop()
88
89 if frameBuffer.Display == "" {
90 t.Fatalf("frameBuffer.Display is empty")
91 }
92
93 d, err := xgbutil.NewConnDisplay(":" + frameBuffer.Display)
94 if err != nil {
95 t.Fatalf("could not connect to display %q: %s", frameBuffer.Display, err.Error())
96 }
97 defer time.Sleep(time.Second * 2)
98 defer d.Conn().Close()
99 s := d.Screen()
100 if diff := cmp.Diff(1280, int(s.WidthInPixels)); diff != "" {
101 t.Fatalf("args returned diff (-want/+got):\n%s", diff)
102 }
103 if diff := cmp.Diff(1024, int(s.HeightInPixels)); diff != "" {
104 t.Fatalf("args returned diff (-want/+got):\n%s", diff)
105 }
106 })
107 t.Run("With bad screen size", func(t *testing.T) {
108 options := FrameBufferOptions{
109 ScreenSize: "not a screen size",
110 }
111 _, err := NewFrameBufferWithOptions(options)
112 if err == nil {
113 t.Fatalf("Expected an error about the screen size")
114 }
115 })
116 t.Run("With screen size", func(t *testing.T) {
117 desiredWidth := 1024
118 desiredHeight := 768
119 desiredDepth := 24
120 options := FrameBufferOptions{
121 ScreenSize: fmt.Sprintf("%dx%dx%d", desiredWidth, desiredHeight, desiredDepth),
122 }
123 frameBuffer, err := NewFrameBufferWithOptions(options)
124 if err != nil {
125 t.Fatalf("Could not create frame buffer: %s", err.Error())
126 }
127 defer frameBuffer.Stop()
128
129 if frameBuffer.Display == "" {
130 t.Fatalf("frameBuffer.Display is empty")
131 }
132
133 d, err := xgbutil.NewConnDisplay(":" + frameBuffer.Display)
134 if err != nil {

Callers

nothing calls this directly

Calls 5

NewFrameBufferFunction · 0.85
ErrorMethod · 0.80
CloseMethod · 0.65
StopMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…