Exemplo n.º 1
0
        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);
        }
        private static void WriteScenarios(IContextManager contextManager)
        {
            foreach (var s in contextManager.FeatureContext.Get <HashSet <TestResult> >())
            {
                allure.WriteTestCase(s.uuid);
            }

            foreach (var c in contextManager.FeatureContext.Get <HashSet <TestResultContainer> >())
            {
                allure
                .StopTestContainer(c.uuid)
                .WriteTestContainer(c.uuid);
            }
        }
Exemplo n.º 3
0
 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);
        }