BLACK Screenshot with Selenium C# with IE browser - ONLY FOR IE browser (Same code working fine with Chrome and Firefox driver , in same condition)
I am working with C# Selenium , I have used below code for Screenshot, the code is working good with all browser like Chrome, IE, Firefox.
But for below condition screenshot method takes black screenshot. :
Condition: If test case faild due to any exception in code, the below code did the black screenshot only for IE browser:
[TestCleanup]
public void TestCleanup()
{
string ssFolder = Path.Combine(Context.TestLogsDir, "Screenshots");
string idxStr = "0";
if (Context.DataRow != null)
{
var index = Context.DataRow.Table.Rows.IndexOf(Context.DataRow);
idxStr = index.ToString();
}
var screenshotFileName = $"{Path.Combine(ssFolder, Context.TestName)}_{idxStr}.png";
if (Context.CurrentTestOutcome == UnitTestOutcome.Failed)
{
// prep folder if needed
if (Directory.Exists(ssFolder) == false)
{
Directory.CreateDirectory(ssFolder);
}
// Now take a screenshot
DriverUtils.Instance.WebDriverInstance.TakeScreenshot(screenshotFileName, ImageFormat.Png);
TestUtils.log.Info($"**SCREENSHOT @ '{screenshotFileName}'**");
Context.AddResultFile(screenshotFileName);
}
TestUtils.log.Debug($"END TEST: {Context.FullyQualifiedTestClassName}.{Context.TestName}");
TestUtils.log.Debug("=================================================================");
DriverUtils.Instance.Kill();
}
public static void TakeScreenshot(this IWebDriver driver, string FileLocationName, ImageFormat imageFormat)
{
((ITakesScreenshot)driver).GetScreenshot().SaveAsFile(FileLocationName, imageFormat);
}
Below version of IE and Selenium used:
IEDriver : <package id="Selenium.WebDriver.IEDriver" version="3.4.0" targetFramework="net452" />
Selenium : <package id="Selenium.WebDriver" version="3.4.0" targetFramework="net452" />
Exception: Test method DDS.DCRM.Test.Regression.Opportunity.OpportunityNeagtive.UpdateCustomerInboundActionNegative threw exception:
OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:4315/session/df6eda6b-97d1-4bd0-98a0-b06d3de07674/element timed out after 60 seconds. ---> System.Net.WebException: The operation has timed out.
Logs:
XXX.TestUtils: **SCREENSHOT @ 'C:\Test\TestResults\Deploy 2017-07-13 13_18_06\In\MYPC\Screenshots\UpdateCustomerInboundActionNegative_1.png
Screeshot : Black Image