samedi 12 octobre 2019

How to access TestContext in Specflow 3.0 [BeforeTestRun] static Hook

I have started using Specflow 3.0 for .NET core tests project with built-in MSTest runner.

I encountered problem while trying to setup one-time method execution in order to persist bearer token value for all running tests in Specflow.

So my idea was to create [BeforeTestRun] Hook static method which would make HTTP request with given credentials. The problem is that those credentials are stored in .runsettings file, so I need to have MSTest's TestContext object in order to access dictionary property.

In Scenario's I'm injecting TestContext and it works fine, however I do not know how to access this object in static [BeforeTestRun] method. Is there any chance to create this object myself and store in static property?

If not, would you suggest another approach how could I store configurable settings besides .runsettings so I could access them in static [BeforeTestRun] method without DI?

Thank you

Aucun commentaire:

Enregistrer un commentaire