Пример #1
0
        protected override void PostTestCleanup(object sender, TestWorkflowPluginEventArgs e)
        {
            var loadTestingWorkflowPluginContext = e.Container.Resolve <LoadTestingWorkflowPluginContext>();

            loadTestingWorkflowPluginContext?.PostTestCleanup();
            base.PostTestCleanup(sender, e);
        }
        private void InitializeTestCase(TestWorkflowPluginEventArgs args)
        {
            var methodInfo      = args.TestMethodMemberInfo;
            var methodAttribute = GetMethodAttribute <DynamicTestCaseAttribute>(methodInfo);
            var classAttribute  = GetClassAttribute <DynamicTestCaseAttribute>(args.TestClassType);

            classAttribute?.SetCustomProperties();
            methodAttribute?.SetCustomProperties();

            string suiteId       = methodAttribute?.SuiteId ?? classAttribute?.SuiteId ?? null;
            string testCaseName  = methodAttribute?.TestName ?? null;
            string testCaseId    = methodAttribute?.TestCaseId ?? null;
            string requirementId = methodAttribute?.RequirementId ?? classAttribute?.RequirementId ?? null;

            var testCaseDescription = methodAttribute?.Description ?? null;

            if (string.IsNullOrEmpty(testCaseName))
            {
                // test case name from the test method name
                testCaseName = TestNameToDesciption(args.TestName);
            }

            _dynamicTestCasesService.Context.SuiteId             = suiteId;
            _dynamicTestCasesService.Context.TestCaseName        = testCaseName;
            _dynamicTestCasesService.Context.TestCaseDescription = testCaseDescription;
            _dynamicTestCasesService.Context.TestCaseId          = testCaseId;
            _dynamicTestCasesService.Context.RequirementId       = requirementId;
            _dynamicTestCasesService.Context.TestFullName        = $"{args.TestClassName}.{args.TestName}";
        }
 protected override void PostTestCleanup(object sender, TestWorkflowPluginEventArgs e)
 {
     if (e.TestOutcome != TestOutcome.Passed)
     {
         LogExceptionTelemetry(e);
     }
 }
Пример #4
0
 protected override void PostAfterScenario(object sender, TestWorkflowPluginEventArgs e)
 {
     if (_currentAppConfiguration?.AppBehavior == AppBehavior.RestartOnFail && !e.TestOutcome.Equals(TestOutcome.Passed))
     {
         RestartApp();
     }
 }
Пример #5
0
        protected override void PreTestsArrange(object sender, TestWorkflowPluginEventArgs e)
        {
            if (e.TestClassType.GetCustomAttributes().Any(x => x.GetType().Equals(typeof(AppAttribute)) || x.GetType().IsSubclassOf(typeof(AppAttribute))))
            {
                // Resolve required data for decision making
                var appConfiguration = GetCurrentAppConfiguration(e.TestMethodMemberInfo, e.TestClassType, e.Container);

                if (appConfiguration != null)
                {
                    ResolvePreviousAppConfiguration(e.Container);

                    // Decide whether the app needs to be restarted
                    bool shouldRestartApp = ShouldRestartApp(e.Container);

                    if (shouldRestartApp)
                    {
                        RestartApp(e.Container);
                        e.Container.RegisterInstance(true, "_isAppStartedDuringPreTestsArrange");
                    }
                }
                else
                {
                    e.Container.RegisterInstance(true, "_isAppStartedDuringPreTestsArrange");
                }
            }

            base.PreTestsArrange(sender, e);
        }
