Esempio n. 1
0
        public void ShouldGetTagListFromScenarioAndSpec()
        {
            var specInfo = SpecInfo.CreateBuilder()
                           .AddTags("foo")
                           .SetName("")
                           .SetFileName("")
                           .SetIsFailed(false)
                           .Build();
            var scenarioInfo = ScenarioInfo.CreateBuilder()
                               .AddTags("bar")
                               .SetName("")
                               .SetIsFailed(false)
                               .Build();
            var currentScenario = ExecutionInfo.CreateBuilder()
                                  .SetCurrentScenario(scenarioInfo)
                                  .SetCurrentSpec(specInfo)
                                  .Build();
            var currentExecutionInfo = StepExecutionEndingRequest.CreateBuilder()
                                       .SetCurrentExecutionInfo(currentScenario)
                                       .Build();
            var message = Message.CreateBuilder()
                          .SetStepExecutionEndingRequest(currentExecutionInfo)
                          .SetMessageType(Message.Types.MessageType.StepExecutionEnding)
                          .SetMessageId(0)
                          .Build();
            var tags = AssertEx.ExecuteProtectedMethod <StepExecutionEndingProcessor>("GetApplicableTags", message).ToList();

            Assert.IsNotEmpty(tags);
            Assert.AreEqual(2, tags.Count);
            Assert.Contains("foo", tags);
            Assert.Contains("bar", tags);
        }
        public void ShouldGetTagListFromScenarioAndSpecAndIgnoreDuplicates()
        {
            var specInfo = new SpecInfo
            {
                Tags     = { "foo" },
                Name     = "",
                FileName = "",
                IsFailed = false
            };
            var scenarioInfo = new ScenarioInfo
            {
                Tags     = { "foo" },
                Name     = "",
                IsFailed = false
            };
            var currentScenario = new ExecutionInfo
            {
                CurrentScenario = scenarioInfo,
                CurrentSpec     = specInfo
            };
            var currentExecutionInfo = new StepExecutionEndingRequest
            {
                CurrentExecutionInfo = currentScenario
            };

            var tags = AssertEx.ExecuteProtectedMethod <StepExecutionEndingProcessor>("GetApplicableTags", currentScenario)
                       .ToList();

            Assert.IsNotEmpty(tags);
            Assert.AreEqual(1, tags.Count);
            Assert.Contains("foo", tags);
        }
        public void Setup()
        {
            var mockHookRegistry           = new Mock <IHookRegistry>();
            var mockAssemblyLoader         = new Mock <IAssemblyLoader>();
            var mockMessageCollectorType   = new Mock <Type>();
            var mockScreenshtCollectorType = new Mock <Type>();

            mockAssemblyLoader.Setup(x => x.GetLibType(LibType.MessageCollector))
            .Returns(mockMessageCollectorType.Object);
            mockAssemblyLoader.Setup(x => x.GetLibType(LibType.ScreenshotCollector))
            .Returns(mockScreenshtCollectorType.Object);
            var mockMethod = new MockMethodBuilder(mockAssemblyLoader)
                             .WithName("Foo")
                             .WithFilteredHook(LibType.BeforeSpec)
                             .Build();
            var hooks = new HashSet <IHookMethod>
            {
                new HookMethod(LibType.BeforeSpec, mockMethod, mockAssemblyLoader.Object)
            };

            mockHookRegistry.Setup(x => x.AfterStepHooks).Returns(hooks);
            var stepExecutionEndingRequest = new StepExecutionEndingRequest
            {
                CurrentExecutionInfo = new ExecutionInfo
                {
                    CurrentSpec     = new SpecInfo(),
                    CurrentScenario = new ScenarioInfo()
                }
            };

            _request = new Message
            {
                MessageType = Message.Types.MessageType.StepExecutionEnding,
                MessageId   = 20,
                StepExecutionEndingRequest = stepExecutionEndingRequest
            };

            _mockMethodExecutor   = new Mock <IExecutionOrchestrator>();
            _protoExecutionResult = new ProtoExecutionResult
            {
                ExecutionTime = 0,
                Failed        = false
            };

            _mockMethodExecutor.Setup(x =>
                                      x.ExecuteHooks("AfterStep", It.IsAny <HooksStrategy>(), It.IsAny <IList <string> >(),
                                                     It.IsAny <ExecutionContext>()))
            .Returns(_protoExecutionResult);
            _mockMethodExecutor.Setup(x =>
                                      x.GetAllPendingMessages()).Returns(_pendingMessages);
            _mockMethodExecutor.Setup(x =>
                                      x.GetAllPendingScreenshots()).Returns(_pendingScreenshots);
            _stepExecutionEndingProcessor = new StepExecutionEndingProcessor(_mockMethodExecutor.Object);
        }
