You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have hooks.cs defined which has [BeforeScenario][AfterScenario][AfterStep][TearDown] which gets executed without an issues but [BeforeTestRun] and [BeforeFeature] are not getting executed.
Im using Playwright libraries which uses aysnc Task methods.
Steps to Reproduce
My hooks.cs looks like this //Comment shows which hoo attribute gets executed
using Allure.Net.Commons;
using Microsoft.Playwright;
using NUnit.Framework;
using DotNetEnv;
[assembly: Parallelizable(ParallelScope.Fixtures)]
[assembly: LevelOfParallelism(5)]
namespace cicd_playwright_specflow.src.Hooks
{
[Binding]
public class Hooks
{
public IPage page { get; private set; } = null!; //-> We'll call this property in the tests
public IAPIRequestContext RequestContext { get; private set; } = null!;
public IPlaywright playwrightAPI { get; private set; } = null!;
[BeforeTestRun] //Does not get executed
public static async Task BeforeTestRun()
{
Console.WriteLine("------Before Test Run");
// Console.WriteLine("----------InBeforeTestRun");
// // Load environment variables from .env file
// // Call the synchronous static method
await Task.Run (()=> LoadEnvironmentVariables());
}
[BeforeFeature] //Does not get executed
public static async Task BeforeAPIFeature()
{
await Task.Run (() => Console.WriteLine("Before API Feature ----------"));
}
public static void LoadEnvironmentVariables()
{
// Load environment variables from .env file
try
{
Env.Load();
//Somecode
}
catch (Exception e)
{
Console.WriteLine("Exception ------" + e.Data);
}
}
[BeforeScenario("@UI")] // Gets executed
public async Task RegisterSingleInstancePractitioner()
{
//Initialise Playwright
var playwright = await Playwright.CreateAsync();
//Initialise a browser - 'Chromium' can be changed to 'Firefox' or 'Webkit'
var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
Headless = false, // -> Use this option to be able to see your test running
Channel = "chrome",
SlowMo = 0
//Channel = "firefox"
});
//Setup a browser context
var context1 = await browser.NewContextAsync();
//Initialise a page on the browser context.
page = await context1.NewPageAsync();
}
[BeforeScenario("@API")] //Gets executed
public async Task BeforeAPIScenario()
{
Console.WriteLine("Running before Scenario for scenario with API tag");
playwrightAPI = await Playwright.CreateAsync();
RequestContext = await playwrightAPI.APIRequest.NewContextAsync(new APIRequestNewContextOptions
{
IgnoreHTTPSErrors = true
});
}
[AfterScenario("@UI")] //Gets executed
public async Task CloseBrowsers()
{
if (page != null)
await page.CloseAsync();
}
[AfterStep("@UI")] //gets exeecuted
public async Task AfterStep(ScenarioContext context)
{
if (context.TestError != null)
{
Console.WriteLine("Step Failed");
AllureApi.AddAttachment("FailedScreenshot_" + context.StepContext.StepInfo.Text, "image/png", await page.ScreenshotAsync(new() { FullPage = true }));
}
}
[TearDown]
public async Task TearDown()
{
// Gets executed
}
}
}
Link to Repro Project
No response
The text was updated successfully, but these errors were encountered:
SpecFlow Version
3.9.74
Which test runner are you using?
NUnit
Test Runner Version Number
3.14
.NET Implementation
.NET 6.0
Project Format of the SpecFlow project
Classic project format using
<PackageReference>
tags.feature.cs files are generated using
SpecFlow.Tools.MsBuild.Generation NuGet package
Test Execution Method
Command line – PLEASE SPECIFY THE FULL COMMAND LINE
I use the command
dotnet test
SpecFlow Section in app.config or content of specflow.json
Issue Description
I have hooks.cs defined which has [BeforeScenario][AfterScenario][AfterStep][TearDown] which gets executed without an issues but [BeforeTestRun] and [BeforeFeature] are not getting executed.
Im using Playwright libraries which uses aysnc Task methods.
Steps to Reproduce
My hooks.cs looks like this
//Comment shows which hoo attribute gets executed
Link to Repro Project
No response
The text was updated successfully, but these errors were encountered: