Skip to content

Tuning methods

Alexandr D edited this page Oct 8, 2018 · 8 revisions

New tuning methods

  • AllureLifecycle.Instance.SetGlobalActionInException (Action action)
  • AllureLifecycle.Instance.SetCurrentTestActionInException (Action action)

You can specify which actions you need to additionally perform if an error occurred in the RunStep method or in the checks in the Verify class.

AllureLifecycle.Instance.SetGlobalActionInException (Action action) is set once globally for all tests and all fixtures.
Be careful, if static fields without threadstatic will be used in this method, there may be unexpected behavior with parallel launches.
In this method, it is recommended to use properties that each time receive a value when referring to them.

AllureLifecycle.Instance.SetCurrentTestActionInException (Action action) need to be set for each test.
After passing the test, this action will be deleted.

You can add as many additional actions as you like by simply calling these methods again.

For example, you can add a screenshot to attach to the report:

[Setup]
public void TestSetup()
{
    AllureLifecycle.Instance.SetCurrentTestActionInException(() =>
        {
            DriverManager.MakeScreenshotAtStep ();
        });
}

Or, for example, you want to add two current test actions, but adding them will be posted in different methods:

[Setup]
public void TestSetup()
{
    AddActionWithStepName("Warning1");
    AddActionWithStepName("Warning2");
}

private void AddActionWithStepName(string stepName)
{
    AllureLifecycle.Instance.SetCurrentTestActionInException(() =>
        {
            AllureLifecycle.Instance.Verify.Warn(stepname);
        });
}

Both actions will be executed if there is an error occured. Accordingly, you can add as many actions as you like from different methods or in same.

Example of Global action:

[OneTimeSetUp]
public void GlobalFixtureSetup()
{
    AllureLifecycle.Instance.SetGlobalActionInException(() =>
        {
            AllureLifecycle.Instance.RunStep("This is just example global step in ex", () => {});
        });
}