Esempio n. 4
0
        public void Setup()
        {
            var mockHookRegistry         = new Mock <IHookRegistry>();
            var mockSandbox              = new Mock <ISandbox>();
            var mockAssemblyLoader       = new Mock <IAssemblyLoader>();
            var mockMessageCollectorType = new Mock <Type>();

            mockAssemblyLoader.Setup(x => x.GetLibType(LibType.MessageCollector))
            .Returns(mockMessageCollectorType.Object);
            var mockMethod = new MockMethodBuilder(mockAssemblyLoader)
                             .WithName("Foo")
                             .WithFilteredHook(LibType.BeforeSpec)
                             .Build();
            var hooks = new HashSet <IHookMethod>
            {
                new HookMethod(LibType.BeforeSpec, mockMethod, mockAssemblyLoader.Object)
            };

            mockHookRegistry.Setup(x => x.AfterStepHooks).Returns(hooks);
            var stepExecutionEndingRequest = new StepExecutionEndingRequest
            {
                CurrentExecutionInfo = new ExecutionInfo
                {
                    CurrentSpec     = new SpecInfo(),
                    CurrentScenario = new ScenarioInfo()
                }
            };

            _request = new Message
            {
                MessageType = Message.Types.MessageType.StepExecutionEnding,
                MessageId   = 20,
                StepExecutionEndingRequest = stepExecutionEndingRequest
            };

            _mockMethodExecutor   = new Mock <IMethodExecutor>();
            _protoExecutionResult = new ProtoExecutionResult
            {
                ExecutionTime = 0,
                Failed        = false,
                Message       = {}
            };
            _mockMethodExecutor.Setup(x =>
                                      x.ExecuteHooks("AfterStep", It.IsAny <TaggedHooksFirstStrategy>(), new List <string>()))
            .Returns(_protoExecutionResult);
            var mockReflectionWrapper = new Mock <IReflectionWrapper>();

            mockReflectionWrapper.Setup(x => x.InvokeMethod(mockMessageCollectorType.Object, null, "GetAllPendingMessages", BindingFlags.Static | BindingFlags.Public))
            .Returns(_pendingMessages);
            _stepExecutionEndingProcessor = new StepExecutionEndingProcessor(_mockMethodExecutor.Object, mockAssemblyLoader.Object, mockReflectionWrapper.Object);
        }
Esempio n. 5
0
        public override Task <Empty> NotifyStepExecutionEnding(StepExecutionEndingRequest request, ServerCallContext context)
        {
            try
            {
                TraceLogger.Info($"{nameof(NotifyStepExecutionEnding)} received");
                TraceLogger.Verbose(System.Text.Json.JsonSerializer.Serialize(request));

                if (request.StepResult != null)
                {
                    _sender.FinishStep(request);
                }
            }
            catch (Exception exp)
            {
                TraceLogger.Error(exp.ToString());
            }

            return(Task.FromResult(new Empty()));
        }
Esempio n. 6
0
        public void Setup()
        {
            var mockHookRegistry = new Mock <IHookRegistry>();
            var mockSandbox      = new Mock <ISandbox>();

            mockSandbox.Setup(sandbox => sandbox.GetAllPendingMessages()).Returns(_pendingMessages);
            var hooks = new HashSet <IHookMethod>
            {
                new HookMethod("BeforeSpec", GetType().GetMethod("Foo"), typeof(Step).Assembly)
            };

            mockHookRegistry.Setup(x => x.AfterStepHooks).Returns(hooks);
            var stepExecutionEndingRequest = new StepExecutionEndingRequest
            {
                CurrentExecutionInfo = new ExecutionInfo
                {
                    CurrentSpec     = new SpecInfo(),
                    CurrentScenario = new ScenarioInfo()
                }
            };

            _request = new Message
            {
                MessageType = Message.Types.MessageType.StepExecutionEnding,
                MessageId   = 20,
                StepExecutionEndingRequest = stepExecutionEndingRequest
            };

            _mockMethodExecutor   = new Mock <IMethodExecutor>();
            _protoExecutionResult = new ProtoExecutionResult
            {
                ExecutionTime = 0,
                Failed        = false,
                Message       = { _pendingMessages }
            };
            _mockMethodExecutor.Setup(x =>
                                      x.ExecuteHooks("AfterStep", It.IsAny <TaggedHooksFirstStrategy>(), new List <string>(), It.IsAny <ExecutionContext>()))
            .Returns(_protoExecutionResult);
            _stepExecutionEndingProcessor = new StepExecutionEndingProcessor(_mockMethodExecutor.Object);
        }
