lefthandedgoat / canopy

f# web automation and testing library, built on top of Selenium (friendly to c# also)
http://lefthandedgoat.github.io/canopy/
MIT License
505 stars 117 forks source link

Screenshots are saves as png despite .jpg extension #500

Open olivercoad opened 4 years ago

olivercoad commented 4 years ago

Describe the bug While looking into #499, I realised that the screenshot function saves the image in png format despite adding the .jpg file extension.

https://github.com/lefthandedgoat/canopy/blob/a593649e5995fb0804c5b7c8f9510cd40840a569/src/canopy/canopy.parallell.functions.fs#L52-L99

Unfortunately, I don't think fixing this won't help reduce file size for #499 because failure screenshots uses the returned byte array which is actually converted to jpg format.

To Reproduce Steps to reproduce the behavior:

  1. Take a screenshot

    start chrome
    url "https://github.com/lefthandedgoat/canopy/issues/500"
    screenshot "screenshots" "issue500"
  2. Check the file format. For example in linux (or WSL),

    $ file screenshot/issue500.jpg
    issue500.jpg: PNG image data, 824 x 918, 8-bit/color RGBA, non-interlaced

Expected behavior Should convert to jpg before saving the file. Or save with .png file extension.

Other information

Dotnet core screenshot actually fails when I use dotnet core. It saves the png format file (with .jpg extension) and then throws when trying to convert to jpg. Maybe I'm missing a paket reference or something.

System.PlatformNotSupportedException: System.Drawing is not supported on this platform.
   at System.Drawing.Image.FromStream(Stream stream)
   at canopy.parallell.functions.pngToJpg(Byte[] pngArray) in C:\projects\canopy\src\canopy\canopy.parallell.functions.fs:line 89
   at <StartupCode$FSI_0013>.$FSI_0013.main@()
lefthandedgoat commented 4 years ago

I can fix this this weekend. canopy uses https://www.nuget.org/packages/System.Drawing.Common/ which should work with .net core but I will also try it on windows + osx, no linux vm handy sorry.

IvanRainbolt commented 3 years ago

I think my issue is related here from comparing the error messages. My script is here: https://gist.github.com/IvanRainbolt/42b8c0c7fe3742e741e40373582be86e and my error message is this: D:\OneDrive\T\canopy.experiment>fsi tryscreenshot.fsx READY_ Starting ChromeDriver 84.0.4147.30 (48b3e868b4cc0aa7e8149519690b6f6949e110a8-refs/branch-heads/4147@{#310}) on port 65077 Only local connections are allowed. Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe. ChromeDriver was started successfully. DevTools listening on ws://127.0.0.1:65080/devtools/browser/0185cedf-d3a3-49d7-a520-81494d7584b7 path: C:\Users\netaz\AppData\Roaming\canopy\ System.TypeLoadException: Could not load type 'System.MarshalByRefObject' from assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. at canopy.parallell.functions.pngToJpg(Byte[] pngArray) at <StartupCode$FSI_0001>.$FSI_0001.main@() in D:\OneDrive\T\canopy.experiment\tryscreenshot.fsx:line 46 Stopped due to error D:\OneDrive\T\canopy.experiment>