Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional info in feature, scenario and steps #191

Closed
tuscias opened this issue Aug 16, 2019 · 5 comments
Closed

Additional info in feature, scenario and steps #191

tuscias opened this issue Aug 16, 2019 · 5 comments
Labels
enhancement An enhancement of the feature or new feature
Milestone

Comments

@tuscias
Copy link

tuscias commented Aug 16, 2019

Description

Hi,
i'm implementing my own scenario decorator and noticed that scenario object doesn't have info about his parent, i.e feature. This information is needed to create Allure reports, where i have to specify a feature id for each scenario so they would link correctly:

public class ScenarioAllureDecorator : IScenarioDecorator
{
private static readonly AllureLifecycle allure = AllureLifecycle.Instance;

    public async Task ExecuteAsync(IScenario scenario, Func<Task> scenarioInvocation)
    {

        var scenarioResult = new TestResult
        {
            uuid = Guid.NewGuid().ToString(),
            name = scenario.Info.Name.ToString(),
            fullName = "FULL NAME",
            status = Status.passed,
            labels = new List<Label>
            {
                Label.Thread(),
                Label.Host(),
                Label.Feature("Dummy"), // <---- HERE: how to get feature name
                Label.Story(scenario.Info.Name.ToString()),
            }
        };
        allure.StartTestCase(scenarioResult);
        try
        {
            await scenarioInvocation();
        }
        catch (Exception ex)
        {
            allure.StopTestCase(scenarioResult.uuid);
            allure.WriteTestCase(scenarioResult.uuid);
            throw ex;
        }

    }
}

Am i missing something? Is this could approached a bit differently?

@Suremaker
Copy link
Collaborator

Hello @tuscias ,

At this moment the child items do not have the ability to track their parent (scenario result/info cannot retrieve the feature result/info). I will make a feature for obtaining it.

If you just want to generate the report after all tests are done, you can achieve it by making own report writer. Here is a wiki page on generating reports.

What you could do is to make own report writer:

class MyEmailingReporter : IReportWriter
{
    public void Save(params IFeatureResult[] results)
    {
        foreach (var featureResult in results)
        {
            // report feature with all it's scenarios and steps
        }
    }
}

The IFeatureResult contains the feature details and its scenarios with scenario info as well as execution results, timings etc.

...then register your writer in LightBDD:

protected override void OnConfigure(LightBddConfiguration configuration)
{
    configuration
        .ReportWritersConfiguration()
        .Add(new AllureReporter());
}

Please note that the report will be generated after all tests are done, so you won't be able to implement any execution notifications as the tests are running this way...


If you are interested in the immediate notification of the test progress, I would say the valid method would be to implement own progress notifier and update report as the tests are executing:

public class AllureProgressNotifier : IScenarioProgressNotifier, IFeatureProgressNotifier
{
    // code updating reports as tests progresses
}

then the registration could be done like that:

var allureNotifier = new AllureProgressNotifier();
configuration.Get<FeatureProgressNotifierConfiguration>()
	.AppendNotifiers(allureNotifier);

configuration.Get<ScenarioProgressNotifierConfiguration>()
	.AppendNotifierProviders(() => allureNotifier);

but with this method, you will get to the same problem as with the decorator where void NotifyScenarioFinished(IScenarioResult scenario) won't have access to the feature, which would mean that you could only retrieve all the data in void NotifyFeatureFinished(IFeatureResult feature).


As mentioned at the beginning of the response, I will have to implement the parent tracking for obtaining incremental/interactive report generation (please let me know if that is your case).

If you just want to make a report at the end, I would suggest going with option 1 as it's the simplest one.

I hope it helps,
Cheers.

@Suremaker Suremaker added the enhancement An enhancement of the feature or new feature label Aug 17, 2019
Suremaker added a commit that referenced this issue Aug 18, 2019
Updated IFeatureInfo, IScenarioInfo, IStepInfo to extend IMetadataInfo
Updated IScenarioInfo, IStepInfo with Parent property
Updated XmlReportFormatter to report RuntimeIds and updated XmlReportFormatterSchema
@Suremaker
Copy link
Collaborator

Hey @tuscias ,

Please take a look at PR #192
The IScenarioInfo and IStepInfo has been updated with Parent property that refers to parent metadata.
Moreover the IFeatureInfo, IScenarioInfo and IStepInfo got RuntimeId that is an unique runtime identifier of the metadata.

Please let me know if the change is sufficient for you to continue with your integration. I have a plan to merge and release it on Monday.

Please also be aware that on Thursday I am going on holiday, which means I won't be able making any changes till the beginning of September.

@tuscias
Copy link
Author

tuscias commented Aug 19, 2019

Yes, that is exactly how I wanted it to work!
Thanks for super fast PR!

@Suremaker
Copy link
Collaborator

Ok, I'll prepare the release tonight

Suremaker added a commit that referenced this issue Aug 19, 2019
#191 Additional info in feature, scenario and steps
Introduced IMetadataInfo with Name and RuntimeId
Updated IFeatureInfo, IScenarioInfo, IStepInfo to extend IMetadataInfo
Updated IScenarioInfo, IStepInfo with Parent property
Updated XmlReportFormatter to report RuntimeIds and updated XmlReportFormatterSchema
@Suremaker Suremaker mentioned this issue Aug 19, 2019
5 tasks
@Suremaker
Copy link
Collaborator

Released with LightBDD 3.1.0

@Suremaker Suremaker added this to the 3.1.0 milestone Aug 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement of the feature or new feature
Projects
None yet
Development

No branches or pull requests

2 participants