1

I am running my selenium test thru Selenium Grid and I couldn't take screenshot on the node from my hub. I have followed the code from the Selenium HQ:

public class ScreenShotRemoteWebDriver : RemoteWebDriver, ITakesScreenshot
{
    public ScreenShotRemoteWebDriver(Uri RemoteAdress, ICapabilities capabilities)
    : base(RemoteAdress, capabilities)
    {
    }

    public new Screenshot GetScreenshot()
    {
        // Get the screenshot as base64.
        Response screenshotResponse = this.Execute(DriverCommand.Screenshot, null);
        string base64 = screenshotResponse.Value.ToString();

        // ... and convert it.
        return new Screenshot(base64);
    }
}


public static void takeRemoteScreenShot(string fileName)
{
    string currentDate = DateTime.Now.ToString("ddd, ddMMMyyyy HHmm");
    ScreenShotRemoteWebDriver webDriver = new ScreenShotRemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), DesiredCapabilities.Chrome());
    Screenshot ss = ((ITakesScreenshot)webDriver).GetScreenshot();
    string screenshot = ss.AsBase64EncodedString;
    //byte[] screenshotAsByteArray = ss.AsByteArray;
    string dir = Settings.DirScreenShots;
    ss.SaveAsFile(dir + currentDate + fileName + ".png", ScreenshotImageFormat.Png);
}

My test is failing due to this error:

 Result StackTrace: 
at SeleniumE2E.Utilities.ScreenshotCapture.takeRemoteScreenShot(String fileName)
   at SEL_ADAccountReactivate2.SmokeTest.RunTest() in C:\Users\Documents\Visual Studio 2015\Projects\App\App\Tests\SmokeTest.cs:line 16
Result Message: 
Test method App.SmokeTest.RunTest threw exception: 
System.MissingMethodException: Method not found: 'Void OpenQA.Selenium.Screenshot.SaveAsFile(System.String, OpenQA.Selenium.ScreenshotImageFormat)'.

1 Answer 1

2

SceenShotImageFormat was a relatively recent change in Selenium for .Net core, can you try with ImageFormat if you're not using .Net core and if that works I would recommend upgrading your entire Solution (Including the grid) to a more recent version of Selenium.

Based on the code in the solution, it looks like it just switches it to the ImageFormat method regardless so .... not sure how it's useful as of yet.

1
  • 1
    Thanks @Paul Muir, I have updated my entire solution to 3.3.1 (I think that is more stable than the 3.4.0) then used 3.3.1 grid and it worked
    – Marj
    Jun 21, 2017 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.