Esempio n. 7
0
        public void ShouldGetTagListFromScenarioAndSpec()
        {
            var specInfo = new SpecInfo
            {
                Tags     = { "foo" },
                Name     = "",
                FileName = "",
                IsFailed = false
            };
            var scenarioInfo = new ScenarioInfo
            {
                Tags     = { "bar" },
                Name     = "",
                IsFailed = false
            };
            var currentScenario = new ExecutionInfo
            {
                CurrentScenario = scenarioInfo,
                CurrentSpec     = specInfo
            };
            var currentExecutionInfo = new StepExecutionEndingRequest
            {
                CurrentExecutionInfo = currentScenario
            };
            var message = new Message
            {
                StepExecutionEndingRequest = currentExecutionInfo,
                MessageType = Message.Types.MessageType.StepExecutionEnding,
                MessageId   = 0
            };
            var tags = AssertEx.ExecuteProtectedMethod <StepExecutionEndingProcessor>("GetApplicableTags", message)
                       .ToList();

            Assert.IsNotEmpty(tags);
            Assert.AreEqual(2, tags.Count);
            Assert.Contains("foo", tags);
            Assert.Contains("bar", tags);
        }
Esempio n. 8
0
 public override Task <ExecutionStatusResponse> FinishStepExecution(StepExecutionEndingRequest request, ServerCallContext context)
 {
     return(_pool.Execute(getStream(request.Stream), () => this.stepExecutionEndingProcessor.Process(request)));
 }
 public override Task <ExecutionStatusResponse> FinishStepExecution(StepExecutionEndingRequest request, ServerCallContext context)
 {
     return(Task.FromResult(this.stepExecutionEndingProcessor.Process(request)));
 }
 public ExecutionStatusResponse Process(StepExecutionEndingRequest request)
 {
     return(base.ExecuteHooks(request.CurrentExecutionInfo));
 }
 public override Task <Empty> NotifyStepExecutionEnding(StepExecutionEndingRequest request, ServerCallContext context)
 {
     return(Task.FromResult(new Empty()));
 }
Esempio n. 12
0
        public void FinishStep(StepExecutionEndingRequest request)
        {
            var key = GetStepKey(request.CurrentExecutionInfo, request.CurrentExecutionInfo.CurrentSpec, request.CurrentExecutionInfo.CurrentScenario, request.CurrentExecutionInfo.CurrentStep);

            TraceLogger.Verbose($"Finishing step with key: {key}");
            var stepReporter = _steps[key];

            var stepStatus = Status.Passed;

            // process gauge log messages
            var logMessages = request.StepResult.ProtoItem.Step.StepExecutionResult.ExecutionResult.Message;

            if (logMessages != null)
            {
                foreach (var logMessage in logMessages)
                {
                    stepReporter.Log(new CreateLogItemRequest
                    {
                        Text  = logMessage,
                        Level = LogLevel.Debug,
                        Time  = DateTime.UtcNow
                    });
                }
            }

            // todo it's never skipped
            if (request.StepResult.ProtoItem.Step.StepExecutionResult.Skipped)
            {
                stepStatus = Status.Skipped;

                stepReporter.Log(new CreateLogItemRequest
                {
                    Time  = DateTime.UtcNow,
                    Level = LogLevel.Info,
                    Text  = $"Skip reason: {request.StepResult.ProtoItem.Step.StepExecutionResult.SkippedReason}"
                });
            }
            ;

            if (request.StepResult.ProtoItem.Step.StepExecutionResult.ExecutionResult.Failed)
            {
                stepStatus = Status.Failed;

                stepReporter.Log(new CreateLogItemRequest
                {
                    Time  = DateTime.UtcNow,
                    Level = LogLevel.Error,
                    Text  = $"{request.StepResult.ProtoItem.Step.StepExecutionResult.ExecutionResult.ErrorMessage}{Environment.NewLine}{Environment.NewLine}{request.StepResult.ProtoItem.Step.StepExecutionResult.ExecutionResult.StackTrace}"
                });
            }

            // process custom screenshots
            var screenshots = request.StepResult.ProtoItem.Step.StepExecutionResult.ExecutionResult.ScreenshotFiles;

            if (screenshots != null)
            {
                foreach (var screeenshot in screenshots)
                {
                    AttachScreenshot(screeenshot, LogLevel.Info, stepReporter);
                }
            }

            // process screenshot on failure
            AttachScreenshot(request.StepResult.ProtoItem.Step.StepExecutionResult.ExecutionResult.FailureScreenshotFile, LogLevel.Error, stepReporter);

            // post hook messages
            if (request.StepResult.ProtoItem.Step.PostHookMessages.Count != 0)
            {
                foreach (var postHookMessage in request.StepResult.ProtoItem.Step.PostHookMessages)
                {
                    stepReporter.Log(new CreateLogItemRequest
                    {
                        Level = LogLevel.Debug,
                        Text  = postHookMessage,
                        Time  = DateTime.UtcNow
                    });
                }
            }

            stepReporter.Finish(new FinishTestItemRequest
            {
                EndTime = DateTime.UtcNow,
                Status  = stepStatus
            });

            _steps.TryRemove(key, out _);
        }
