@@ -151,17 +151,46 @@ func TestElementHandleDblclick(t *testing.T) {
151
151
func TestElementBoundingBox (t * testing.T ) {
152
152
BeforeEach (t )
153
153
154
- require .NoError (t , page .SetViewportSize (500 , 500 ))
155
- _ , err := page .Goto (server .PREFIX + "/grid.html" )
156
- require .NoError (t , err )
157
- element_handle , err := page .QuerySelector (".box:nth-of-type(13)" )
158
- require .NoError (t , err )
159
- box , err := element_handle .BoundingBox ()
160
- require .NoError (t , err )
161
- require .Equal (t , 100.0 , box .X )
162
- require .Equal (t , 50.0 , box .Y )
163
- require .Equal (t , 50.0 , box .Width )
164
- require .Equal (t , 50.0 , box .Height )
154
+ testCases := []struct {
155
+ name string
156
+ setup func () error
157
+ selector string
158
+ expectedBox * playwright.Rect
159
+ }{
160
+ {
161
+ name : "Test element bounding box" ,
162
+ setup : func () error {
163
+ require .NoError (t , page .SetViewportSize (500 , 500 ))
164
+ _ , err := page .Goto (server .PREFIX + "/grid.html" )
165
+ return err
166
+ },
167
+ selector : ".box:nth-of-type(13)" ,
168
+ expectedBox : & playwright.Rect {X : 100.0 , Y : 50.0 , Width : 50.0 , Height : 50.0 },
169
+ },
170
+ {
171
+ name : "Bounding box of display:none element should be nil" ,
172
+ setup : func () error {
173
+ _ , err := page .Goto (server .EMPTY_PAGE )
174
+ require .NoError (t , err )
175
+ return page .SetContent ("<div id='hidden' style='display:none'>Hidden</div>" )
176
+ },
177
+ selector : "#hidden" ,
178
+ expectedBox : nil ,
179
+ },
180
+ }
181
+
182
+ for _ , tc := range testCases {
183
+ t .Run (tc .name , func (t * testing.T ) {
184
+ require .NoError (t , tc .setup ())
185
+
186
+ elementHandle , err := page .QuerySelector (tc .selector )
187
+ require .NoError (t , err )
188
+ box , err := elementHandle .BoundingBox ()
189
+ require .NoError (t , err )
190
+
191
+ require .Equal (t , tc .expectedBox , box )
192
+ })
193
+ }
165
194
}
166
195
167
196
func TestElementHandleTap (t * testing.T ) {
0 commit comments