Using Page Object Pattern in Rspec

Amalrik Maia
1 min readMar 2, 2019

--

Clear tests with this pattern is easy

code should be SOLID

first published at: coffedutty

The page object pattern is a handy technique you can use to simplify the interaction with forms in a web app.

Take a look at this code in rspec.

code in pure capybara

Although capybara has a really great syntax, this can be troublesome with complex forms and prevents any code reuse.

This is the final code after refactored to use PO pattern.

code refactored with page object pattern

The first thing is creating a spec/support folder.

The class is a simple PORO

The first thing is to require devise, capybara and rails helpers we need.

Then add the methods to the class, to chain methods just remember return self:

--

--