Esempio n. 13
0
        public void FinishStep(StepExecutionEndingRequest request)
        {
            var key = GetStepKey(request.CurrentExecutionInfo, request.CurrentExecutionInfo.CurrentSpec, request.CurrentExecutionInfo.CurrentScenario, request.CurrentExecutionInfo.CurrentStep);

            TraceLogger.Verbose($"Finishing step with key: {key}");
            var stepReporter = _steps[key];

            var stepStatus = Status.Passed;

            // process gauge log messages
            var logMessages = request.StepResult.ProtoItem.Step.StepExecutionResult.ExecutionResult.Message;

            if (logMessages != null)
            {
                foreach (var logMessage in logMessages)
                {
                    stepReporter.Log(new CreateLogItemRequest
                    {
                        Text  = logMessage,
                        Level = LogLevel.Debug,
                        Time  = DateTime.UtcNow
                    });
                }
            }

            // todo it's never skipped
            if (request.StepResult.ProtoItem.Step.StepExecutionResult.Skipped)
            {
                stepStatus = Status.Skipped;

                stepReporter.Log(new CreateLogItemRequest
                {
                    Time  = DateTime.UtcNow,
                    Level = LogLevel.Info,
                    Text  = $"Skip reason: {request.StepResult.ProtoItem.Step.StepExecutionResult.SkippedReason}"
                });
            }
            ;

            if (request.StepResult.ProtoItem.Step.StepExecutionResult.ExecutionResult.Failed)
            {
                stepStatus = Status.Failed;

                stepReporter.Log(new CreateLogItemRequest
                {
                    Time  = DateTime.UtcNow,
                    Level = LogLevel.Error,
                    Text  = $"{request.StepResult.ProtoItem.Step.StepExecutionResult.ExecutionResult.ErrorMessage}{Environment.NewLine}{Environment.NewLine}{request.StepResult.ProtoItem.Step.StepExecutionResult.ExecutionResult.StackTrace}"
                });
            }

            try
            {
                var failureScreenshotFile = request.StepResult.ProtoItem.Step.StepExecutionResult.ExecutionResult.FailureScreenshotFile;
                if (!string.IsNullOrEmpty(failureScreenshotFile))
                {
                    stepReporter.Log(new CreateLogItemRequest
                    {
                        Time   = DateTime.UtcNow,
                        Level  = LogLevel.Error,
                        Text   = "Screenshot",
                        Attach = new Attach
                        {
                            Name     = "screenshot",
                            MimeType = Shared.MimeTypes.MimeTypeMap.GetMimeType(Path.GetExtension(failureScreenshotFile)),
                            Data     = File.ReadAllBytes(Path.Combine(_gaugeScreenshotsDir, failureScreenshotFile))
                        }
                    });
                }
            }
            catch (Exception exp)
            {
                TraceLogger.Error($"Couldn't parse failure step screenshot. {exp}");
            }

            // post hook messages
            if (request.StepResult.ProtoItem.Step.PostHookMessages.Count != 0)
            {
                foreach (var postHookMessage in request.StepResult.ProtoItem.Step.PostHookMessages)
                {
                    stepReporter.Log(new CreateLogItemRequest
                    {
                        Level = LogLevel.Debug,
                        Text  = postHookMessage,
                        Time  = DateTime.UtcNow
                    });
                }
            }

            stepReporter.Finish(new FinishTestItemRequest
            {
                EndTime = DateTime.UtcNow,
                Status  = stepStatus
            });

            _steps.TryRemove(key, out _);
        }