Giter VIP home page Giter VIP logo

noksa / webdriver.screenshots.extensions Goto Github PK

View Code? Open in Web Editor NEW
12.0 12.0 8.0 26.56 MB

C# WebDriver screenshots extensions, like a screenshot entire page

License: MIT License

C# 5.57% JavaScript 0.21% HTML 10.81% C# 5.57% JavaScript 0.21% HTML 10.81% C# 18.60% JavaScript 4.10% HTML 44.13%
automation csharp extension screenshot selenium selenium-webdriver testing testing-tools webdriver

webdriver.screenshots.extensions's People

Contributors

jtone123 avatar luizcarlosfaria avatar noksa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

webdriver.screenshots.extensions's Issues

Saving the screenshot

Hey. I don't understand how to save a screenshot to a hard drive like Ss.SaveAsFile() in standard Selenium.

Doesn't work for IE driver

This is what I get when I try to take a screenshot with the Internet Explorer driver:

OpenQA.Selenium.WebDriverException : JavaScript error

Relevant parts of the stacktrace:

 at OpenQA.Selenium.Support.Extensions.WebDriverExtensions.ExecuteJavaScript[T](IWebDriver driver, String script, Object[] args)
 at WDSE.Helpers.JQueryHelper.GetAllElementsWithScrollbars(IWebDriver driver)
 at WDSE.Helpers.JQueryHelper.GetElementWithActiveScrollBar(IWebDriver driver)
 at WDSE.Decorators.VerticalCombineDecorator.CombineScreenshots(IWebDriver driver)
 at WDSE.Decorators.VerticalCombineDecorator.MakeScreenshot(IWebDriver driver)
 at WDSE.ExtensionMethods.TakeScreenshot(IWebDriver driver, IScreenshotStrategy strategy)

I believe this is because IE doesn't support some of the latest Javascript features.
eg.

  • const keyword
  • let keyword
  • spread operator (...array)
  • string interpolation `${foobar}`

footer is overlapped with top of scrolled-down screenshot causing over-lapped information to be hidden by footer.

While taking full screenshot of scrollable webpage, the footer is shown at middle of the screenshot which overlaps with the important information of the top of scrolled lower screenshot image; hence, those important information of webpage at down side is not shown. The issue is that the important information is hidden due to overlapped footer in the middle of the whole screenshot .

Please inform how to rectify this issue while taking full screenshot of scrollable webpage with footer.

The code implemented with this issue:

VerticalCombineDecorator vcd = new VerticalCombineDecorator(new ScreenshotMaker().RemoveScrollBarsWhileShooting());

driver.TakeScreenshot(vcd).ToMagickImage().Write(string.Format("{0:yyyy-MMM-ddTHH.mm.ss.fff}.jpg", DateTime.Now), MagickFormat.Jpg);

The ability to remove an element from DOM before taking screenshot

There are elements that need to be removed in the screenshots, especially if you are using a VerticalCombineDecorator.
For example, this is phpdebugbar, which is absolutely not needed at the screenshots.

It is required to develop a additional setting at ScreenshotMaker class, that will hides the elements from DOM if they are visible.

javascript error: $ is not defined - Error returned when taking screenshot

When attempting to take a screenshot using the snippet below I get an error back.

Error:

OpenQA.Selenium.WebDriverException
  HResult=0x80131500
  Message=javascript error: $ is not defined
  (Session info: chrome=79.0.3945.117)
  Source=WebDriver
  StackTrace:
   at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.ExecuteScriptCommand(String script, String commandName, Object[] args)
   at OpenQA.Selenium.Remote.RemoteWebDriver.ExecuteScript(String script, Object[] args)
   at OpenQA.Selenium.Support.Extensions.WebDriverExtensions.ExecuteJavaScriptInternal(IWebDriver driver, String script, Object[] args)
   at OpenQA.Selenium.Support.Extensions.WebDriverExtensions.ExecuteJavaScript[T](IWebDriver driver, String script, Object[] args)
   at WDSE.Helpers.SizesHelper.GetHeight(IWebDriver driver, Entity entity)
   at WDSE.Decorators.VerticalCombineDecorator.CombineScreenshots(IWebDriver driver)
   at WDSE.Decorators.VerticalCombineDecorator.MakeScreenshot(IWebDriver driver)
   at WDSE.ExtensionMethods.TakeScreenshot(IWebDriver driver, IScreenshotStrategy strategy)

Snippet:

var driver = new ChromeDriver();

driver.Navigate().GoToUrl("https://github.com/Noksa/WebDriver.Screenshots.Extensions/wiki/How-to-use");

var vcd = new VerticalCombineDecorator(new ScreenshotMaker());
var screenshot = driver.TakeScreenshot(vcd);

System.OverflowException: 'Arithmetic operation resulted in an overflow.'

Please find the code

             IWebDriver driver;
            driver = new ChromeDriver(System.IO.Directory.GetCurrentDirectory() + "\\driver");
            driver.Url = "http://www.seleniumstutorial.com/taking-screenshot-using-c-selenium/";

            var scMaker = new ScreenshotMaker();
            var cutFooterDecorator = new CutterDecorator(scMaker);
            cutFooterDecorator.SetCuttingStrategy(new CutElementHeightOnEntireWidthThenCombine(By.Id("footer")));
            var vcd = new VerticalCombineDecorator(cutFooterDecorator);
            var screenArrBytes = driver.TakeScreenshot(vcd);

