Skip to content

AllureStep Attribute

Alexandr D edited this page Jan 28, 2020 · 18 revisions

[AllureStep] Attribute - forget about wrapping test methods with RunStep

Available since 3.0 version.


IMPORTANT
  1. In the projects with targeting .NET Core framework, [AllureStep] support added since 3.1.0-beta1 version.

Steps discovering will be performed in all assemblies (exclude some commons assemblies) in the output directory.

  1. If you use your own package (for example, core of all tests projects) and in tests projects only references your own package, then you don't directly install the package with the allure in the test project. For this reason you need to change the import of the allure package in the your own package after installing as follows:
<PackageReference Include="Noksa.NUnit.Allure" Version="...some version here...">
    <PrivateAssets>contentfiles;analyzers</PrivateAssets>
</PackageReference>

So, if you install this package directly in test project, you dont need to do it.


HOW TO USE

Just apply the attribute to any method, that should be a report step. If you want the parameter values of the method to be used in the text of the step, use the parameter names.

&parameter& - parameter name as in the method.

You can also call a method, property or field (private/public/static) on the passed parameter, if parameter has it.

Example 1:

[AllureStep("Test &myClass.GetString()& &myClass.Int& &myClass._fieldName&")]
private void Test(MegaClass myClass)
{
    // some code
}

public class MegaClass
{
    public string GetString()
    {
        return "Mega";
    }

    private double _fieldName = 4005;
    public static int Int => 10;
}


Step text will be: Test Mega 10 4005

Example 2:

[AllureStep("Try login to office with bad credentials (&login&, &password&)")]
public LoginPage TryLogin(string login, string password)
{
    // some code here        
}

In the report:


Disable discovering steps

If for any reason you no longer want to discovering steps, you can add an empty file called StepInject.disable to the output directory (or add it to project and set property Copy to output directory -> Always).


All other actions in the step (for example, errors, etc.) remain the same, since you configured it using the tuning methods.