Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
1.6k views
by Contributing Tester (48 points)
edited by
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 like 0 dislike
by The go-to Tester (222 points)
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.
by Contributing Tester (48 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.
by The go-to Tester (181 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.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...