While excute above code in TakeScreenshot return following error.
"Arithmetic operation resulted in an overflow."

Vertically combine only element

Is it possible to get just an element that's longer than display, and combine it?
I've tried using
new VerticalCombineDecorator(new OnlyElementDecorator(scmkr).SetElement(element));
It does not trim the element correctly, so I get a long image with the element repeating.

new OnlyElementDecorator(new VerticalCombineDecorator(scmkr)).SetElement(element);
Doesn't work because doesn't combine

Fixed navigation menu screenshot issue

I have a application that has a fixed navigation menu. When it takes screenshot, the menu appears on all the segment of the screenshot. Please suggest how to fix or handle it?

Thanks!
Venky.

System.TypeInitializationException: The type initializer for 'NativeMagickImageCollection' threw an exception.

First of all, thanks for making a great library, it helps a lot.
However, when I upgraded version of .NET, TakeScreenShot start throwing an following error, if I run dotnet publish, and run the produced package. It runs perfectly with dotnet run.
I would appreciate very much if you can fix this problem quickly, or give me solution.

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using OpenQA.Selenium;
using WDSE;
using WDSE.Decorators;
using WDSE.ScreenshotMaker;
namespace SeleniumScriptRunner
{
  public partial class ScriptGlobals
  {
    public static void TakeFullPageScreenshot(ref IWebDriver driver, string saveTo)
    {
      var scm = new ScreenshotMaker();
      scm.RemoveScrollBarsWhileShooting();
      var vcs = new VerticalCombineDecorator(scm);
      var bytesArr = driver.TakeScreenshot(vcs);
      File.WriteAllBytes(saveTo, bytesArr);
    }

  }
}
System.TypeInitializationException: The type initializer for 'NativeMagickImageCollection' threw an exception.
 ---> System.EntryPointNotFoundException: Unable to find an entry point named 'Environment_Initialize' in DLL 'Magick.NET-Q8-x64.Native.dll'.
   at ImageMagick.Environment.NativeMethods.X64.Environment_Initialize()
   at ImageMagick.Environment.NativeEnvironment.Initialize()
   at ImageMagick.Environment.Initialize()
   at ImageMagick.MagickImageCollection.NativeMagickImageCollection..cctor()
   --- End of inner exception stack trace ---
   at ImageMagick.MagickImageCollection.NativeMagickImageCollection..ctor()
   at ImageMagick.MagickImageCollection..ctor()
   at WDSE.Decorators.VerticalCombineDecorator.CombineScreenshots(IWebDriver driver)  
   at WDSE.Decorators.VerticalCombineDecorator.MakeScreenshot(IWebDriver driver)      
   at WDSE.ExtensionMethods.TakeScreenshot(IWebDriver driver, IScreenshotStrategy strategy)
   at SeleniumScriptRunner.ScriptGlobals.TakeFullPageScreenshot(IWebDriver& driver, String saveTo) in 
   at Submission#0.<<Initialize>>b__0_1(IWebDriver driver)
   at SeleniumScriptRunner.ScriptGlobals.Test(String name, Action f) in 

Versions

  • Windows 10
  • dotnet 6.0.100
  • Nuget NuGet Version: 6.0.0.280
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <RootNamespace>SeleniumScriptRunner</RootNamespace>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="3.10.0"/>
    <PackageReference Include="Noksa.WebDriver.ScreenshotsExtensions" Version="0.1.5.4"/>
    <PackageReference Include="Selenium.Support" Version="4.1.0"/>
    <PackageReference Include="Selenium.WebDriver" Version="4.1.0"/>
    <PackageReference Include="CommandLineParser" Version="2.9.0-preview1"/>
    <PackageReference Include="System.Drawing.Common" Version="5.0.2"/>
    <PackageReference Include="Magick.NET-Q8-x64" Version="8.4.0"/>
  </ItemGroup>
  <Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <Exec Command="echo D | xcopy $(ProjectDir)contentFiles $(TargetDir)contentFiles  /I/E/Y
xcopy  $(ProjectDir)codes $(TargetDir)codes /I/E/Y"/>
  </Target>
  <Target Name="PostPublish" AfterTargets="AfterPublish">
    <Exec Command="xcopy $(ProjectDir)contentFiles $(PublishDir)contentFiles  /I/E/Y
xcopy  $(ProjectDir)codes $(PublishDir)codes /I/E/Y"/>
  </Target>

No longer supported in Selenium 4.x

[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.

.NET Standard Support

Read on Nuget.org we can see dependencies about:

  • .NETFramework 4.5.2
  • .NETFramework 4.6
  • .NETFramework 4.6.1
  • .NETFramework 4.6.2
  • .NETFramework 4.7
  • .NETFramework 4.7.1
  • .NETFramework 4.7.2

And has no target for .NET Standard 2.

Do you have any roadmap to provide a .NET Standard target?

Error using new Selenium 4 Edge driver and TakeScreenshot method

When I execute this code:

var maker = new ScreenshotMaker();
maker.RemoveScrollBarsWhileShooting();
var vertical = new VerticalCombineDecorator(maker);
var data = DriverManagerContext.GetDriverManager().GetDriver().TakeScreenshot(vertical);

I get the following exception when calling TakeScreenshot method using a Selenium 4 Edge driver:

Unable to cast object of type 'OpenQA.Selenium.Edge.EdgeDriver' to type 'OpenQA.Selenium.Remote.RemoteWebDriver'.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.