Skip to content

Commit

Permalink
change impage format from png to jpeg for error reporting for #310
Browse files Browse the repository at this point in the history
  • Loading branch information
lefthandedgoat committed Nov 21, 2016
1 parent 1100929 commit 0d5daa3
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/canopy/canopy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ let private regexMatch pattern input = System.Text.RegularExpressions.Regex.Matc
let private saveScreenshot directory filename pic =
if not <| Directory.Exists(directory)
then Directory.CreateDirectory(directory) |> ignore
IO.File.WriteAllBytes(Path.Combine(directory,filename + ".png"), pic)
IO.File.WriteAllBytes(Path.Combine(directory,filename + ".jpg"), pic)

let private takeScreenShotIfAlertUp () =
try
Expand Down Expand Up @@ -92,10 +92,20 @@ let private takeScreenshot directory filename =
alert.Accept()
pic

let private pngToJpg pngArray =
let pngStream = new MemoryStream()
let jpgStream = new MemoryStream()

pngStream.Write(pngArray, 0, pngArray.Length)
let img = Image.FromStream(pngStream)

img.Save(jpgStream, ImageFormat.Jpeg)
jpgStream.ToArray()

(* documented/actions *)
let screenshot directory filename =
match box browser with
| :? ITakesScreenshot -> takeScreenshot directory filename
| :? ITakesScreenshot -> takeScreenshot directory filename |> pngToJpg
| _ -> Array.empty<byte>

(* documented/actions *)
Expand Down

0 comments on commit 0d5daa3

Please sign in to comment.