SpecFlow icon indicating copy to clipboard operation
SpecFlow copied to clipboard

LivingDoc attachment not shown

Open Naweap opened this issue 4 years ago • 6 comments

SpecFlow Version

3.9.7

Which test runner are you using?

SpecFlow+ Runner

Test Runner Version Number

3.9.7

.NET Implementation

.NET Core 3.1

Project Format of the SpecFlow project

Classic project format using packages.config

.feature.cs files are generated using

SpecFlow.Tools.MsBuild.Generation NuGet package

Test Execution Method

Visual Studio Test Explorer

SpecFlow Section in app.config or content of specflow.json

Issue Description

Dear community,

I'm using SpecFlow with Appium for testing an UWP application.

After running a scenario, I take a screenshot of the application and attach it to SpecFlowOutputHelper in order to integrate it to the LivingDoc report.

Next, I generate the report using the CLI and the TestExecution.json file.

Unfortunatly, the LivingDoc report doesn't include the attachment every time.

I've noticed that when I'm running a scenario that call another child scenario, the attachment doesn't appear. Button called 'Show Test Output' is clickable but doesn't show attachment when clicked.

Otherwise, when I'm using regular steps without calling a child scenario from the current one, everything works fine.

Here is the code of 'Hooks.cs' after every scenario execution, takes the screenshot and saves it : ` [AfterScenario] public void AfterScenario(ScenarioContext scenarioContext) { var driver = scenarioContext.Get<WindowsDriver<WindowsElement>>(Global.Driver);

        // Create screenshot filename
        var filename = $"{scenarioContext.ScenarioInfo.Title}_{DateTime.Now:yyyy'-'MM'-'dd'T'HH''mm''ss}.png";

        // Get screenshot
        driver.GetScreenshot().SaveAsFile(filename);

        // Save screenshot
        _specFlowOutputHelper.AddAttachment($"{ConfigHelper.GetConfigValue("screenshotDirectory")}/{filename}");

        // Close the application and delete the session
        if (driver != null)
        {
            driver.Quit();
            driver.Dispose();
            scenarioContext.Remove(Global.Driver);
        }
    }`

Steps to Reproduce

  1. Create a feature file called 'Login.feature' with the following content :

_Feature: Login Login feature

Scenario: Login from the network Given I launched the app When I log in the app Then I'm successfully authenticated_

Create a step file called 'LoginStep.cs' containing the steps above (logic doesn't matter for the issue).

  1. Then create a feature file called 'Home.feature' with the following content :

_Feature: Home Home feature

Scenario: Home page Given I execute the steps of 'Login'.'Login from the network' When I test the home page Then I close the app_

As I said, logic doesn't matter in this issue. When I move 'Home.feature' step into 'Login.feature' scenario everything works fine and the attachment appear correctly.

Link to Repro Project

No response

Naweap avatar Nov 08 '21 07:11 Naweap

What do you mean with I'm running a scenario that call another child scenario?

Are you calling the generated test method from a binding?

SabotageAndi avatar Nov 12 '21 08:11 SabotageAndi

Not directly.

For exemple you got a file called 'login.feature'.

In this file you've the scenarios below :

Scenario: Login: First scenario
Scenario: Login: Second scenario

Then I've something like this for the first scenario :

Scenario: Login: First scenario
Given I execute the steps of 'Second scenario'
...
...

Then for sure in the Second scenario, I'm calling the generated test method from a binding.

But the screenshots aren't attached correctly only when I'm in this case. When I call an existing sub-scenario from another one. Otherwise, it works fine.

I think I also installed the Nuget package SpecFlow.SharedSteps in order to do that.

Naweap avatar Nov 12 '21 09:11 Naweap

Calling a complete scenario from another scenario is perhaps technically possible, but we don't support this. And we don't take this into account when we design new features. The reason is, this fucks up the internal state machine of SpecFlow and LivingDoc can't handle this.

The NuGet package SpecFlow.SharedSteps is not from us. No idea what this is doing.

SabotageAndi avatar Nov 19 '21 10:11 SabotageAndi

@SabotageAndi

Is it possible to add livingdoc attachments (files) in specflow runner?

The documentation(https://docs.specflow.org/projects/specflow/en/latest/outputapi/outputapi.html#addattachment-string-filepath) says it's impossible.

If not, when will you apply?

namilkimfree avatar Nov 29 '21 04:11 namilkimfree

@namilkimfree I assume you are refering this note:

Note: Handling of attachments depends on your runner. MStest and NUnit currently support this feature but xUnit and SpecFlow+ Runner do not.

What we mean is, that the Runner has no attachment functionality and you will not get the attachments in your CI system. You will get the link in LivingDoc to the attachment.

SabotageAndi avatar Dec 02 '21 09:12 SabotageAndi

Hi @SabotageAndi I'm able to generate living Doc report from command prompt, but I don't know how to see the link (in code level I need to do any changes ) in test explorer can you please help me, I have updated my Spec flow+Living Doc

we need to run command always to generate livingdoc.html?

Swaroop065 avatar Nov 22 '22 12:11 Swaroop065