question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ScenarioBuilder extendability

See original GitHub issue

We are implementing extensions on the fluent scenario builder to be able to run scenarios according to configuration data while running the tests. For example run specific tests only on specific environments (QA / Prod).

We have implement the feature by creating an extension method on the runner methods.

Examples

Extended Extension

public static async Task RunScenarioActionOnEnvironmentAsync<TContext>(
        this IBddRunner<TContext> runner,
        string env,
        params Expression<Action<TContext>>[] steps
)
{
    if (env.Equals(ConfigEnv))
    {
        await runner.RunScenarioActionsAsync(steps);
    }
    else
    {
        StepExecution.Current.IgnoreScenario(_message);
    }
}

Fluent Extension

public static async Task RunOnEnvAsync<TContext>(
    this IScenarioBuilder<TContext> builder,
    string env
)
{
    if (env.Equals(ConfigEnv))
    {
        await builder.RunAsync();
    }
    else
    {
        StepExecution.Current.IgnoreScenario(Message);
    }
}

Ideally, instead we want to add an extension method to be able to filter test scenarios which would be much cleaner + we can add more filters. But to implement such a feature we require to have a Dictionary in the ScenarioBuilder class to be able to add specific filters.

Usage

// extensions
public static IScenarioBuilder<TContext> FilterEnv<TContext>(this IScenarioBuilder<TContext> builder, string env)
{
    builder.Items.Add("ENV", env);
    return builder;
}

public static async Task RunWithFilters<TContext>(this IScenarioBuilder<TContext> builder)
{
    string env = (string)builder.Items["ENV"];
    if (env.Equals(ConfigEnv))
    {
        await builder.RunAsync();
    }
    else
    {
        StepExecution.Current.IgnoreScenario(Message);
    }
}
// usage in feature specs
public async Task Browsing_invoices()
{

    await Runner
        .NewScenario()
        .FilterEnv("QA") // our extension method
        .AddAsyncSteps(
            _ => Given_invoice("Invoice-1"),
            _ => Given_invoice("Invoice-2"))
        .AddSteps(
            When_I_request_all_historical_invoices)
        .AddSteps(
            _ => Then_I_should_see_invoices("Invoice-1", "Invoice-2"))
        .RunWithFilter(); // our extension method
}

If you agree I am happy to create a PR.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
Suremakercommented, Jan 23, 2018

Hey, I did not have gitter before but created room there (https://gitter.im/LightBDD/LightBDD) and sent you an invite. Will add it to repo readme as well as I think it may be easier to ask questions there than via github issues

1reaction
Suremakercommented, Jan 23, 2018

Cool, it’s good to hear it works for you.

In fact both mentioned attributes works on step and scenario methods as they implement both decorator interfaces.

See how the IgnoreScenarioAttribute implements IStepDecoratorAttribute here: https://github.com/LightBDD/LightBDD/blob/master/src/LightBDD.NUnit3/IgnoreScenarioAttribute.cs

… while example usage is described here: https://github.com/LightBDD/LightBDD/wiki/What-Is-New#2-declarative-way-for-ignoring-scenarios-and-steps

Read more comments on GitHub >

github_iconTop Results From Across the Web

Scala dynamic scenario - gatling
I had to modify scenario to ScenarioBuilder with import statement io.gatling.core.structure.{PopulationBuilder, ScenarioBuilder} added as ...
Read more >
Load testing with Gatling.io. Performance testing - Pragmatists
Extending Simulation class will give us access to tools needed to set up and execute tests. It will allow us to define actions, ......
Read more >
Run multiple scenarios based on a condition
I have a project running multiple scenarios and it is working fine, now the requirement extended to run only the passed scenarios via ......
Read more >
scenario-builder/yarn.lock at master
Internal builder for scenario module's javascript included in CRM Scenarios Module - scenario-builder/yarn.lock at master · remp2020/scenario-builder.
Read more >
Customer Due Diligence Features
Ability to create, govern and update customer monitoring scenarios with a visual, built-in scenario builder. Extendable end user Interface with pre-built ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found