Пример #6
0
        protected override void PreTestInit(object sender, TestWorkflowPluginEventArgs e)
        {
            bool isAppStartedDuringPreTestsArrange = e.Container.Resolve <bool>("_isAppStartedDuringPreTestsArrange");

            if (!isAppStartedDuringPreTestsArrange)
            {
                // Resolve required data for decision making
                var appConfiguration = GetCurrentAppConfiguration(e.TestMethodMemberInfo, e.TestClassType, e.Container);
                if (appConfiguration != null)
                {
                    ResolvePreviousAppConfiguration(e.Container);

                    // Decide whether the app needs to be restarted
                    bool shouldRestartApp = ShouldRestartApp(e.Container);

                    if (shouldRestartApp)
                    {
                        RestartApp(e.Container);
                    }
                }
            }

            e.Container.RegisterInstance(false, "_isAppStartedDuringPreTestsArrange");
            base.PreTestInit(sender, e);
        }
Пример #7
0
 public VideoPluginEventArgs(TestWorkflowPluginEventArgs testWorkflowPluginEventArgs, string videoPath)
     : base(testWorkflowPluginEventArgs.TestOutcome,
            testWorkflowPluginEventArgs.FeatureName,
            testWorkflowPluginEventArgs.ScenarioName,
            testWorkflowPluginEventArgs.ConsoleOutputMessage,
            testWorkflowPluginEventArgs.ConsoleOutputStackTrace,
            testWorkflowPluginEventArgs.FeatureTags,
            testWorkflowPluginEventArgs.ScenarioTags) => VideoPath = videoPath;
 protected override void PreTestInit(object sender, TestWorkflowPluginEventArgs e)
 {
     _hasStarted = false;
     StartTestContainer(e.TestFullName);
     StartTestCase(e.TestName, e.TestClassName, e.TestFullName);
     _hasStarted = true;
     base.PreTestInit(sender, e);
 }
Пример #9
0
 public ScreenshotPluginEventArgs(TestWorkflowPluginEventArgs testWorkflowPluginEventArgs, string screenshotPath)
     : base(testWorkflowPluginEventArgs.TestOutcome,
            testWorkflowPluginEventArgs.FeatureName,
            testWorkflowPluginEventArgs.ScenarioName,
            testWorkflowPluginEventArgs.ConsoleOutputMessage,
            testWorkflowPluginEventArgs.ConsoleOutputStackTrace,
            testWorkflowPluginEventArgs.FeatureTags,
            testWorkflowPluginEventArgs.ScenarioTags) => ScreenshotPath = screenshotPath;
Пример #10
0
        protected override void PreTestsArrange(object sender, TestWorkflowPluginEventArgs e)
        {
            var authenticator = GetAuthenticatorByType(e.TestClassType);

            if (authenticator != null)
            {
                e.Container.RegisterInstance(authenticator);
            }
        }
Пример #11
0
        protected override void TestInitFailed(object sender, TestWorkflowPluginEventArgs e)
        {
            StartTestContainer(e.TestFullName);
            StartTestCase(e.TestName, e.TestClassName, e.TestFullName);
            StopTestCase(e.Categories, e.Authors, e.Descriptions, e.TestMethodMemberInfo, e.TestOutcome, e.ConsoleOutputMessage, e.ConsoleOutputStackTrace);
            StopTestContainer();

            base.TestInitFailed(sender, e);
        }
Пример #12
0
        protected override void PreTestInit(object sender, TestWorkflowPluginEventArgs e)
        {
            if (!ConfigurationService.GetSection <BugReportingSettings>().IsEnabled)
            {
                return;
            }

            base.PreTestInit(sender, e);
            InitializeTestCase(e);
        }
Пример #13
0
        protected override void PostTestCleanup(object sender, TestWorkflowPluginEventArgs e)
        {
            var appConfiguration = GetCurrentAppConfiguration(e.TestMethodMemberInfo, e.TestClassType, e.Container);

            if (appConfiguration?.AppBehavior == AppBehavior.RestartEveryTime || (appConfiguration?.AppBehavior == AppBehavior.RestartOnFail && !e.TestOutcome.Equals(TestOutcome.Passed)))
            {
                ShutdownApp(e.Container);
                e.Container.RegisterInstance(false, "_isAppStartedDuringPreTestsArrange");
            }
        }
        protected override void PreTestsArrange(object sender, TestWorkflowPluginEventArgs e)
        {
            if (!ConfigurationService.GetSection <DynamicTestCasesSettings>().IsEnabled || e.TestMethodMemberInfo == null)
            {
                return;
            }

            base.PreTestsArrange(sender, e);

            InitializeTestCase(e);
        }
