public void MixingTestsAndLogs() { var service = new MockServiceBuilder().Build(); var launchReporter = new LaunchReporter(service.Object, null, null, new ExtensionManager()); launchReporter.Start(new StartLaunchRequest { StartTime = DateTime.UtcNow }); for (int i = 0; i < 10; i++) { var suite = launchReporter.StartChildTestReporter(new StartTestItemRequest { StartTime = DateTime.UtcNow }); suite.Log(new CreateLogItemRequest { Time = DateTime.UtcNow }); for (int j = 0; j < 20; j++) { var test = suite.StartChildTestReporter(new StartTestItemRequest { StartTime = DateTime.UtcNow }); test.Log(new CreateLogItemRequest { Time = DateTime.UtcNow }); test.Finish(new FinishTestItemRequest { EndTime = DateTime.UtcNow }); } suite.Log(new CreateLogItemRequest { Time = DateTime.UtcNow }); suite.Finish(new FinishTestItemRequest { EndTime = DateTime.UtcNow }); } launchReporter.Finish(new FinishLaunchRequest { EndTime = DateTime.UtcNow }); launchReporter.Sync(); }
public async Task UseExistingLaunchId() { var launchDateTime = DateTime.UtcNow; var launch = await _service.Launch.StartAsync(new StartLaunchRequest { Name = "UseExistingLaunchId", StartTime = launchDateTime, Mode = LaunchMode.Debug }); var config = new ConfigurationBuilder().Build(); config.Properties["Launch:Id"] = launch.Uuid; var launchReporter = new LaunchReporter(_service, config, null, new ExtensionManager()); launchReporter.Start(new StartLaunchRequest { Name = "SomeOtherName", StartTime = launchDateTime.AddDays(1) }); launchReporter.Finish(new FinishLaunchRequest { EndTime = DateTime.UtcNow }); launchReporter.Sync(); Assert.Equal(launch.Uuid, launchReporter.Info.Uuid); Assert.Equal(launchDateTime.ToString(), launchReporter.Info.StartTime.ToString()); var reportedLaunch = await _service.Launch.GetAsync(launch.Uuid); Assert.Equal("UseExistingLaunchId", reportedLaunch.Name); Assert.Equal(launchDateTime.ToString(), reportedLaunch.StartTime.ToString()); await _service.Launch.FinishAsync(launch.Uuid, new FinishLaunchRequest { EndTime = DateTime.UtcNow }); var gotLaunch = await _service.Launch.GetAsync(launchReporter.Info.Uuid); await _service.Launch.DeleteAsync(gotLaunch.Id); }
public void End() { // End all tests & suites foreach (var test in _context.GetTests()) { FinishTestItem(test); } foreach (var suite in _context.GetSuites()) { suite.Finish(new FinishTestItemRequest { EndTime = DateTime.UtcNow }); } //Finish launch _launchReporter.Finish(new FinishLaunchRequest { EndTime = DateTime.UtcNow }); _launchReporter.Sync(); }
public void LaunchShouldCareOfFinishTime() { var launchStartTime = DateTime.UtcNow; var service = new MockServiceBuilder().Build(); var launch = new LaunchReporter(service.Object, null, null, new ExtensionManager()); launch.Start(new StartLaunchRequest() { StartTime = launchStartTime }); launch.Finish(new FinishLaunchRequest() { EndTime = launchStartTime.AddDays(-1) }); launch.Sync(); launch.Info.FinishTime.Should().Be(launch.Info.StartTime); }
public void ShouldBeAbleToLogIntoLaunch() { var service = new MockServiceBuilder().Build(); var launch = new LaunchReporter(service.Object, null, null, new ExtensionManager()); launch.Start(new StartLaunchRequest() { StartTime = DateTime.UtcNow }); launch.Log(new CreateLogItemRequest { Time = DateTime.UtcNow, Text = "log" }); launch.Finish(new FinishLaunchRequest() { EndTime = DateTime.UtcNow }); launch.Sync(); service.Verify(s => s.LogItem.CreateAsync(It.IsAny <CreateLogItemRequest[]>()), Times.Once); }
public void FailedLaunchLogShouldNotBreakReporting() { var service = new MockServiceBuilder().Build(); service.Setup(s => s.LogItem.CreateAsync(It.IsAny <CreateLogItemRequest>())).Throws(new Exception()); var launch = new LaunchReporter(service.Object, null, null, new ExtensionManager()); launch.Start(new StartLaunchRequest() { StartTime = DateTime.UtcNow }); launch.Log(new CreateLogItemRequest { Time = DateTime.UtcNow, Text = "log" }); launch.Finish(new FinishLaunchRequest() { EndTime = DateTime.UtcNow }); launch.Sync(); }
public void LaunchReporter() { var configuration = new Configuration.ConfigurationBuilder().Build(); var nopService = new NopService(); var launchReporter = new LaunchReporter(nopService, configuration, null, new ExtensionManager()); var launchDateTime = DateTime.UtcNow; launchReporter.Start(new StartLaunchRequest { Name = "ReportPortal Benchmark", StartTime = launchDateTime, Mode = LaunchMode.Debug }); for (int i = 0; i < SuitesCount; i++) { var suiteNode = launchReporter.StartChildTestReporter(new StartTestItemRequest { Name = $"Suite {i}", StartTime = launchDateTime.AddMilliseconds(-1), Type = TestItemType.Suite }); suiteNode.Finish(new FinishTestItemRequest { EndTime = launchDateTime, Status = Status.Passed }); } launchReporter.Finish(new FinishLaunchRequest { EndTime = launchDateTime }); launchReporter.Sync(); }
public void ShouldNotLogIfLaunchFailedToStart() { var service = new MockServiceBuilder().Build(); service.Setup(s => s.Launch.StartAsync(It.IsAny <StartLaunchRequest>())).Throws(new Exception()); var launch = new LaunchReporter(service.Object, null, null, new ExtensionManager()); launch.Start(new StartLaunchRequest() { StartTime = DateTime.UtcNow }); launch.Log(new CreateLogItemRequest { Time = DateTime.UtcNow, Text = "log" }); Action waitAct = () => launch.Sync(); waitAct.Should().Throw <Exception>(); service.Verify(s => s.LogItem.CreateAsync(It.IsAny <CreateLogItemRequest>()), Times.Never); }
public void RerunLaunch() { var service = new MockServiceBuilder().Build(); var config = new Shared.Configuration.ConfigurationBuilder().Build(); config.Properties["Launch:RerunOf"] = "any_uuid_of_existing_launch"; var launch = new LaunchReporter(service.Object, config, null, new Mock <IExtensionManager>().Object); launch.Start(new StartLaunchRequest() { StartTime = DateTime.UtcNow }); launch.Finish(new FinishLaunchRequest() { EndTime = DateTime.UtcNow }); launch.Sync(); service.Verify(s => s.Launch.StartAsync(It.IsAny <StartLaunchRequest>()), Times.Once); service.Verify(s => s.Launch.FinishAsync(It.IsAny <string>(), It.IsAny <FinishLaunchRequest>()), Times.Never); }
public async Task UseRerunLaunchId() { var launchDateTime = DateTime.UtcNow; var launchName = "UseRerunLaunchId"; var launch = await _service.Launch.StartAsync(new StartLaunchRequest { Name = launchName, StartTime = launchDateTime, Mode = LaunchMode.Debug }); var config = new ConfigurationBuilder().Build(); config.Properties["Launch:RerunOf"] = launch.Uuid; var tasks = new List <Task <LaunchReporter> >(); for (int i = 0; i < 3; i++) { tasks.Add(Task.Run(() => { var r_launch = new LaunchReporter(_service, config, null, null); r_launch.Start(new StartLaunchRequest { Name = "UseRerunLaunchId", StartTime = launchDateTime, Mode = LaunchMode.Debug }); for (int j = 0; j < 30; j++) { var r_suiteReporter = r_launch.StartChildTestReporter(new StartTestItemRequest { Name = $"Suite {j}", StartTime = launchDateTime, Type = TestItemType.Suite }); for (int jj = 0; jj < 3; jj++) { var rr_suiteReporter = r_suiteReporter.StartChildTestReporter(new StartTestItemRequest { Name = $"Suite {jj}", StartTime = launchDateTime, Type = TestItemType.Suite }); for (int k = 0; k < 0; k++) { var r_test = rr_suiteReporter.StartChildTestReporter(new StartTestItemRequest { Name = $"Test {k}", StartTime = launchDateTime, Type = TestItemType.Step }); for (int l = 0; l < 0; l++) { r_test.Log(new CreateLogItemRequest { Level = LogLevel.Info, Text = $"Log message #{l}", Time = launchDateTime }); } r_test.Finish(new FinishTestItemRequest { EndTime = launchDateTime, Status = Status.Passed }); } rr_suiteReporter.Finish(new FinishTestItemRequest { EndTime = launchDateTime, Status = Status.Passed }); } r_suiteReporter.Finish(new FinishTestItemRequest { EndTime = launchDateTime, Status = Status.Passed }); } r_launch.Finish(new FinishLaunchRequest { EndTime = launchDateTime }); r_launch.Sync(); return(r_launch); })); } Task.WaitAll(tasks.ToArray()); var reportedLaunch = await _service.Launch.GetAsync(launch.Uuid); Assert.Equal(launchName, reportedLaunch.Name); Assert.Equal(launchDateTime.ToString(), reportedLaunch.StartTime.ToString()); await _service.Launch.FinishAsync(launch.Uuid, new FinishLaunchRequest { EndTime = DateTime.UtcNow }); //var gotLaunch = await _service.Launch.GetAsync(launchReporter.LaunchInfo.Uuid); //await _service.Launch.DeleteAsync(gotLaunch.Id); }
public async Task UseRerun() { var launchDateTime = DateTime.UtcNow; var launchName = "UseRerun"; var launch = await _service.Launch.StartAsync(new StartLaunchRequest { Name = launchName, StartTime = launchDateTime, Mode = LaunchMode.Debug }); await _service.Launch.FinishAsync(launch.Uuid, new FinishLaunchRequest { EndTime = DateTime.UtcNow }); var config = new ConfigurationBuilder().Build(); config.Properties["Launch:Rerun"] = true; var r_launch = new LaunchReporter(_service, config, null, new ExtensionManager()); r_launch.Start(new StartLaunchRequest { Name = "UseRerun", StartTime = launchDateTime, Mode = LaunchMode.Debug }); for (int j = 0; j < 1; j++) { var r_suiteReporter = r_launch.StartChildTestReporter(new StartTestItemRequest { Name = $"Suite {j}", StartTime = launchDateTime, Type = TestItemType.Suite }); for (int jj = 0; jj < 1; jj++) { var rr_suiteReporter = r_suiteReporter.StartChildTestReporter(new StartTestItemRequest { Name = $"Suite {jj}", StartTime = launchDateTime, Type = TestItemType.Suite }); for (int k = 0; k < 10; k++) { var r_test = rr_suiteReporter.StartChildTestReporter(new StartTestItemRequest { Name = $"Test {k}", StartTime = launchDateTime, Type = TestItemType.Step }); for (int l = 0; l < 0; l++) { r_test.Log(new CreateLogItemRequest { Level = LogLevel.Info, Text = $"Log message #{l}", Time = launchDateTime }); } r_test.Finish(new FinishTestItemRequest { EndTime = launchDateTime, Status = Status.Passed }); } rr_suiteReporter.Finish(new FinishTestItemRequest { EndTime = launchDateTime, Status = Status.Passed }); } r_suiteReporter.Finish(new FinishTestItemRequest { EndTime = launchDateTime, Status = Status.Passed }); } r_launch.Finish(new FinishLaunchRequest { EndTime = launchDateTime }); r_launch.Sync(); var reportedLaunch = await _service.Launch.GetAsync(r_launch.Info.Uuid); Assert.Equal(launchName, reportedLaunch.Name); Assert.Equal(launchDateTime.ToString(), reportedLaunch.StartTime.ToString()); var gotLaunch = await _service.Launch.GetAsync(r_launch.Info.Uuid); await _service.Launch.DeleteAsync(gotLaunch.Id); }
static void Main(string[] args) { var port = Convert.ToInt32(Environment.GetEnvironmentVariable("plugin_connection_port")); var rpUri = new Uri(Config.GetValue <string>("Uri")); var rpProject = Config.GetValue <string>("Project"); var rpUuid = Config.GetValue <string>("Uuid"); var service = new Service(rpUri, rpProject, rpUuid); var launchReporter = new LaunchReporter(service, Config, requestExecuterFactory: null); using (var gaugeConnection = new GaugeConnection(new TcpClientWrapper(port))) { while (gaugeConnection.Connected) { var message = Message.Parser.ParseFrom(gaugeConnection.ReadBytes().ToArray()); if (message.MessageType == Message.Types.MessageType.SuiteExecutionResult) { var suiteExecutionResult = message.SuiteExecutionResult.SuiteResult; var launchStartDateTime = DateTime.UtcNow.AddMilliseconds(-suiteExecutionResult.ExecutionTime); launchReporter.Start(new Client.Requests.StartLaunchRequest { Name = Config.GetValue("Launch:Name", suiteExecutionResult.ProjectName), Description = Config.GetValue("Launch:Description", string.Empty), Tags = Config.GetValues("Launch:Tags", new List <string>()).ToList(), StartTime = launchStartDateTime }); foreach (var specResult in suiteExecutionResult.SpecResults) { var specStartTime = launchStartDateTime; var specReporter = launchReporter.StartChildTestReporter(new Client.Requests.StartTestItemRequest { Type = Client.Models.TestItemType.Suite, Name = specResult.ProtoSpec.SpecHeading, Description = string.Join("", specResult.ProtoSpec.Items.Where(i => i.ItemType == ProtoItem.Types.ItemType.Comment).Select(c => c.Comment.Text)), StartTime = specStartTime, Tags = specResult.ProtoSpec.Tags.Select(t => t.ToString()).ToList() }); foreach (var scenarioResult in specResult.ProtoSpec.Items.Where(i => i.ItemType == ProtoItem.Types.ItemType.Scenario || i.ItemType == ProtoItem.Types.ItemType.TableDrivenScenario)) { ProtoScenario scenario; switch (scenarioResult.ItemType) { case ProtoItem.Types.ItemType.Scenario: scenario = scenarioResult.Scenario; break; case ProtoItem.Types.ItemType.TableDrivenScenario: scenario = scenarioResult.TableDrivenScenario.Scenario; break; default: scenario = scenarioResult.Scenario; break; } var scenarioStartTime = specStartTime; var scenarioReporter = specReporter.StartChildTestReporter(new Client.Requests.StartTestItemRequest { Type = Client.Models.TestItemType.Step, StartTime = scenarioStartTime, Name = scenario.ScenarioHeading, Description = string.Join("", scenario.ScenarioItems.Where(i => i.ItemType == ProtoItem.Types.ItemType.Comment).Select(c => c.Comment.Text)), Tags = scenario.Tags.Select(t => t.ToString()).ToList() }); // internal log ("rp_log_enabled" property) if (Config.GetValue("log:enabled", false)) { scenarioReporter.Log(new Client.Requests.AddLogItemRequest { Text = "Spec Result Proto", Level = Client.Models.LogLevel.Trace, Time = DateTime.UtcNow, Attach = new Client.Models.Attach("Spec", "application/json", System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(specResult))) }); scenarioReporter.Log(new Client.Requests.AddLogItemRequest { Text = "Scenario Result Proto", Level = Client.Models.LogLevel.Trace, Time = DateTime.UtcNow, Attach = new Client.Models.Attach("Scenario", "application/json", System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(scenarioResult))) }); } var lastStepStartTime = scenarioStartTime; if (scenario.ScenarioItems != null) { foreach (var stepResult in scenario.ScenarioItems.Where(i => i.ItemType == ProtoItem.Types.ItemType.Step)) { var text = "!!!MARKDOWN_MODE!!!" + stepResult.Step.ActualText; var stepLogLevel = stepResult.Step.StepExecutionResult.ExecutionResult.Failed ? Client.Models.LogLevel.Error : Client.Models.LogLevel.Info; // if step argument is table var tableParameter = stepResult.Step.Fragments.FirstOrDefault(f => f.Parameter?.Table != null)?.Parameter.Table; if (tableParameter != null) { text += Environment.NewLine + Environment.NewLine + "| " + string.Join(" | ", tableParameter.Headers.Cells.ToArray()) + " |"; text += Environment.NewLine + "| " + string.Join(" | ", tableParameter.Headers.Cells.Select(c => "---")) + " |"; foreach (var tableRow in tableParameter.Rows) { text += Environment.NewLine + "| " + string.Join(" | ", tableRow.Cells.ToArray()) + " |"; } } // if dynamic arguments var dynamicParameteres = stepResult.Step.Fragments.Where(f => f.FragmentType == Fragment.Types.FragmentType.Parameter && f.Parameter.ParameterType == Parameter.Types.ParameterType.Dynamic).Select(f => f.Parameter); if (dynamicParameteres.Count() != 0) { text += Environment.NewLine; foreach (var dynamicParameter in dynamicParameteres) { text += $"{Environment.NewLine}{dynamicParameter.Name}: {dynamicParameter.Value}"; } } if (stepResult.Step.StepExecutionResult.ExecutionResult.Failed) { text += $"{Environment.NewLine}{Environment.NewLine}{stepResult.Step.StepExecutionResult.ExecutionResult.ErrorMessage}{Environment.NewLine}{stepResult.Step.StepExecutionResult.ExecutionResult.StackTrace}"; } scenarioReporter.Log(new Client.Requests.AddLogItemRequest { Level = stepLogLevel, Time = lastStepStartTime, Text = text }); if (stepResult.Step.StepExecutionResult.ExecutionResult.ScreenShot?.Length != 0) { scenarioReporter.Log(new Client.Requests.AddLogItemRequest { Level = Client.Models.LogLevel.Debug, Time = lastStepStartTime, Text = "Screenshot", Attach = new Client.Models.Attach("Screenshot", "image/png", stepResult.Step.StepExecutionResult.ExecutionResult.ScreenShot.ToByteArray()) }); } lastStepStartTime = lastStepStartTime.AddMilliseconds(stepResult.Step.StepExecutionResult.ExecutionResult.ExecutionTime); } } scenarioReporter.Finish(new Client.Requests.FinishTestItemRequest { EndTime = scenarioStartTime.AddMilliseconds(scenario.ExecutionTime), Status = _statusMap[scenario.ExecutionStatus] }); } var specFinishStatus = specResult.Failed ? Client.Models.Status.Failed : Client.Models.Status.Passed; specReporter.Finish(new Client.Requests.FinishTestItemRequest { Status = specFinishStatus, EndTime = specStartTime.AddMilliseconds(specResult.ExecutionTime) }); } launchReporter.Finish(new Client.Requests.FinishLaunchRequest { EndTime = DateTime.UtcNow }); } if (message.MessageType == Message.Types.MessageType.KillProcessRequest) { Console.Write("Finishing to send results to Report Portal... "); var sw = Stopwatch.StartNew(); launchReporter.Sync(); Console.WriteLine($"Elapsed: {sw.Elapsed}"); return; } } } }