Пример #1
0
        public void AfterTest()
        {
            if (TestContext.CurrentContext.Test.Properties["Category"].Contains("UI") &&
                !TestContext.CurrentContext.Test.Properties["Category"].Contains("ConsoleErrorExpected") &&
                Parameters.Parameters.Browser.ToLower() != "microsoftedge")
            {
                var errors = App.Ui.UiHelp.GetBrowserLogs();
                if (errors.Count > 0)
                {
                    App.Logger.Error($"Browser console errors were found during test method run: {TestContext.CurrentContext.Test.MethodName}. Errors:" + Environment.NewLine);
                    foreach (var er in errors)
                    {
                        App.Logger.Error(er.Level + " " + er.Message);
                    }
                }
            }


            APIClient testRailClient = null;

            if (!string.IsNullOrEmpty(Parameters.Parameters.TestRailUrl))
            {
                testRailClient = this.InitTestRailClient(Parameters.Parameters.TestRailUrl);
            }

            var testCaseNumbers = TestContext.CurrentContext.Test.Properties.ContainsKey("TestCase") ?
                                  TestContext.CurrentContext.Test.Properties["TestCase"].ToList() :
                                  new List <object>();

            if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed)
            {
                this.App.Logger.Warn("Test failed - " + TestContext.CurrentContext.Test.MethodName);

                this.ProcessFailedCaseWithTestRail(testCaseNumbers, testRailClient);

                if (this.App.PageManagerExists)
                {
                    this.MakeScreenshot();
                }
            }
            else
            {
                if (TestContext.CurrentContext.Result.Outcome.Status != TestStatus.Skipped)
                {
                    this.App.Logger.Info("Test completed successfully - " + TestContext.CurrentContext.Test.MethodName);

                    this.ProcessPassedCaseWithTestRail(testCaseNumbers, testRailClient);
                }
            }

            if (this.App.PageManagerExists)
            {
                if (this.App.Pages.Driver != null)
                {
                    WebDriverFactory.DismissLocalThreadDriver();
                }
            }

            // Nullify application mananger after each test
            this.App = null;
        }