Пример #15
0
 public ScreenshotPluginEventArgs(TestWorkflowPluginEventArgs testWorkflowPluginEventArgs, string screenshotPath)
     : base(testWorkflowPluginEventArgs.TestOutcome,
            testWorkflowPluginEventArgs.TestName,
            testWorkflowPluginEventArgs.TestMethodMemberInfo,
            testWorkflowPluginEventArgs.TestClassType,
            testWorkflowPluginEventArgs.ConsoleOutputMessage,
            testWorkflowPluginEventArgs.ConsoleOutputStackTrace,
            testWorkflowPluginEventArgs.Exception,
            testWorkflowPluginEventArgs.Categories,
            testWorkflowPluginEventArgs.Authors,
            testWorkflowPluginEventArgs.Descriptions) => ScreenshotPath = screenshotPath;
Пример #16
0
        protected override void PostTestInit(object sender, TestWorkflowPluginEventArgs e)
        {
            RetryFailedRequestsInfo retryFailedRequestsInfo = GetRetryFailedRequestsInfo(e.TestMethodMemberInfo);

            if (retryFailedRequestsInfo != null)
            {
                var client = e.Container.Resolve <ApiClientService>();
                client.PauseBetweenFailures = TimeSpanConverter.Convert(retryFailedRequestsInfo.PauseBetweenFailures, retryFailedRequestsInfo.TimeUnit);
                client.MaxRetryAttempts     = retryFailedRequestsInfo.MaxRetryAttempts;
            }
        }
Пример #17
0
        protected override void PostTestCleanup(object sender, TestWorkflowPluginEventArgs e)
        {
            if (_hasStarted)
            {
                StopTestCase(e.Categories, e.Authors, e.Descriptions, e.TestMethodMemberInfo, e.TestOutcome, e.ConsoleOutputMessage, e.ConsoleOutputStackTrace);
                StopTestContainer();
            }

            _hasStarted = false;

            base.PostTestCleanup(sender, e);
        }
 private static void LogExceptionTelemetry(TestWorkflowPluginEventArgs e)
 {
     if (e.Exception != null && e.Exception.Source.StartsWith("Bellatrix.") &&
         !e.Exception.GetType().FullName.Contains("ElementPropertyValidateException") &&
         !e.Exception.GetType().FullName.Contains("LayoutAssertFailedException") &&
         !e.ConsoleOutputStackTrace.Contains("TimeoutException") &&
         !e.ConsoleOutputStackTrace.Contains("OpenQA.Selenium") &&
         !e.ConsoleOutputStackTrace.Contains("Bellatrix.TestExecutionExtensions.Screenshots"))
     {
         Telemetry.Instance.TrackException(e.Exception);
     }
 }
Пример #19
0
        protected override void PreBeforeScenario(object sender, TestWorkflowPluginEventArgs e)
        {
            VideoWorkflowPluginContext.RecordingMode = ConfigurationService.GetSection <VideoRecordingSettings>().IsEnabled ? VideoWorkflowPluginContext.RecordingMode : VideoRecordingMode.DoNotRecord;

            if (VideoWorkflowPluginContext.RecordingMode != VideoRecordingMode.DoNotRecord)
            {
                var videoRecordingDir      = _videoRecorderOutputProvider.GetOutputFolder();
                var videoRecordingFileName = _videoRecorderOutputProvider.GetUniqueFileName(e.TestFullName).Replace(" ", "_");

                _videoRecordingPath = _videoRecorder.Record(videoRecordingDir, videoRecordingFileName);
            }
        }
