public static void WrapInStep(this AllureLifecycle allureInstance, Action action, string stepName = "") { var id = Guid.NewGuid().ToString(); var stepResult = new StepResult { name = stepName }; try { allureInstance.StartStep(id, stepResult); action.Invoke(); allureInstance.StopStep(step => stepResult.status = Status.passed); } catch (ArgumentNullException) { Console.WriteLine($" > WARN - You can't use step {stepName} here. Allure hasn't been initialized"); action.Invoke(); } catch (Exception ex) { allureInstance.StopStep(step => { step.stage = Stage.finished; step.status = Status.failed; step.statusDetails = GetStatusDetails(ex); }); throw; } }
public string ParamNameRegex(string config) { File.Copy(config, "allureConfig.json", true); var configuration = new PluginConfiguration(AllureLifecycle.CreateInstance().Configuration); return(configuration.ParamNameRegex?.ToString()); }
/// <summary> /// Wraps method into AllureStep. /// </summary> public static void WrapInStep(this AllureLifecycle lifecycle, Action action, string stepName = "", [CallerMemberName] string callerName = "") { if (string.IsNullOrEmpty(stepName)) { stepName = callerName; } var id = Guid.NewGuid().ToString(); var stepResult = new StepResult { name = stepName }; try { lifecycle.StartStep(id, stepResult); action.Invoke(); lifecycle.StopStep(step => stepResult.status = Status.passed); } catch (Exception e) { lifecycle.StopStep(step => { step.statusDetails = new StatusDetails { message = e.Message, trace = e.StackTrace }; step.status = AllureNUnitHelper.GetNUnitStatus(); }); throw; } }
public void Defaults(string config) { RestoreState(config); var allureCycle = AllureLifecycle.CreateInstance(); Assert.IsType <AllureLifecycle>(allureCycle); }
/// <summary> /// AllureNUnit AddScreenDiff wrapper method. /// </summary> public static void AddScreenDiff(this AllureLifecycle lifecycle, string expected, string actual, string diff) { var storageMain = lifecycle.GetType().GetField("storage", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(lifecycle); var storageInternal = storageMain.GetType().GetField("storage", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(storageMain); var keys = (storageInternal as System.Collections.Concurrent.ConcurrentDictionary <string, object>).Keys.ToList(); AllureLifecycle.Instance.AddScreenDiff(keys.Find(key => key.Contains("-tr-")), expected, actual, diff); }
public Hooks(ScenarioContext scenarioContext) { ScenarioContext = scenarioContext; if (scenarioContext.ContainsKey(ContextKey.WebDriver)) { Driver = scenarioContext.GetContextKey(ContextKey.WebDriver) as IWebDriver; } AllureLifecycle = AllureLifecycle.Instance; }
public void ShouldConfigureTitle() { var json = @"{""allure"":{""title"": ""hello Allure""}}"; configFile = WriteConfig(json); var actualTitle = new AllureLifecycle(configFile).AllureConfiguration.Title; Assert.AreEqual("hello Allure", actualTitle); }
private void AllureHackForScenarioOutlineTests() { ScenarioContext.TryGetValue(out TestResult result); AllureLifecycle.UpdateTestCase(result.uuid, test => { test.name = ScenarioContext.ScenarioInfo.Title; test.historyId = Guid.NewGuid().ToString(); }); }
public void ShouldAccessConfigProperties() { var config = @"{""allure"":{""customKey"": ""customValue""}}"; RestoreState(config); var cycle = AllureLifecycle.CreateInstance(); Assert.Equal("customValue", cycle.Configuration["allure:customKey"]); }
public static string AddTest(testDefinition test) { TestResult tr = new TestResult { labels = new List <Label>() }; if (string.IsNullOrWhiteSpace(test.id)) { test.id = Guid.NewGuid().ToString("N"); } tr.uuid = test.id; tr.name = test.name; tr.description = test.description; if (!string.IsNullOrWhiteSpace(test.epicName)) { tr.labels.Add(Label.Epic(test.epicName)); } if (!string.IsNullOrWhiteSpace(test.featureName)) { tr.labels.Add(Label.Feature(test.featureName)); } if (!string.IsNullOrWhiteSpace(test.storyName)) { tr.labels.Add(Label.Story(test.storyName)); } if (tr.labels.Count > 0) { tr.labels.Add(Label.Thread()); } if (test.listLinks != null) { if (test.listLinks.Count > 0) { tr.links = new List <Link>(); for (int i = 0; i < test.listLinks.Count; i++) { if (test.listLinks[i].isIssue) { tr.links.Add(Link.Issue(test.listLinks[i].name, test.listLinks[i].url)); } else { tr.links.Add(Link.Tms(test.listLinks[i].name, test.listLinks[i].url)); } } } } _instance = _instance.StartTestCase(tr); return(tr.uuid); }
public void ShouldConfigureResultsDirectoryFromJson() { var json = @"{""allure"":{""directory"": ""test""}}"; configFile = WriteConfig(json); var allureCycle = new AllureLifecycle(configFile); Assert.AreEqual(Path.Combine(Environment.CurrentDirectory, "test"), allureCycle.ResultsDirectory); }
public void TearDown() { if (ScenarioContext.TestError != null) { var path = Utils.MakeScreenShot(Driver); AllureLifecycle.AddAttachment(path); } Driver.Quit(); Driver.Dispose(); AllureHackForScenarioOutlineTests(); }
public void ShouldConfigureDefaultValues(string json) { var allureLifecycle = new AllureLifecycle(JObject.Parse(json)); Assert.Multiple(() => { Assert.IsInstanceOf <AllureLifecycle>(allureLifecycle); Assert.IsNotNull(allureLifecycle.JsonConfiguration); Assert.AreEqual(Path.Combine(Environment.CurrentDirectory, AllureConstants.DEFAULT_RESULTS_FOLDER), allureLifecycle.ResultsDirectory); Assert.IsNotNull(allureLifecycle.AllureConfiguration.Links); }); }
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 Defaults(string json) { configFile = WriteConfig(json); var allureCycle = new AllureLifecycle(configFile); Assert.Multiple(() => { Assert.IsInstanceOf <AllureLifecycle>(allureCycle); Assert.IsNotNull(allureCycle.JsonConfiguration); Assert.AreEqual(Path.Combine(Environment.CurrentDirectory, AllureConstants.DEFAULT_RESULTS_FOLDER), allureCycle.ResultsDirectory); Assert.IsNotNull(allureCycle.AllureConfiguration.Links); }); }
public static void TakeScreenshot(this IWebDriver driver, string path) { Directory.CreateDirectory(path); var testName = TestContext.CurrentContext.Test.Name; var correctTestName = string.Join("", testName.Split(Path.GetInvalidFileNameChars())); var fileName = $"{Path.Combine(path, correctTestName)}_{DateTime.Now.ToString("yyyy.MM.dd HH.mm.ss")}.png"; var screenShot = ((ITakesScreenshot)driver).GetScreenshot(); screenShot.SaveAsFile(fileName, ScreenshotImageFormat.Png); AllureLifecycle cycle = AllureLifecycle.Instance; cycle.AddAttachment(fileName, $"{correctTestName}"); }
internal (Status StepStatus, Exception ThrowedEx, bool NeedRethrow) ProceedException(Exception e, Status defaultStepStatus = Status.failed) { var throwEx = true; var stepStatus = defaultStepStatus; Exception throwedEx; if (e is TargetInvocationException) { throwedEx = AllureLifecycle.GetInnerExceptions(e) .First(q => q.GetType() != typeof(TargetInvocationException)); } else { throwedEx = e; } if (throwedEx is InconclusiveException) { stepStatus = Status.skipped; } else if (throwedEx is SuccessException) { throwEx = false; // no throw ex, because assert.pass } var list = TestContext.CurrentContext.Test.Properties.Get(AllureConstants.TestAsserts) as List <Exception>; list?.Add(throwedEx); if (!throwedEx.Data.Contains(Rethrow)) { throwedEx.Data.Add(Rethrow, true); AllureLifecycle.Instance.MakeStepWithExMessage(_assertsInTestBeforeStep.Count, _stepText, throwedEx, defaultStepStatus); AllureLifecycle.CurrentTestActionsInException?.ForEach(action => action.Invoke()); AllureLifecycle.GlobalActionsInException?.ForEach(action => action.Invoke()); } return(stepStatus, throwedEx, throwEx); }
private static void FailIgnoredTests(Dictionary <ITest, string> dict, ITest suite) { lock (Locker) { foreach (var pair in dict) { pair.Key.Properties.Set(AllureConstants.TestIgnoreReason, $"Test was ignored by reason: {pair.Value}"); var testResult = new TestContext.ResultAdapter(new TestCaseResult(new TestMethod(pair.Key.Method))); AddInfoToIgnoredTest(ref testResult); pair.Key.Properties.Set(AllureConstants.TestResult, testResult); AllureLifecycle.Instance.Storage.ClearStepContext(); AllureLifecycle.Instance.Storage.CurrentThreadStepContext.AddLast(pair.Key.Properties .Get(AllureConstants.TestUuid).ToString()); AllureLifecycle.Instance.StartStepAndStopIt(null, $"Test was ignored by reason: {pair.Value}", Status.skipped); AllureLifecycle.Instance.UpdateTestContainer( pair.Key.Properties.Get(AllureConstants.TestContainerUuid).ToString(), x => x.start = AllureLifecycle.ToUnixTimestamp()); AllureLifecycle.Instance.UpdateTestCase(pair.Key.Properties .Get(AllureConstants.TestUuid).ToString(), x => { x.start = AllureLifecycle.ToUnixTimestamp(); x.labels.RemoveAll(q => q.name == "thread"); x.labels.Add(Label.Thread()); var subSuites = x.labels.Where(lbl => lbl.name.ToLower().Equals("subsuite")).ToList(); subSuites.ForEach(lbl => x.labels.Remove(lbl)); x.labels.Add(Label.SubSuite("Ignored tests/test-cases")); }); Thread.Sleep(5); StopAllureLogging(testResult, pair.Key.Properties .Get(AllureConstants.TestUuid).ToString(), pair.Key.Properties .Get(AllureConstants.TestContainerUuid).ToString(), suite, true, pair.Value); } } }
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); }); }
private bool VerifyRunner(string stepName, Action action, Status stepStatusIfFailed, params object[] stepParams) { var result = AllureLifecycle.StepRunner <bool>(stepName, action, false, stepStatusIfFailed, stepParams); return(result); }
public Hooks(ScenarioContext scenarioContext) { _scenarioContext = scenarioContext; _allureLifecycle = AllureLifecycle.Instance; }
public void SetDir() { Environment.CurrentDirectory = Path.GetDirectoryName(this.GetType().Assembly.Location); cycle = AllureLifecycle.Instance; }
public HooksSteps(IObjectContainer objectContainer, ScenarioContext scenarioContext) { _objectContainer = objectContainer; _scenarioContext = scenarioContext; _allureLifecycle = AllureLifecycle.Instance; }
public static void createInstance() { instance = AllureLifecycle.Instance; }