@@ -87,7 +87,6 @@ def create_screenshot(**options)
87
87
end
88
88
89
89
after do
90
- FileUtils . rm_f ( "#{ PROJECT_ROOT } /spec/tmp/screenshot.pdf" )
91
90
FileUtils . rm_f ( "#{ PROJECT_ROOT } /spec/tmp/screenshot.png" )
92
91
end
93
92
@@ -206,6 +205,56 @@ def create_screenshot(**options)
206
205
include_examples "when scale is set"
207
206
end
208
207
208
+ include_examples "screenshot screen"
209
+
210
+ context "when encoding is base64" do
211
+ let ( :file ) { "#{ PROJECT_ROOT } /spec/tmp/screenshot.#{ format } " }
212
+
213
+ def create_screenshot ( path : file , **options )
214
+ image = browser . screenshot ( format : format , encoding : :base64 , **options )
215
+ File . open ( file , "wb" ) { |f | f . write Base64 . decode64 ( image ) }
216
+ end
217
+
218
+ it "defaults to base64 when path isn't set" do
219
+ browser . go_to
220
+
221
+ screenshot = browser . screenshot ( format : format )
222
+
223
+ expect ( screenshot . length ) . to be > 100
224
+ end
225
+
226
+ it "supports screenshotting the page in base64" do
227
+ browser . go_to
228
+
229
+ screenshot = browser . screenshot ( encoding : :base64 )
230
+
231
+ expect ( screenshot . length ) . to be > 100
232
+ end
233
+
234
+ context "png" do
235
+ let ( :format ) { :png }
236
+ after { FileUtils . rm_f ( file ) }
237
+
238
+ include_examples "screenshot screen"
239
+ end
240
+
241
+ context "jpeg" do
242
+ let ( :format ) { :jpeg }
243
+ after { FileUtils . rm_f ( file ) }
244
+
245
+ include_examples "screenshot screen"
246
+ end
247
+ end
248
+ end
249
+
250
+ describe "#pdf" do
251
+ let ( :format ) { :pdf }
252
+ let ( :file ) { "#{ PROJECT_ROOT } /spec/tmp/screenshot.#{ format } " }
253
+
254
+ after do
255
+ FileUtils . rm_f ( "#{ PROJECT_ROOT } /spec/tmp/screenshot.pdf" )
256
+ end
257
+
209
258
context "when :paper_width and :paper_height are set" do
210
259
it "changes pdf size" do
211
260
browser . go_to ( "/ferrum/long_page" )
@@ -280,46 +329,37 @@ def create_screenshot(**options)
280
329
transfer_mode : "ReturnAsBase64" )
281
330
end
282
331
end
332
+ end
283
333
284
- include_examples "screenshot screen"
285
-
286
- context "when encoding is base64" do
287
- let ( :file ) { "#{ PROJECT_ROOT } /spec/tmp/screenshot.#{ format } " }
288
-
289
- def create_screenshot ( path : file , **options )
290
- image = browser . screenshot ( format : format , encoding : :base64 , **options )
291
- File . open ( file , "wb" ) { |f | f . write Base64 . decode64 ( image ) }
292
- end
293
-
294
- it "defaults to base64 when path isn't set" do
295
- browser . go_to
296
-
297
- screenshot = browser . screenshot ( format : format )
298
-
299
- expect ( screenshot . length ) . to be > 100
300
- end
334
+ describe "#mhtml" do
335
+ let ( :format ) { :mhtml }
336
+ let ( :file ) { "#{ PROJECT_ROOT } /spec/tmp/screenshot.#{ format } " }
301
337
302
- it "supports screenshotting the page in base64" do
303
- browser . go_to
338
+ after do
339
+ FileUtils . rm_f ( "#{ PROJECT_ROOT } /spec/tmp/screenshot.mhtml" )
340
+ end
304
341
305
- screenshot = browser . screenshot ( encoding : :base64 )
342
+ it "returns data" do
343
+ browser . go_to ( "/ferrum/simple" )
306
344
307
- expect ( screenshot . length ) . to be > 100
308
- end
345
+ data = browser . mhtml
309
346
310
- context "png" do
311
- let ( :format ) { :png }
312
- after { FileUtils . rm_f ( file ) }
347
+ expect ( data ) . to match ( /\/ ferrum\/ simple/ )
348
+ expect ( data ) . to match ( /mhtml.blink/ )
349
+ expect ( data ) . to match ( /\< \! DOCTYPE html\> / )
350
+ expect ( data ) . to match ( /Foo\< br\> Bar/ )
351
+ end
313
352
314
- include_examples "screenshot screen"
315
- end
353
+ it "saves a file" do
354
+ browser . go_to ( "/ferrum/simple" )
316
355
317
- context "jpeg" do
318
- let ( :format ) { :jpeg }
319
- after { FileUtils . rm_f ( file ) }
356
+ browser . mhtml ( path : file )
320
357
321
- include_examples "screenshot screen"
322
- end
358
+ content = File . read ( file )
359
+ expect ( content ) . to match ( /\/ ferrum\/ simple/ )
360
+ expect ( content ) . to match ( /mhtml.blink/ )
361
+ expect ( content ) . to match ( /\< \! DOCTYPE html\> / )
362
+ expect ( content ) . to match ( /Foo\< br\> Bar/ )
323
363
end
324
364
end
325
365
end
0 commit comments