Пример #20
0
        private void InitializeTestCase(TestWorkflowPluginEventArgs args)
        {
            if (args.TestMethodMemberInfo == null)
            {
                return;
            }

            _filesToBeAttached = new List <string>();
            _bugReportingContextService.Context = new BugReportingContext();
            _bugReportingContextService.Context.TestCaseName    = TestNameToDesciption(args.TestName);
            _bugReportingContextService.Context.TestFullName    = $"{args.TestMethodMemberInfo.DeclaringType.Name}.{args.TestName}";
            _bugReportingContextService.Context.TestProjectName = args.TestMethodMemberInfo.DeclaringType.FullName;
        }
        protected override void PostBeforeScenario(object sender, TestWorkflowPluginEventArgs e)
        {
            var retryFailedRequestsInfo = new RetryFailedRequestsInfo()
            {
                MaxRetryAttempts     = _maxRetryAttempts,
                PauseBetweenFailures = _pauseBetweenFailures,
                TimeUnit             = _timeUnit,
            };

            var client = ServicesCollection.Current.Resolve <ApiClientService>();

            client.PauseBetweenFailures = TimeSpanConverter.Convert(retryFailedRequestsInfo.PauseBetweenFailures, retryFailedRequestsInfo.TimeUnit);
            client.MaxRetryAttempts     = retryFailedRequestsInfo.MaxRetryAttempts;
        }
Пример #22
0
        protected override void PostTestInit(object sender, TestWorkflowPluginEventArgs e)
        {
            _recordingMode = ConfigureTestVideoRecordingMode(e.TestMethodMemberInfo);

            if (_recordingMode != VideoRecordingMode.DoNotRecord)
            {
                var fullTestName           = $"{e.TestMethodMemberInfo.DeclaringType.Name}.{e.TestName}";
                var videoRecordingDir      = _videoRecorderOutputProvider.GetOutputFolder();
                var videoRecordingFileName = _videoRecorderOutputProvider.GetUniqueFileName(fullTestName);

                string videoRecordingPath = _videoRecorder.Record(videoRecordingDir, videoRecordingFileName);
                e.Container.RegisterInstance(videoRecordingPath, "_videoRecordingPath");
                e.Container.RegisterInstance(_videoRecorder, "_videoRecorder");
            }
        }
Пример #23
0
        protected override void PostTestCleanup(object sender, TestWorkflowPluginEventArgs e)
        {
            if (!ConfigurationService.GetSection <BugReportingSettings>().IsEnabled)
            {
                return;
            }

            base.PostTestCleanup(sender, e);

            if (e.TestOutcome == TestOutcome.Failed && _bugReportingContextService?.Context != null)
            {
                _bugReportingService.LogBug(_bugReportingContextService.Context, e.Exception.ToString(), _filesToBeAttached);
            }

            _bugReportingContextService?.ResetContext();
        }
        protected override void PreBeforeScenario(object sender, TestWorkflowPluginEventArgs e)
        {
            TimeSpan executionTimeout = GetExecutionTimeout(e.FeatureTags, e.ScenarioTags);

            if (executionTimeout != TimeSpan.MaxValue)
            {
                DateTime startTime = DateTime.Now;
                if (!_testsExecutionTimes.ContainsKey(e.TestFullName))
                {
                    _testsExecutionTimes.Add(e.TestFullName, startTime);
                }
                else
                {
                    _testsExecutionTimes[e.TestFullName] = startTime;
                }
            }
        }
        protected override void PostTestInit(object sender, TestWorkflowPluginEventArgs e)
        {
            TimeSpan executionTimeout = GetExecutionTimeout(e.TestMethodMemberInfo);
            string   testFullName     = GetTestFullName(e);

            if (executionTimeout != TimeSpan.MaxValue)
            {
                DateTime startTime = DateTime.Now;
                if (!_testsExecutionTimes.ContainsKey(testFullName))
                {
                    _testsExecutionTimes.Add(testFullName, startTime);
                }
                else
                {
                    _testsExecutionTimes[testFullName] = startTime;
                }
            }
        }
