private TestReporter AddTestReporter(IReadonlyNode <TestReporter> parent, Path path, Location test, string tags) { TestItemType type = TestItemType.Suite; if (test.Index == path.Length - 2) { type = TestItemType.Test; } else if (test.Index == path.Length - 1) { type = TestItemType.Step; } var startTestItemRequest = new StartTestItemRequest() { Name = test.Name, StartTime = DateTime.UtcNow, Type = type, Tags = SplitOnTags(tags) }; var suite = parent.Value != null ? parent.Value.StartNewTestNode(startTestItemRequest) : _launchReporter.StartNewTestNode(startTestItemRequest); return(suite); }
public void Test1() { var service = new Service(new Uri("https://rp.epam.com/api/v1/"), "default_project", "7853c7a9-7f27-43ea-835a-cab01355fd17"); var launchReporter = new LaunchReporter(service); launchReporter.Start(new Client.Requests.StartLaunchRequest { Name = "ReportPortal.Shared", StartTime = DateTime.UtcNow, Mode = Client.Models.LaunchMode.Debug }); var suiteReporter = launchReporter.StartNewTestNode(new Client.Requests.StartTestItemRequest { Name = "Suite", StartTime = DateTime.UtcNow, Type = Client.Models.TestItemType.Suite }); var testReporter = suiteReporter.StartNewTestNode(new Client.Requests.StartTestItemRequest { Name = "Test", StartTime = DateTime.UtcNow, Type = Client.Models.TestItemType.Step }); for (int i = 0; i < 10; i++) { System.Threading.Thread.Sleep(1); testReporter.Log(new Client.Requests.AddLogItemRequest { Text = $"Log message #{i}", Time = DateTime.UtcNow, Level = Client.Models.LogLevel.Info }); } testReporter.Finish(new Client.Requests.FinishTestItemRequest { EndTime = DateTime.UtcNow, Status = Client.Models.Status.Passed }); suiteReporter.Finish(new Client.Requests.FinishTestItemRequest { EndTime = DateTime.UtcNow, Status = Client.Models.Status.Passed }); launchReporter.Finish(new Client.Requests.FinishLaunchRequest { EndTime = DateTime.UtcNow }); launchReporter.FinishTask.Wait(); }
static void Main(string[] args) { var port = Convert.ToInt32(Environment.GetEnvironmentVariable("plugin_connection_port")); var rpUri = new Uri(ReadEnvVariable("rp_uri")); var rpProject = ReadEnvVariable("rp_project"); var rpUuid = ReadEnvVariable("rp_uuid"); var service = new Service(rpUri, rpProject, rpUuid); var launchReporter = new LaunchReporter(service); 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; launchReporter.Start(new Client.Requests.StartLaunchRequest { Name = suiteExecutionResult.ProjectName, Tags = suiteExecutionResult.Tags.Select(t => t.ToString()).ToList(), StartTime = DateTime.UtcNow }); foreach (var specResult in suiteExecutionResult.SpecResults) { var specReporter = launchReporter.StartNewTestNode(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 = DateTime.UtcNow, Tags = specResult.ProtoSpec.Tags.Select(t => t.ToString()).ToList() }); foreach (var scenarioResult in specResult.ProtoSpec.Items.Where(i => i.ItemType == ProtoItem.Types.ItemType.Scenario)) { var scenarioReporter = specReporter.StartNewTestNode(new Client.Requests.StartTestItemRequest { Type = Client.Models.TestItemType.Step, StartTime = DateTime.UtcNow, Name = scenarioResult.Scenario.ScenarioHeading, Description = string.Join("", scenarioResult.Scenario.ScenarioItems.Where(i => i.ItemType == ProtoItem.Types.ItemType.Comment).Select(c => c.Comment.Text)), Tags = scenarioResult.Scenario.Tags.Select(t => t.ToString()).ToList() }); foreach (var scenarioContext in scenarioResult.Scenario.Contexts) { scenarioReporter.Log(new Client.Requests.AddLogItemRequest { Level = Client.Models.LogLevel.Info, Time = DateTime.UtcNow, Text = scenarioContext.Step.ActualText }); } foreach (var stepResult in scenarioResult.Scenario.ScenarioItems.Where(i => i.ItemType == ProtoItem.Types.ItemType.Step)) { var text = stepResult.Step.ActualText; scenarioReporter.Log(new Client.Requests.AddLogItemRequest { Level = Client.Models.LogLevel.Info, Time = DateTime.UtcNow, Text = text }); } scenarioReporter.Finish(new Client.Requests.FinishTestItemRequest { EndTime = DateTime.UtcNow, Status = _statusMap[scenarioResult.Scenario.ExecutionStatus] }); } specReporter.Finish(new Client.Requests.FinishTestItemRequest { Status = Client.Models.Status.Passed, EndTime = DateTime.UtcNow }); } 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.FinishTask?.Wait(); Console.WriteLine($"Elapsed: {sw.Elapsed}"); return; } } } }