Пример #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);
            }
        }
Пример #2
0
        public async Task ReturnBrowserToPool(IWebBrowser webBrowser)
        {
            if (webBrowser.Factory is IReusableWebBrowserFactory reusableFactory)
            {
                runner.LogVerbose($"(#{Thread.CurrentThread.ManagedThreadId}) Clearing browser {webBrowser.UniqueName} state.");
                try
                {
                    reusableFactory.ClearBrowserState(webBrowser);

                    lock (locker)
                    {
                        pool.Add(webBrowser);
                    }
                    runner.LogVerbose($"(#{Thread.CurrentThread.ManagedThreadId}) Browser {webBrowser.UniqueName} returned to the pool cache.");
                    return;
                }
                catch (Exception ex)
                {
                    runner.LogError(new Exception($"(#{Thread.CurrentThread.ManagedThreadId}) Failed to clear browser {webBrowser.UniqueName} state", ex));
                }
            }

            await DisposeBrowser(webBrowser);
        }