Question

Context:

I'm trying to make reusable step definitions that click on page objects on the current page, e.g. (cucumber step def follows):

When(/^the user clicks the "([^"]*)" button$/) do |button|

      click_button = button.downcase.gsub(" ","_")
      @current_page #somehow get current page object on this line
      @current_page.click_button

end

Problem statement:

I can't find anything that returns the current page object.

An explanation for why the obvious solution didn't work:

I thought @current_page was already there as something I could use. I looked in the source code for page object, and the variable @current_page does exist. Not sure how to use it if I can...


BTW, in this case, I have a bunch of testers that can write Gherkin but not necessarily step definitions. We are trying to rapidly finish a bunch of regression tests for an in house app with an unchanging interface.

Was it helpful?

Solution

This is somewhat at odds with what page-object is trying to provide.

Page object attempts to provide well named actions for interacting with a specific page. If you are wanting to make something that works in general against any page, it will be much easier to write it with watir-webdriver directly.

That said, I agree that a specification based heavily on implementation like that is likely to change. I also would add that it doesn't add much value. I would only continue down this path if you understand and accept that you are using cucumber as a test templating tool instead of a requirements communication tool.

OTHER TIPS

As Justin Ko mentioned, @current_page gets set when you call the on or visit methods. Its not a good idea to lump something that changes the page object in a step that performs a specific action (in this case clicking a button). You might want a different step that indicates the behavior of the application, such as

     the application lands on the <your page> page

Then you're can use the name of the page object class to load @current_page via the on method in that step definition. This also gives the benifit (or curse of having your step having more lower level details) of indicating expected page navigation behavior.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top