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)'.