Let’s introduce page objects into our awesome browser automation project.
The following pull request shows changes for introducing page objects for the home page.
Page objects gem searches for page object files in support folder. The page object is a Ruby class that includes the PageObject library. page_url is a page object attribute that holds page URL (note that attribute name explains its purpose – this is clean code kata). The value of page_url looks cryptic, but only if you never heard of Ruby On Rails template engine.
are start and stop characters for the template. This template will receive the params dictionary with one dictionary key value :base_url (in Ruby, variable with : is called symbol and dictionary keys are usually symbols).
is a page object factory. It accepts page object class name, using_params: is key with a value that is a dictionary with page object params. As we stated in page object HomePage, we expect a dictionary with key base_url and value @app[‘SITE’] (application.yml has this parameter value.)
is factory that accepts page object class name, and it returns the Watir Browser object. That object has a url attribute that holds current page url.
You have your first page objects implementation. Run cucumber cmd, and you should have one scenario pass and one fail.