public void AllureNUnit_1() { var name = "PassingTest1"; var labels = new List <Label> { Label.Thread() }; cycle.StartTestCase(new TestResult { uuid = name, name = name, labels = labels }); cycle.StopTestCase(x => x.status = Status.passed); cycle.WriteTestCase(name); }
public static bool stopTest(string testId, Status status, string message, string trace) { StatusDetails std = new StatusDetails { flaky = false, known = true, message = message, trace = trace, muted = false }; instance = instance.UpdateTestCase(testId, x => x.status = status); instance = instance.UpdateTestCase(testId, x => x.statusDetails = std); instance.StopTestCase(testId) .WriteTestCase(testId); return(true); }
public void TearDown() { _allure.StopTestCase(x => { x.status = TestContext.CurrentContext.Result.Outcome.Status == NUnit.Framework.Interfaces.TestStatus.Passed ? Status.passed : Status.failed; x.descriptionHtml = TestContext.CurrentContext.Result.Message; x.name = TestContext.CurrentContext.Test.Name; x.statusDetails = new StatusDetails { message = TestContext.CurrentContext.Result.Message, trace = TestContext.CurrentContext.Result.StackTrace }; }); _allure.WriteTestCase(TestContext.CurrentContext.Test.ID); }
public virtual void AfterTest(ITest test) { var currentAction = (ITestAction)this; var testActions = GetCurrentActions(test); if (testActions.Last() == currentAction) { Allure.UpdateTestCase(x => x.statusDetails = new StatusDetails { message = TestContext.CurrentContext.Result.Message, trace = TestContext.CurrentContext.Result.StackTrace }); Allure.StopTestCase(x => x.status = GetNunitStatus(TestContext.CurrentContext.Result.Outcome.Status)); Allure.WriteTestCase(test.Id); } }
public override void TearDown() { _allure.UpdateTestCase(test => { var packageName = TestContext.CurrentContext.Test.ClassName; var className = packageName.Substring(packageName.LastIndexOf('.') + 1); test.labels.AddRange(new List <Label> { Label.Suite(TestRunner.FeatureContext?.FeatureInfo.Title.Trim()), Label.Feature(TestRunner.FeatureContext?.FeatureInfo.Title), Label.TestClass(className), Label.Package(packageName) }); if (Driver != null) { test.labels.Add(Label.ParentSuite(BrowserName)); try { test.parameters.Add(new Parameter { name = "Screen", value = string.Concat(Driver.Manage().Window.Size.Width, "x", Driver.Manage().Window.Size.Height) }); } catch (Exception) { // } } else { test.labels.Add(Label.ParentSuite(test.statusDetails.message)); } if (TestRunner.ScenarioContext != null) { var tags = PluginHelper.GetTags(TestRunner.FeatureContext?.FeatureInfo, TestRunner.ScenarioContext?.ScenarioInfo); test.labels.Add(Label.SubSuite(TestRunner.ScenarioContext?.ScenarioInfo.Title)); test.labels.AddRange(tags.Item1); test.links = tags.Item2; } }); if (TestContext.CurrentContext.Result.Outcome.Status != TestStatus.Passed) { if (Driver != null) { try { var screen = ((ITakesScreenshot)Driver).GetScreenshot(); _allure.AddAttachment("ScreenShot", "image/png", screen.AsByteArray); } catch (Exception e) { _allure.UpdateTestCase(test => test.parameters.Add(new Parameter { name = "ScreenShotError", value = e.Message })); } } } else { _allure.UpdateTestCase(x => x.status = Status.passed); } _allure.StopTestCase(TestResultId); _allure.WriteTestCase(TestResultId); _allure.StartAfterFixture(TestContainerId, Guid.NewGuid().ToString(), new FixtureResult()); if (Driver != null) { if (Driver is PaidWebDriver driver) { _allure.WrapInStep(UpdateApi, $"Updating {driver.Name} results through API"); } _allure.WrapInStep(KillWebDriver, $"Killing {BrowserName}"); } _allure.StopFixture(fixture => { fixture.stage = Stage.finished; }); _allure.UpdateTestContainer(TestContainerId, testContainer => testContainer.stop = DateTimeOffset.Now.ToUnixTimeMilliseconds()); _allure.StopTestContainer(TestContainerId); _allure.WriteTestContainer(TestContainerId); }
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)); } }