Skip to content

Commit

Permalink
Allure-specflow explicit net462 removal + refactoring
Browse files Browse the repository at this point in the history
  - Remove net462 target from allure-specflow (net462 already
    implements netstandard2.0).
  - Fix allure-specflow README (version references, examples).
  - Increase SpecFlow.NUnit and SpecFlow.Tools.MsBuild.Generation
    to 3.9.52 (max version that doesn't break SpecFlow.SharedSteps).
  - Tiny refactoring of AllureBindingInvoker.cs
  • Loading branch information
delatrie committed Oct 10, 2023
1 parent 9abc94d commit da34417
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 40 deletions.
7 changes: 5 additions & 2 deletions Allure.Features/Allure.Features.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
<PackageReference Include="SpecFlow" Version="3.9.74" />
<PackageReference Include="SpecFlow.SharedSteps" Version="3.0.7" />
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.9.8" />
<PackageReference Include="SpecFlow.NUnit" Version="3.9.8" />

<!-- SpecFlow.SharedSteps doesn't work with SpecFlow.Tools.MsBuild.Generation v3.9.58+ -->
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.9.52" />

<PackageReference Include="SpecFlow.NUnit" Version="3.9.52" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Allure.Net.Commons\Allure.Net.Commons.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion Allure.SpecFlowPlugin/Allure.SpecFlowPlugin.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net462;netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<IsPackable>true</IsPackable>
<Nullable>enable</Nullable>
<PackageId>Allure.SpecFlow</PackageId>
Expand Down
21 changes: 18 additions & 3 deletions Allure.SpecFlowPlugin/AllureBindingInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,28 @@ out duration
ITestTracer testTracer,
HookBinding hook
) =>
IsAllureHook(hook) ? this.InvokeAllureBinding(
IsAllureHook(hook) ? this.InvokeAllureHookBinding(
binding,
contextManager,
arguments,
testTracer,
hook
) : hook.HookType switch
) : this.MakeFixtureFromFeatureOrScenarioHook(
binding,
contextManager,
arguments,
testTracer,
hook
);

(object, TimeSpan) MakeFixtureFromFeatureOrScenarioHook(
IBinding binding,
IContextManager contextManager,
object[] arguments,
ITestTracer testTracer,
HookBinding hook
) =>
hook.HookType switch
{
HookType.BeforeFeature =>
this.MakeFixtureFromBeforeFeatureHook(
Expand Down Expand Up @@ -300,7 +315,7 @@ HookBinding hook
return result;
}

(object, TimeSpan) InvokeAllureBinding(
(object, TimeSpan) InvokeAllureHookBinding(
IBinding binding,
IContextManager contextManager,
object[] arguments,
Expand Down
137 changes: 103 additions & 34 deletions Allure.SpecFlowPlugin/README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,74 @@
## SpecFlow Adapter [![](http://img.shields.io/nuget/vpre/Allure.SpecFlow.svg?style=flat)](https://www.nuget.org/packages/Allure.SpecFlow)
Currently supports [SpecFlow](http://specflow.org/) v2.1 - 3.1.*

See [Allure report](https://allure-secondary.z23.web.core.windows.net/) generated from https://github.com/allure-framework/allure-csharp/tree/main/Allure.Features
Currently supports [SpecFlow](http://specflow.org/) v2.1 - 3.9.*

See [Allure report](https://allure-secondary.z23.web.core.windows.net/)
generated from https://github.com/allure-framework/allure-csharp/tree/main/Allure.Features

Please use corresponding NuGet package version.

### Installation

Install [Allure.SpecFlow](https://www.nuget.org/packages/Allure.SpecFlow) nuget package according to your Specflow version.
Install [Allure.SpecFlow](https://www.nuget.org/packages/Allure.SpecFlow)
nuget package according to your Specflow version.

### Configuration

For Specflow 3 please add or update the following section in your specflow.json:

```
"stepAssemblies": [
{ "assembly": "Allure.SpecFlowPlugin" }
]
```
The plugin uses Allure.Commons json configuration extended with custom sections.
### Custom host name
In case if you want to customize host name which is displayed in Allure Timeline section, please configure `allure.title` property in json configuraion file.

The plugin uses allureConfig.json extended with custom sections that are
described below.

#### Custom host name

In case if you want to customize host name which is displayed in Allure Timeline
section, please configure `allure.title` property in json configuraion file.

```json
{
"allure": {
"title": "My title"
}
}
```

#### If you use NUnit
Default value for allure.directory in allureConfig.json is "allure-results", default working directory in NUnit 3.* is the working directory of console runner. If you don't want to place allure results into NUnit default working folder please either set absolute path in allure.config or set working directory for NUnit in your test setup, e.g.:

The default value for allure.directory in allureConfig.json is "allure-results".
The default working directory in NUnit 3.* depends on what runner you use.

If you don't want to place allure results into NUnit default working folder
please either set absolute path in allure.config or set working directory for
NUnit in your test setup, e.g.:

``` csharp
[OneTimeSetUp]
public void Init()
{
Environment.CurrentDirectory = Path.GetDirectoryName(GetType().Assembly.Location);
}
```

### Usage
Just run your SpecFlow scenarios and find `allure-results` folder ready to generate Allure report.

Just run your SpecFlow scenarios and find the `allure-results` folder ready to
generate Allure report.

### Features

#### Grouping
You can structure your scenarios in 3 Allure hierarchies using feature and scenario tags.
Please read [report structure](https://docs.qameta.io/allure/latest/#_report_structure) Allure documentation section for additional details. Hierarchies consist of the following levels:

You can structure your scenarios in 3 Allure hierarchies using feature and
scenario tags.
Please read [report structure](https://docs.qameta.io/allure/latest/#_report_structure)
Allure documentation section for additional details. Hierarchies consist of
the following levels:

**Suites**
* Parent Suite
Expand All @@ -49,16 +85,22 @@ Please read [report structure](https://docs.qameta.io/allure/latest/#_report_str
* * Class
* * * Method

The plugin uses `allure:grouping` configuration section to parse tags with the regular expression. If the expression contains the group, it will be used as hierarchy level name otherwise entire match will be used. E.g:
The plugin uses `allure:grouping` configuration section to parse tags with the
regular expression. If the expression contains the group, it will be used as
hierarchy level name otherwise entire match will be used. E.g:

`^mytag.*` : any tags starting with `@mytag` will be used for grouping.

`^type:(ui|api)` : `@ui` or `@api` tags from regex pattern will be used for grouping.
`^type:(ui|api)` : `@ui` or `@api` tags from regex pattern will be used for
grouping.

Check this [config example](https://github.com/allure-framework/allure-csharp/blob/main/Tests.SpecRun/allureConfig.json) as a starting point.
Check this [config example](https://github.com/allure-framework/allure-csharp/blob/main/Tests.SpecRun/allureConfig.json)
as a starting point.

#### Links
You can add links to your scenarios using tags. Tag and link patterns can be configured in `allureConfig.json`
You can add links to your scenarios using tags. Tag and link patterns can be
configured in `allureConfig.json`

``` json
{
"allure": {
Expand All @@ -76,60 +118,85 @@ You can add links to your scenarios using tags. Tag and link patterns can be con
}
}
```

The following scenario

``` cucumber
@123456 @tms:42 @link:http://example.org
Scenario: I do like click on links in Allure report
```

will have three links in Allure report:
[123456](https://myissuetracker.org/123456), [42](https://mytestmanagementsystem.org?test=tms-42) and http://example.org.
[123456](https://myissuetracker.org/123456),
[42](https://mytestmanagementsystem.org?test=tms-42) and http://example.org.

Links generated dynamically during the tests can be added in code via
AllureLifecycle. The next example adds the [Example link](http://example.com)
link at runtime:

In case there are links, which are generated during tests, then they can be added in code via AllureLifecycle:
``` c#
AllureLifecycle.UpdateTestCase(testResult.uuid, tc =>
{
tc.links.Add(new Link()
{
name = "Example link",
url = "http://example.com"
});
});
AllureLifecycle.Instance.UpdateTestCase(tc =>
{
tc.links.Add(new Link()
{
name = "Example link",
url = "http://example.com"
});
});
```
This will show for scenario link with Text: Example link; and url: "http://example.com".

#### Severity
You can add Severity for your scenarios using tags. It can be configured in `allureConfig.json`
You can add Severity for your scenarios using tags. It can be configured in
`allureConfig.json`:

``` json
"labels": {
"severity": "^(normal|blocker|critical|minor|trivial)"
},
```

The following scenario

``` cucumber
@critical
Scenario: ....
```
will set current scenario severity in Allure report as Blocker

sets the current scenario's severity in Allure report as Blocker.

#### Label
You can add Label for your scenarios using tags. It can be configured in `allureConfig.json`

You can add allure labels for your scenarios using tags. It can be configured
in `allureConfig.json`:

``` json
"labels": {
"label": "^label:([\\w]+):(.+)"
},
```

The following scenario

``` cucumber
@label:layer:e2e: @label:as_id:123
@label:layer:e2e: @label:allure_id:123
Scenario: ....
```
will set current scenario Layer as e2e and Id as 123 in Allure report

sets the current scenario's layer as e2e and Id as 123 in Allure report

#### Tables conversion
Table arguments in SpecFlow steps can be converted either to step csv-attacments or step parameters in the Allure report. The conversion is configurable in `specflow:stepArguments` config section.
With `specflow:stepArguments:convertToParameters` set to `true` the following table arguments will be represented as parameters:

Table arguments in SpecFlow steps can be converted either to step
csv-attacments or step parameters in the Allure report. The conversion is
configurable in `specflow:stepArguments` config section.

With `specflow:stepArguments:convertToParameters` set to `true` the following
table arguments will be represented as parameters:

* one row tables
* two column tables with the headers matching both `specflow:stepArguments:paramNameRegex` and `specflow:stepArguments:paramValueRegex` regular expressions.
* two column tables with the headers matching both
`specflow:stepArguments:paramNameRegex` and
`specflow:stepArguments:paramValueRegex` regular expressions.

<table>
<th>SpecFlow</th>
Expand All @@ -149,9 +216,11 @@ With `specflow:stepArguments:convertToParameters` set to `true` the following ta
</table>

#### Attachments

You can add attachments to an Allure report from your step bindings:

```csharp
using Allure.Commons;
using Allure.Net.Commons;
...
AllureLifecycle.Instance.AddAttachment(path, "Attachment Title");
// or
Expand Down

0 comments on commit da34417

Please sign in to comment.