Пример #26
0
 protected override void PostAfterScenario(object sender, TestWorkflowPluginEventArgs e)
 {
     if (VideoWorkflowPluginContext.RecordingMode != VideoRecordingMode.DoNotRecord)
     {
         try
         {
             bool hasTestPassed = e.TestOutcome.Equals(TestOutcome.Passed);
             DeleteVideoDependingOnTestOutcome(hasTestPassed);
         }
         finally
         {
             _videoRecorder.Dispose();
             if (File.Exists(_videoRecordingPath))
             {
                 _videoPluginProvider.VideoGenerated(e, _videoRecordingPath);
             }
         }
     }
 }
        protected override void PostAfterScenario(object sender, TestWorkflowPluginEventArgs e)
        {
            TimeSpan executionTimeout = GetExecutionTimeout(e.FeatureTags, e.ScenarioTags);

            if (executionTimeout != TimeSpan.MaxValue)
            {
                DateTime endTime = DateTime.Now;
                if (_testsExecutionTimes.ContainsKey(e.TestFullName))
                {
                    var startTime          = _testsExecutionTimes[e.TestFullName];
                    var totalExecutionTime = endTime - startTime;
                    _testsExecutionTimes.Remove(e.TestFullName);
                    if (totalExecutionTime > executionTimeout)
                    {
                        throw new ExecutionTimeoutException($"The test {e.TestFullName} was executed for {totalExecutionTime}. The specified limit was {executionTimeout}.");
                    }
                }
            }
        }
        protected override void PostAfterScenario(object sender, TestWorkflowPluginEventArgs e)
        {
            if (_currentBrowserConfiguration != null)
            {
                if (_currentBrowserConfiguration.ShouldCaptureHttpTraffic)
                {
                    var proxyService = ServicesCollection.Current.Resolve <ProxyService>();
                    if (proxyService != null)
                    {
                        proxyService.RequestsHistory.Clear();
                        proxyService.ResponsesHistory.Clear();
                    }
                }

                if (_currentBrowserConfiguration.BrowserBehavior == BrowserBehavior.RestartEveryTime || (_currentBrowserConfiguration.BrowserBehavior == BrowserBehavior.RestartOnFail && !e.TestOutcome.Equals(TestOutcome.Passed)))
                {
                    ShutdownBrowser(e.Container);
                }
            }
        }
        protected override void PostTestCleanup(object sender, TestWorkflowPluginEventArgs e)
        {
            TimeSpan executionTimeout = GetExecutionTimeout(e.TestMethodMemberInfo);
            string   testFullName     = GetTestFullName(e);

            if (executionTimeout != TimeSpan.MaxValue)
            {
                DateTime endTime = DateTime.Now;
                if (_testsExecutionTimes.ContainsKey(testFullName))
                {
                    var startTime          = _testsExecutionTimes[testFullName];
                    var totalExecutionTime = endTime - startTime;
                    _testsExecutionTimes.Remove(testFullName);
                    if (totalExecutionTime > executionTimeout)
                    {
                        throw new ExecutionTimeoutException($"The test {testFullName} was executed for {totalExecutionTime}. The specified limit was {executionTimeout}.");
                    }
                }
            }
        }
Пример #30
0
        protected override void PreAfterScenario(object sender, TestWorkflowPluginEventArgs e)
        {
            GetTestScreenshotOnFailMode(e.TestOutcome);

            try
            {
                if (ScreenshotWorkflowPluginContext.ShouldTakeScreenshot)
                {
                    var    screenshotSaveDir  = _screenshotOutputProvider.GetOutputFolder();
                    var    screenshotFileName = _screenshotOutputProvider.GetUniqueFileName(e.TestFullName);
                    string image     = _screenshotEngine.TakeScreenshot(e.Container);
                    string imagePath = Path.Combine(screenshotSaveDir, screenshotFileName);
                    File.WriteAllBytes(imagePath, Convert.FromBase64String(image));
                    _screenshotPluginProvider.ScreenshotGenerated(e, imagePath);
                }
            }
            catch (Exception ex)
            {
                // Ignore
            }
        }