Create page object framework using cucumber watir
My first ruby code was with Capybara and cucumber and I’m still coding on it with the help of site_prism to have a page object structure. Last couple of weeks I’ve spent some time with watir just from curiosity and because it uses Ruby, a full-featured modern scripting language, rather than a proprietary vendorscript. Here I will try to show to you guys how to get started with cucumber watir using page object model.
Cucumber watir setup:
Getting started with cucumber watir
Install the gem from rubygems.org:
Cucumber watir project structure:
Cucumber watir page object model code example:
Lets see what’s inside model >> page_object.rb
Lets create our object inside model >> object.rb
Lets handle our components :
Your first cucumber watir page inside mapping >> pages >> main_page.rb
Your first cucumber waitr from inside mapping >> forms >> search_form.rb
Your first cucumber watir component class inside mapping >> components >> header_menu.rb
Create your first cucumber watir feature file inside features :
Inside support folder we are going to initialise the project setup , environment variables , selenium driver , and provide the possibility to take screenshots
support >> _init.rb
support >> browser.rb
support >> env.rb
support >> screenshot_maker.rb
And we are almost done lets create the step definition inside features >> step_definitions for our cucumber watir project
Actions step definitions example :
Assertions context example :
Here we go , you just managed to setup your first cucumber watir project and your are ready to extend it with as many page objects and components you want.
What I like about this structure is because gives you full reusability of the cucumber steps. I don’t like the fact that complex logic need to be handled separated of the reusable actions .
If you need more informations about setup you can find it here on the official watir page.
How to initialise the cucumber ruby project you can fallow the cucumber documentation .