How to update BDD feature file scenario result (Pass/Fail) in the excel sheet based on any tags?

97 Views Asked by At

C# Specflow Playwright - My lead want me to update the test case result in the excel sheet after the feature file is executed. So in her excel sheet, she has given an unique tag (tag: test name) to each test case which I will add in each scenario (in the feature file) and once the feature file is executed. She is expecting to update the excel sheet with Pass/Fail result for all test name tags. I know how to write script in BDD but never integrated excel sheet with BDD scenario. So any help on above requirement is much appreciated.

1

There are 1 best solutions below

0
On

So you need 2 things

  1. Get the Result of scenario
  2. Update in excel Sheet

You can do this like below in AfterScenario , so after each scenario is executed we will pass its tags and result to update function which will open the excel sheet and update it.

    [AfterScenario]
    public async Task TearDown()
    {
      string resultOfScenario = _scenarioContext.ScenarioExecutionStatus.ToString(); 
      var tags = _scenarioContext.ScenarioInfo.Tags

      functiontoupdateExcelsheet(tags,resultofscenario)

     }

if your test cases are run in parallel , you can try using below. Save all tags / result in a csv etc.

once all tests are run.. you can call the function which can write it to excel

        [AfterTestRun]