Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: Exception saving a screenshot as file (.NET driver v4.12.2, on net6.0, linux) #12652

Closed
javiertuya opened this issue Sep 1, 2023 · 4 comments · Fixed by #12654
Closed

Comments

@javiertuya
Copy link

What happened?

After updating from v4.11.0 to v4.12.2 (.NET driver), I take an screenshot and then save it. The save operation fails with an exception System.PlatformNotSupportedException: System.Drawing.Common is not supported on this platform.

Additional details:

  • Works well on windows
  • Raises an exception on linux (GitHub Actions ubuntu-latest, dotnet-version 6.0.x)
  • Same exception using Chrome Headless or Chrome with Selenoid
  • Surprisingly, a .png file is generated with the Screenshot !!!

I suspect the problem is caused because now v4.12.2 targets netstandard2.0 only: #12608

How can we reproduce the issue?

Use this repo to reproduce the problem: https://github.com/javiertuya/selenium-4.12.2-screenshot-bug

The fragment of code is:

            ChromeOptions opt = new ChromeOptions();
            opt.AddArgument("--headless");
            IWebDriver driver = new ChromeDriver(opt);
            driver.Navigate().GoToUrl("https://www.selenium.dev/");
            Screenshot ss = ((ITakesScreenshot)driver).GetScreenshot();
            ss.SaveAsFile("../../../../screenshot.png", ScreenshotImageFormat.Png);
            driver.Close();


### Relevant log output

```shell
This is the log from GH Actions (the .trx test report is published as an artifact):

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Starting ChromeDriver 116.0.5845.96 (1a391816688002153ef791ffe60d9e899a71a037-refs/branch-heads/5845@{#1382}) on port 38071
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
  Failed TestScreenshot [2 s]
  Error Message:
   Test method Giis.Samples.Selema.Mstest2.TestScreenshotBug.TestScreenshot threw exception: 
System.PlatformNotSupportedException: System.Drawing.Common is not supported on this platform.
  Stack Trace:
      at System.Drawing.Image.FromStream(Stream stream)
   at OpenQA.Selenium.Screenshot.SaveAsFile(String fileName, ScreenshotImageFormat format)
   at Giis.Samples.Selema.Mstest2.TestScreenshotBug.TestScreenshot() in /home/runner/work/selenium-4.12.2-screenshot-bug/selenium-4.12.2-screenshot-bug/selenium-4.12.2-screenshot-bug/TestScreenshotBug.cs:line 19

  Standard Output Messages:
 Connection refused (localhost:38071)


### Operating System

Ubuntu latest on GitHub Actions

### Selenium version

.NET (C#) v4.12.2

### What are the browser(s) and version(s) where you see this issue?

Chrome (latest available on GH Actions)

### What are the browser driver(s) and version(s) where you see this issue?

Chrome 116.0.5845.96

### Are you using Selenium Grid?

No
@github-actions
Copy link

github-actions bot commented Sep 1, 2023

@javiertuya, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@titusfortner
Copy link
Member

Yes, it's related to removing targeting other frameworks.

@nvborisenko can we create examples for how users should be getting screenshots now?

@nvborisenko
Copy link
Member

nvborisenko commented Sep 1, 2023

It should work as before, but with limitations:

https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/6.0/system-drawing-common-windows-only
I think we should not let user to save screenshot as file in not PNG format (next major release?). In any case user is able to get screenshot bytes and encode it to any format he wants with any library for image processing.

Copy link

github-actions bot commented Dec 6, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants