6. Page flow

Page flow is a widely used pattern in web testing which describes how we should use our page objects to write more readable and well designed code. What page flow telling us, is that in our test code every Page Object method which navigates from one page to another should return a new Page Object. The following actions in the test code will be executed by calling methods from the newly returned Page Object. Here is an example:

Sample code - Password change

The benefits of this pattern are:

  1. Easier to write test code. The Page Object methods reveals which page will be the next the method execution.
  2. Improving test code readability
  3. We got additional verifications, because each page object extends the Selenium’s LoadableComponent class. When we are creating a new instance of a PageObject the isLoaded() method will be executed, which contains validations against must displayed elements on the page.

What is the connection between page flow and cucumber?

The reason we wrote this small tutorial is to represent what we lose with cucumber. In cucumber the test steps are independent methods which means it’s harder to use page flow to write test methods. The cucumber implementation of the above mentioned test case looks like this:

Scenario: ChangePassword
Given Login with “<username>” “<password>”
And Open Settings page
And Open Change password tab
When Change password from “<password>” to “<new password>”
Then Logout
And Login with “<username>” “<new password>”

Examples:

| username |    password    | new password |
| TestUser | secretPassword |  newSecPass  |

As we mentioned before every step is mapped to one method in Java world. That being said, we need to store the page object reference in the common object to be able to use in the next step. The downside of the solution is that we need to cast the currently used page object in every step to access to particular page object methods.
The bigger issue is that we can skip a test step or put them into a wrong order. We are not able to found out our mistake until we execute the code. For instance:

Scenario: ChangePassword
Given Login with “<username>” “<password>”
And Open Change password tab
And Open Settings page
When Change password from “<password>” to “<new password>”
And Login with “<username>” “<new password>”

Examples:

| username |    password    | new password |
| TestUser | secretPassword |  newSecPass  |

This cucumber scenario will compile without exception, but will fail when trying to execute test step “And Open Change password tab”.

Conclusion

With cucumber:

  • the test cases are executing slower
  • the organization of the steps can be chaotic and not really intuitive if there are lot of steps
  • we won’t get alerted if the order of the test steps is not correct or if a test step is missing before execution

Similar Posts from the author: