I'm submitting a:
What is the current behavior?
when we use AddAttachment(filePath) method in [AfterStep] specflow Hook then attachments aren't shown under each step. All attachments are added after all feature steps.
![Untitled](https://user-images.githubusercontent.com/24543037/66196976-71fdf700-e667-11e9-9a2c-53b6faeb3453.png)
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem
Create simple Specflow project where screen can be made:
1) Add feature file:
@regression
Feature: Sample test
In order to verify mobile app
As logged in user
I want to see correct behavior
Scenario: Sample test
Given I click on "Sample button"
When I Swipe Left to "sample element" element
Then I should see "sample name" is "sample value" for card
[StepDefinition(@"I click on ""(.*)""")]
public void GivenIClickOnElement(string elementName)
{
}
[StepDefinition(@"I Swipe Left to ""(.*)"" element")]
public void SwipeLeft(string elementName)
{
}
[Then(@"I should see ""(.*)"" is ""(.*)"" for card)]
public void ThenIShouldSeeIsForCardWithLastDigits(string elementName, string expectedValue, string cardDigits)
{
}
2)
Add [AfterStep] hook
[Binding]
public class BaseHook {
private readonly ScenarioContext _scenarioContext;
public BaseHook(ScenarioContext scenarioContext)
{
_scenarioContext = scenarioContext;
}
[BeforeTestRun]
public static void RegisterServices()
{
//there run browser, or mobile app
}
[AfterStep]
public void TakeScreenShot()
{
var screenShotFilePath = ScreenShotHelper.SaveScreenShot(_scenarioContext);
AllureLifecycle.Instance.AddAttachment(screenShotFilePath, _scenarioContext.StepContext.StepInfo.Text);
}
}
What is the expected behavior?
Attachments are shown under each step in case of using [AfterStep] specflow Hook Attribute
What is the motivation / use case for changing the behavior?
It's more convenient to see screens under each step. Because if we have 20 steps for example it will be a bit messy
Please tell us about your environment:
NUnit.Allure Version 1.0.6
Allure.Commons Version 2.4.2.4
Specflow.Allure Version 2.4.2.4
Specflow Version 2.4.1
SpecFlow.NUnit Version 2.4.1
allure serve allure-results
Other information
In .json result I see:
"steps": [
{
"name": "Given I click on "Sample Element"",
"status": "passed",
"statusDetails": {
"known": false,
"muted": false,
"flaky": false
},
"stage": "finished",
"steps": [],
"attachments": [],
"parameters": [],
"start": 1570178164235,
"stop": 1570178164284
},
{
"name": "When I Swipe Left to "Sample" element",
"status": "passed",
"statusDetails": {
"known": false,
"muted": false,
"flaky": false
},
"stage": "finished",
"steps": [],
"attachments": [],
"parameters": [],
"start": 1570178164870,
"stop": 1570178164871
},
{
"name": "Then I should see "Sample Name" is "Samle" for card "",
"status": "passed",
"statusDetails": {
"known": false,
"muted": false,
"flaky": false
},
"stage": "finished",
"steps": [],
"attachments": [],
"parameters": [],
"start": 1570178165161,
"stop": 1570178165162
}
],
"attachments": [
{
"name": "I click on "Sample element"",
"source": "7b8d735728114f0c87ea75e8324933de-attachment.png",
"type": "image/png"
},
{
"name": "I Swipe Left to "Sample" element",
"source": "642e3d30d3944fce9b9cf10b2622d1f6-attachment.png",
"type": "image/png"
},
{
"name": "I should see "Sample name" is "Sample" for card"",
"source": "e7e4d3a8c6fc4e76900a05329084fb73-attachment.png",
"type": "image/png"
},
],
"parameters": [],
"start": 1570178164227,
"stop": 1570178165426
}
NOTE
If we add attachment in each step definition everything works fine.
[StepDefinition]
public void AddAttachment() {
var fileNameBase = $"{TestContext.CurrentContext.WorkerId}{DateTime.Now:yyyyMMdd_HHmmss}";
var artifactDirectory = Path.Combine(EnvironmentManager.AssemblyDirectoryPath, "Results");
var fileName = Path.Combine(artifactDirectory, fileNameBase + "_log.txt");
using (File.Create(fileName)) { }
AllureLifecycle.Instance.AddAttachment(fileName);
}