[MGNLTEST-23] Cucumber using pageObjects requires dependency injection Created: 28/Aug/19 Updated: 29/Nov/21 Resolved: 29/Nov/21 |
|
| Status: | Closed |
| Project: | Magnolia Test Framework |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Neutral |
| Reporter: | Christoph Meier | Assignee: | Unassigned |
| Resolution: | Obsolete | Votes: | 0 |
| Labels: | QA&Testing, ui-test-fwk | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Template: |
|
| Acceptance criteria: |
Empty
|
| Task DoR: |
Empty
|
| Epic Link: | core-TF-features-bugs-improvements |
| Description |
TLDRIn Cucumber step-definition classes, we need the possibility to share the root pageObject among several methods. This requires dependency injection. Cucumber contextIn cucumber within one step definition class, there are typically a bunch of step definition methods for multiple scenarios of the same feature or even for several features of the same domain. Each scenario consists of a set of methods. Sometimes one method can even be reused for more than one of the scenarios. The step def methods are executed in the order of how the scenario is defined in the feature file. step def methods can not have parameters to share objects between methods (with the exception of cucumber.api.Scenario). Cucumber recommends using dependency injection (DI) to share objects among different methods. Luckily, if a feature has multiple scenarios , the cucumber test runner creates a new instance of the step definition class for each scenario; and for each row of a scenario outline the cucumber test runner creates a new instance of the step definition class. Sharing the root pageObject "ui" among the methods of the same scenario ...Within one scenario the class must share the same instance of the root page object info.magnolia.testframework.PageObjects (="ui") among the methods of this same scenario. ... but resetting the ui when starting a new scenarioWhen executing the 1st method of a scenario, the class must get a new, "fresh" instance of the ui. HooksThe cucumber API provide "hooks" which are executed before the 1st step and after the last step.
See https://cucumber.io/docs/cucumber/api/#hooks Acceptance criteria
More resources
Mocked exampleI have added another example covering all my "cases" (having multiple scenarios plus a scenario outline).
To trigger the test, run ConfigAppAvailabilityTest via Maven |