예제 #1
0
        /// <summary>
        /// Constructor of Base Page
        /// </summary>
        protected BasePage(string testMethod)
        {
            var webTestMethodManager = WebTestManager.Instance().WebTestMethodManager;
            var webTestMethod        = (WebTestMethod)webTestMethodManager.TryGetValue(testMethod);

            _driver = webTestMethod?.WebDriver;
            _configurationReader = webTestMethod?.ConfigurationReader;
            _loggingUtility      = webTestMethodManager.LoggingUtility;
        }
        public override void OnTestCleanup()
        {
            var testMethod = TestMethod;

            TestManager = WebTestManager.Instance();
            WebTestMethodManager.TestMethods.TryGetValue(testMethod, out ITestMethodBase testMethodBase);
            var webTestMethod = (WebTestMethod)testMethodBase;

            try
            {
                CustomAttributesCleanup(testMethod);

                if (TestContext.CurrentTestOutcome != UnitTestOutcome.Passed)
                {
                    TestContext.WriteLine(Infrastructure.Constants.Generic.TestErrorMessage);

                    if (LoggingUtility == null || TestManager.ConfigurationReader == null)
                    {
                        return;
                    }

                    var outputPath = !string.IsNullOrWhiteSpace(TestManager.ConfigurationReader.GetConfigurationValue(Constants.Configuration.ConfigKeyOutputFileScreenshotsDirectory)) ? $"{TestManager.ConfigurationReader.GetConfigurationValue(Constants.Configuration.ConfigKeyOutputFileScreenshotsDirectory)}" : $"{TestContext.TestRunResultsDirectory}{Constants.Configuration.ScreenshotsDirectory}";

                    if (webTestMethod?.WebDriver == null)
                    {
                        return;
                    }

                    TestContext.WriteLine($"Attempting to capture screen shot to: {outputPath}");

                    var captureScreenShot = webTestMethod.WebDriver.ScreenShotSaveFile(outputPath, testMethod);

                    if (string.IsNullOrWhiteSpace(captureScreenShot))
                    {
                        return;
                    }

                    TestContext.AddResultFile(captureScreenShot);

                    LoggingUtility.Error(captureScreenShot);
                }
                else
                {
                    TestContext.WriteLine(Infrastructure.Constants.Generic.TestSuccessMessage);
                }
            }
            catch (System.Exception ex)
            {
                HandleException(ex);
            }
            finally
            {
                WebTestManager.OnTestCleanup(testMethod);
            }
        }
        public override void OnTestInitialise()
        {
            var testMethod = TestMethod;

            TestManager = WebTestManager.Instance();

            try
            {
                WebTestManager.OnTestMethodInitialise(testMethod, TestContext);
                CustomAttributesInitialise(testMethod);
            }
            catch (System.Exception ex)
            {
                if (LoggingUtility == null || TestManager.ConfigurationReader == null)
                {
                    throw;
                }

                LoggingUtility.Error(Constants.Exceptions.ExceptionMsgSetupError + ex.Message);

                WebTestMethodManager.TestMethods.TryGetValue(testMethod, out ITestMethodBase testMethodBase);
                var webTestMethod = (WebTestMethod)testMethodBase;

                if (webTestMethod?.WebDriver == null)
                {
                    throw;
                }

                var outputScreenshotsDirectory = TestManager.ConfigurationReader.GetConfigurationValue("OutputScreenshotsDirectory");

                var outputPath = !string.IsNullOrWhiteSpace(outputScreenshotsDirectory) ? outputScreenshotsDirectory : $"{TestContext.TestRunResultsDirectory}\\Screenshots";

                webTestMethod.WebDriver.ScreenShotSaveFile(outputPath, testMethod);

                throw;
            }
        }