Example #1
0
        private string TakeScreenshot(IBrowserWrapper browserWrapper)
        {
            var testContext = TestSuiteRunner.TestContextProvider.GetGlobalScopeTestContext();

            try
            {
                var deploymentDirectory = testContext.DeploymentDirectory;
                if (!string.IsNullOrWhiteSpace(TestSuiteRunner.Configuration.TestRunOptions.ScreenshotPath))
                {
                    deploymentDirectory = CreateDirectory(Path.Combine(TestSuiteRunner.Configuration.TestRunOptions.ScreenshotPath, DateTime.UtcNow.ToString("yyyyMMdd")));
                }

                var filename = Path.Combine(deploymentDirectory,
                                            $"{testContext.FullyQualifiedTestClassName}_{testContext.TestName}_{testAttemptNumber}.png");
                TestSuiteRunner.LogVerbose(
                    $"(#{Thread.CurrentThread.ManagedThreadId}) {TestName}: Taking screenshot {filename}");
                browserWrapper.TakeScreenshot(filename);
                TestSuiteRunner.TestContextAccessor.GetTestContext().AddResultFile(filename);
                return(filename);
            }
            catch (Exception ex)
            {
                TestSuiteRunner.LogError(new Exception(
                                             $"(#{Thread.CurrentThread.ManagedThreadId}) {TestName}: Failed to take screenshot.", ex));
                return(null);
            }
        }