public static string addTestContainer(testContainer testContainer) { var trc = new TestResultContainer(); if (string.IsNullOrWhiteSpace(testContainer.id)) { testContainer.id = Guid.NewGuid().ToString("N"); } trc.uuid = testContainer.id; if (string.IsNullOrWhiteSpace(testContainer.name)) { testContainer.name = "Container Name " + trc.uuid; } trc.name = testContainer.name; if (!string.IsNullOrWhiteSpace(testContainer.description)) { testContainer.description = "Container Description " + trc.uuid; } trc.description = testContainer.description; if (testContainer.listLinks != null) { if (testContainer.listLinks.Count > 0) { trc.links = new List <Link>(); for (int i = 0; i < testContainer.listLinks.Count; i++) { if (testContainer.listLinks[i].isIssue) { Link.Issue(name: testContainer.listLinks[i].name, url: testContainer.listLinks[i].url); } else { Link.Tms(name: testContainer.listLinks[i].name, url: testContainer.listLinks[i].url); } } } } instance.StartTestContainer(trc); return(trc.uuid); }
public void IntegrationTest() { Parallel.For(0, 2, i => { AllureLifecycle cycle = AllureLifecycle.Instance; var container = DataGenerator.GetTestResultContainer(); var beforeFeature = DataGenerator.GetFixture(Fixture.BeforeFeature); var afterFeature = DataGenerator.GetFixture(Fixture.AfterFeature); var beforeScenario = DataGenerator.GetFixture(Fixture.BeforeScenario); var afterScenario = DataGenerator.GetFixture(Fixture.AfterScenario); var test = DataGenerator.GetTestResult(); var fixtureStep = DataGenerator.GetStep(); var step1 = DataGenerator.GetStep(); var step2 = DataGenerator.GetStep(); var step3 = DataGenerator.GetStep(); var step4 = DataGenerator.GetStep(); var txtAttach = DataGenerator.GetAttachment(".txt"); var txtAttachWithNoExt = DataGenerator.GetAttachment(); cycle .StartTestContainer(container) .StartBeforeFixture(container.uuid, beforeFeature.uuid, beforeFeature.fixture) .StartStep(fixtureStep.uuid, fixtureStep.step) .StopStep(x => x.status = Status.passed) .AddAttachment("text file", "text/xml", txtAttach.path) .AddAttachment(txtAttach.path) .UpdateFixture(beforeFeature.uuid, f => f.status = Status.passed) .StopFixture(beforeFeature.uuid) .StartBeforeFixture(container.uuid, beforeScenario.uuid, beforeScenario.fixture) .UpdateFixture(beforeScenario.uuid, f => f.status = Status.passed) .StopFixture(beforeScenario.uuid) .StartTestCase(container.uuid, test) .StartStep(step1.uuid, step1.step) .StopStep(x => x.status = Status.passed) .StartStep(step2.uuid, step2.step) .AddAttachment("unknown file", "text/xml", txtAttachWithNoExt.content) .StopStep(x => x.status = Status.broken) .StartStep(step3.uuid, step3.step) .StopStep(x => x.status = Status.skipped) .StartStep(step4.uuid, step4.step, DateTimeOffset.Now) .StopStep(step4.uuid, DateTimeOffset.Now) .AddScreenDiff(test.uuid, "expected.png", "actual.png", "diff.png") .StopTestCase(x => { x.status = Status.broken; x.statusDetails = new StatusDetails() { flaky = true, known = true, message = "Oh my!", trace = "That was really bad...", muted = true }; }) .StartAfterFixture(container.uuid, afterScenario.uuid, afterScenario.fixture) .UpdateFixture(afterScenario.uuid, f => f.status = Status.passed) .StopFixture(afterScenario.uuid) .StartAfterFixture(container.uuid, afterFeature.uuid, afterFeature.fixture) .StopFixture(f => f.status = Status.passed) .WriteTestCase(test.uuid) .StopTestContainer(container.uuid) .WriteTestContainer(container.uuid); }); }
public override void FeatureSetup() { _allure.StartTestContainer(new TestResultContainer { uuid = RootContainerId }); }
public override object InvokeBinding(IBinding binding, IContextManager contextManager, object[] arguments, ITestTracer testTracer, out TimeSpan duration) { var hook = binding as HookBinding; // process hook if (hook != null) { var featureContainerId = AllureHelper.GetFeatureContainerId(contextManager.FeatureContext?.FeatureInfo); switch (hook.HookType) { case HookType.BeforeFeature: if (hook.HookOrder == int.MinValue) { // starting point var featureContainer = new TestResultContainer { uuid = AllureHelper.GetFeatureContainerId(contextManager.FeatureContext?.FeatureInfo) }; allure.StartTestContainer(featureContainer); contextManager.FeatureContext.Set(new HashSet <TestResultContainer>()); contextManager.FeatureContext.Set(new HashSet <TestResult>()); return(base.InvokeBinding(binding, contextManager, arguments, testTracer, out duration)); } else { try { this.StartFixture(hook, featureContainerId); var result = base.InvokeBinding(binding, contextManager, arguments, testTracer, out duration); allure.StopFixture(x => x.status = Status.passed); return(result); } catch (Exception ex) { allure.StopFixture(x => x.status = Status.broken); // if BeforeFeature is failed execution is stopped. We need to create, update, stop and write everything here. // create fake scenario container var scenarioContainer = AllureHelper.StartTestContainer(contextManager.FeatureContext, null); // start fake scenario var scenario = AllureHelper.StartTestCase(scenarioContainer.uuid, contextManager.FeatureContext, null); // update, stop and write allure .StopTestCase(x => { x.status = Status.broken; x.statusDetails = AllureHelper.GetStatusDetails(ex); }) .WriteTestCase(scenario.uuid) .StopTestContainer(scenarioContainer.uuid) .WriteTestContainer(scenarioContainer.uuid) .StopTestContainer(featureContainerId) .WriteTestContainer(featureContainerId); throw; } } case HookType.BeforeStep: case HookType.AfterStep: { var scenario = AllureHelper.GetCurrentTestCase(contextManager.ScenarioContext); try { return(base.InvokeBinding(binding, contextManager, arguments, testTracer, out duration)); } catch (Exception ex) { allure .UpdateTestCase(scenario.uuid, x => { x.status = Status.broken; x.statusDetails = AllureHelper.GetStatusDetails(ex); }); throw; } } case HookType.BeforeScenario: case HookType.AfterScenario: if (hook.HookOrder == int.MinValue || hook.HookOrder == int.MaxValue) { return(base.InvokeBinding(binding, contextManager, arguments, testTracer, out duration)); } else { var scenarioContainer = AllureHelper.GetCurrentTestConainer(contextManager.ScenarioContext); try { this.StartFixture(hook, scenarioContainer.uuid); var result = base.InvokeBinding(binding, contextManager, arguments, testTracer, out duration); allure.StopFixture(x => x.status = Status.passed); return(result); } catch (Exception ex) { allure.StopFixture(x => x.status = Status.broken); // get or add new scenario var scenario = AllureHelper.GetCurrentTestCase(contextManager.ScenarioContext) ?? AllureHelper.StartTestCase(scenarioContainer.uuid, contextManager.FeatureContext, contextManager.ScenarioContext); allure.UpdateTestCase(scenario.uuid, x => { x.status = Status.broken; x.statusDetails = AllureHelper.GetStatusDetails(ex); }); throw; } } case HookType.AfterFeature: if (hook.HookOrder == int.MaxValue) // finish point { WriteScenarios(contextManager); allure .StopTestContainer(featureContainerId) .WriteTestContainer(featureContainerId); return(base.InvokeBinding(binding, contextManager, arguments, testTracer, out duration)); } else { try { StartFixture(hook, featureContainerId); var result = base.InvokeBinding(binding, contextManager, arguments, testTracer, out duration); allure.StopFixture(x => x.status = Status.passed); return(result); } catch (Exception ex) { var scenario = contextManager.FeatureContext.Get <HashSet <TestResult> >().Last(); allure .StopFixture(x => x.status = Status.broken) .UpdateTestCase(scenario.uuid, x => { x.status = Status.broken; x.statusDetails = AllureHelper.GetStatusDetails(ex); }); WriteScenarios(contextManager); allure .StopTestContainer(featureContainerId) .WriteTestContainer(featureContainerId); throw; } } case HookType.BeforeScenarioBlock: case HookType.AfterScenarioBlock: case HookType.BeforeTestRun: case HookType.AfterTestRun: default: return(base.InvokeBinding(binding, contextManager, arguments, testTracer, out duration)); } } else { return(base.InvokeBinding(binding, contextManager, arguments, testTracer, out duration)); } }