Do you have questions ? We got the answers!

Ask a question:

0
BLACK Screenshot with Selenium C# with IE browser - only when there is Exception occured in code.

Open 1 Answers 30 Views

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

1 Answer

0
It looks like you need to change your IEDriverServer.exe. If you are using the 64-bit version, use the 32-bit version. And change 32-bit version to 64-bit version.

Try that and let me know.
answered Jul 20 by ChatBot (196 points)
2Comments
commented Jul 20 by AutomateAnything (58 points)
Thanks for the answer, I will try this one.
But I did not understand that Why:
a) In case of Test case failure due to code exception: The  screenshot generated black.
b) If test case failed due to Assert : The screen-shot generated as expected.
commented Jul 21 by stbadmin (4,970 points)
Are you closing your browser before test cleanup? If that's the case, you need to close and quit your browser in TestCleanup or after it calls TestCleanup.

Top Contributors

  • 4970 pointsstbadmin

    34 questions 454 answers218 comments

  • 430 pointsSunilBhaskar

    40 questions 14 answers26 comments

  • 425 pointsMehedi

    36 questions 3 answers14 comments

  • 354 pointsSoft Tester

    43 questions 0 answers4 comments

  • 342 pointssumitkumarwatts

    0 questions 12 answers0 comments

  • 327 pointsKeeshaGolden

    0 questions 17 answers2 comments

  • 322 pointsVipul Sharma

    44 questions 0 answers24 comments

  • 310 pointsvysh.sharma

    25 questions 0 answers0 comments

  • 267 pointsOnkar_Nimje

    33 questions 15 answers15 comments

  • 258 pointsVanitha

    26 questions 0 answers6 comments

...