Context Injection Query For Async ReqNroll #481
Replies: 2 comments
-
As you have already surmised, the ideal solution here is to not couple your objects to threads or execution flows and instead lean on the DI system to provide these components to your other objects where they need them: it's precisely what the DI system is for. You might be able to get something to work quickly by using If there's something about using the DI system that's not working for you, or if you'd like to run through some examples of what you believe you'd need to implement, we can help validate the implementation and suggest potential improvements that might make it easier to swallow. |
Beta Was this translation helpful? Give feedback.
-
Also please have a look at our sample app, you can get inspiration from that too. https://github.com/reqnroll/Sample-ReqOverflow/ |
Beta Was this translation helpful? Give feedback.
-
Hello,
Our team has begun the process of migrating from Specflow to ReqNRoll for our Playwright .NET/Nunit Test Framework, but in doing so we are experiencing issues due to the handling of threads in ReqNRoll. I am aware that ReqNRoll handles threads differently to that of Specflow, and wondered if we could get help in the best approach for obtaining our thread data in real time.
Our project implementation takes the following approach.
Feature File
-> Step File
-> Page Object Files
-> Components
In our Step File we reference our Page Object class which contains definitions for all our Individual components, these components are 'helper' classes which contain all the functionality we expect a given component to make and this is the point in which we use Playwright to interact with our components.
Our dilema here is we would like a way to initialise our WebDriver and PlayWright Page as part of the [BeforeScenario] event and then access this in our Component files without the need to inject this all the way through our step and Page Object definitions. Until now we have achieved this in Specflow using ThreadStatic variables which have been working correctly, but I believe this no longer works for ReqNRoll.
Is there a way to reference this data directly for inteligent extraction of this data?
Here is a highly simplified example of our approach to demonstrate the flow. Our tests are required to run in parallel and we have ~50+ components. Each page could have 20+ components defined, some of which are utilised multiple times.
Class Hooks
[BeforeScenario]
Static Class Context
Class Button
public async Task ClickButton(){
// use Context.BrowserContext to execute the action
}
Class MyPage
public Button saveButton = new("locatorID");
Class StepDefinition
MyPage page = new();
public async Task MyStepDefinition(){
page.saveButton.ClickButton();
}
Any advice or help with this approach would be greatly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions