With Test Automation's Page Object Model we link pages together like this:
WebDriver driver = new WebDriver() HomePage homePage = new HomePage(driver); LoginPage loginPage = homePage.GoToLoginPage(); WelcomePage welcomePage = loginPage.Login(); etc etc
The big benefit of this is if the Devs change the homepage so it no longer links to the loginpage, I can update my homepage class and see all the tests I need to update (with errors) before even running a test.
With Gherkin however, each row above would form a separate 'Step' and therefore a separate method. Therefore, how can this linking be done?
Is the only way to place instances of the page object classes (e.g. homePage, loginPage, etc) into a cross gherkin statement persistant store (e.g. like a specflow POCO or 'World')?
Steps to setup Cucumber Test Automation Framework using Page Object Model. Create a Java Class for each page where define WebElements as variables using Annotation @FindBy and Create methods for actions performed on WebElements.
Selenium is a widely used tool for functional testing across top organizations as it is easy to integrate with Gherkin and makes understanding and automating of the flow both easy and possible to be done at the same time.
Note: Description is not a keyword of Gherkin.
Ok so having asked numerous dev and test automation experts, it seems the solution is to continue with linking [e.g. WelcomePage welcomePage = loginPage.loginWithValidUser(validUser)]
is the way to go.
To persist instance of page objects across steps (e.g. welcomePage in example above) you can use dependency injection tool (creating functionality similar to World extensions in Ruby's implementation of cucumber).
Here is more info: https://cukes.info/docs/reference/java-di
However, most projects will benefit from a Dependency Injection module to organize your code better and to share state between Step Definitions.
More info from SpecFlow (the .net official cucumber implementation):
http://specflow.org/getting-started/beyond-the-basics/
And finally, I have created a whole blog around this area that might help people out, since gherkin/page object interaction is a subject of great interest to me:
http://www.seligmanventures.com/dev-blog/test-automation-page-object-model-with-gherkin
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With