Noksa / WebDriver.Screenshots.Extensions

C# WebDriver screenshots extensions, like a screenshot entire page
MIT License
12 stars 8 forks source link

No longer supported in Selenium 4.x #27

Closed kathyrollo closed 1 year ago

kathyrollo commented 2 years ago
[TestCleanup]
public void TearDown()
{
    if (TestContext.CurrentTestOutcome == UnitTestOutcome.Failed)
    {
        var maker = new ScreenshotMaker();
        maker.RemoveScrollBarsWhileShooting();
        var vertical = new VerticalCombineDecorator(maker);
        var sshot = driver.TakeScreenshot(vertical);
        var fileName = $"{TestContext.TestResultsDirectory}/sshot_{DateTimeOffset.Now.ToUnixTimeMilliseconds()}.png";
        File.WriteAllBytes(fileName, sshot);
        TestContext.AddResultFile(fileName);
    }
    driver.Quit();
}

No compile error but the same code that used to work with Selenium 3.141.0 no longer saves screenshots after updating to Selenium 4.0.1.

Noksa commented 2 years ago

I'll check it in a few days

Noksa commented 2 years ago

I've tested it and I can't reproduce this error. File was saved to a directory in this line: File.WriteAllBytes(fileName, sshot);

kathyrollo commented 2 years ago

@Noksa Thanks for looking into it. What was the exact Selenium version you used?

Noksa commented 2 years ago

@kathyrollo I used the latest version from nuget. It was 4.1.0

kathyrollo commented 2 years ago

@Noksa Thanks, this was observed in 4.0.1. Will check with the latest version to see if it replicates and update.

sirphilliptubell commented 2 years ago

Seems like this is the proper place to post this as I'm also having issues with 4.x.

When calling WDSE.ExtensionMethods.TakeScreenshot(this IWebDriver driver, IScreenshotStrategy strategy) I get this exception: System.TypeLoadException: 'Could not load type 'OpenQA.Selenium.Remote.CapabilityType' from assembly 'WebDriver, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null'.'

It looks like CapabilityType was moved to the OpenQA.Selenium namespace

domosgabor commented 2 years ago

Seems like this is the proper place to post this as I'm also having issues with 4.x.

When calling WDSE.ExtensionMethods.TakeScreenshot(this IWebDriver driver, IScreenshotStrategy strategy) I get this exception: System.TypeLoadException: 'Could not load type 'OpenQA.Selenium.Remote.CapabilityType' from assembly 'WebDriver, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null'.'

It looks like CapabilityType was moved to the OpenQA.Selenium namespace

I would like to report the same issue

shatulsky commented 2 years ago

Got the same error System.TypeLoadException: Could not load type 'OpenQA.Selenium.Remote.CapabilityType' from assembly 'WebDriver, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null'. at OpenQA.Selenium.Support.Extensions.WebDriverExtensions.TakeScreenshot(IWebDriver driver) at WDSE.ScreenshotMaker.ScreenshotMaker.MakeScreenshot(IWebDriver driver) at WDSE.Decorators.VerticalCombineDecorator.CombineScreenshots(IWebDriver driver) at WDSE.Decorators.VerticalCombineDecorator.MakeScreenshot(IWebDriver driver) at WDSE.ExtensionMethods.TakeScreenshot(IWebDriver driver, IScreenshotStrategy strategy)

<PackageReference Include="Selenium.WebDriver" Version="4.1.0" /> <PackageReference Include="Noksa.WebDriver.ScreenshotsExtensions" Version="0.1.5.4" />

domosgabor commented 2 years ago

Got the same error System.TypeLoadException: Could not load type 'OpenQA.Selenium.Remote.CapabilityType' from assembly 'WebDriver, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null'. at OpenQA.Selenium.Support.Extensions.WebDriverExtensions.TakeScreenshot(IWebDriver driver) at WDSE.ScreenshotMaker.ScreenshotMaker.MakeScreenshot(IWebDriver driver) at WDSE.Decorators.VerticalCombineDecorator.CombineScreenshots(IWebDriver driver) at WDSE.Decorators.VerticalCombineDecorator.MakeScreenshot(IWebDriver driver) at WDSE.ExtensionMethods.TakeScreenshot(IWebDriver driver, IScreenshotStrategy strategy)

<PackageReference Include="Selenium.WebDriver" Version="4.1.0" /> <PackageReference Include="Noksa.WebDriver.ScreenshotsExtensions" Version="0.1.5.4" />

domosgabor commented 2 years ago

For us a workaround solution was to downgrade Selenium.WebDriver and Selenium.Support to v4.0.0

Noksa commented 2 years ago

Can someone share a sample project where it reproduces every time? I would very appreciate because I can't reproduce it.

shatulsky commented 2 years ago

Can someone share a sample project where it reproduces every time? I would very appreciate because I can't reproduce it.

The reason for failing for me was that I did not have Selenium.Support in my solution. And seems like the version from your solution (3.8.0) was used.

Adding <PackageReference Include="Selenium.Support" Version="4.1.0" /> to my solution fixed the issue.

So updating Selenium.WebDriver and Selenium.Support versions to 4.1.0 in your solution should probably fix the issue.

Noksa commented 2 years ago

Yeah, that's why I wrote this message: https://github.com/Noksa/WebDriver.Screenshots.Extensions/issues/27#issuecomment-983457976

shatulsky commented 2 years ago

Yea, but to reproduce the issue you can just create an empty project and reference only Selenium.WebDriver 4.1.0 and your NuGet package. That is was you asking for, right?

Can someone share a sample project where it reproduces every time? I would very appreciate because I can't reproduce it.

pants11 commented 2 years ago

I still have the same issue after I downgraded from V4.11.x to V3.14.1. I'm not sure where I can add " Adding '<PackageReference Include="Selenium.Support" Version="4.1.0" /'> to my solution fixed the issue. So updating Selenium.WebDriver and Selenium.Support versions to 4.1.0 in your solution should probably fix the issue. "

[updated] I had trouble with the nuget package versions mapping tables while downgrade and upgrade nuget installations. I had to search to understand shatulsky's comments and it helped me solve it.

sirphilliptubell commented 2 years ago

So I confirmed adding Selenium.Support (with the proper version) fixes the issue.

Here's a scenario

The other fix would be to add a new WDSE version (say 4.0) that has a dependency on 4.x of the Selenium packages - that way it's clear you need a WDSE 4.x if you're using Selenium 4.x. Otherwise people will continue to get the latest WSDE and Selenium.WebDriver packages only and get this error.

@Noksa here's an example

  <ItemGroup>
    <PackageReference Include="Noksa.WebDriver.ScreenshotsExtensions" Version="0.1.5.4" />
    <PackageReference Include="Selenium.WebDriver" Version="4.3.0" />
    <PackageReference Include="WebDriverManager" Version="2.14.1" />
  </ItemGroup>
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.Extensions;
using WDSE;
using WDSE.Decorators;
using WDSE.ScreenshotMaker;
using WebDriverManager;
using WebDriverManager.DriverConfigs.Impl;

new DriverManager().SetUpDriver(new ChromeConfig());
var driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://slashdot.org");
// throws
var screenshot = driver.TakeScreenshot(new VerticalCombineDecorator(new ScreenshotMaker()));
kathyrollo commented 1 year ago

Hi @Noksa ,

I confirm it works with the following latest versions (as of this writing):

2022-09-30 11_51_27-Window

I'm closing the ticket unless you deem otherwise. Thanks.