ncbi / robotframework-pageobjects

Implementation of the Page Object pattern with Robot Framework and selenium. Also facilitates page object pattern independent of Robot Framework
http://ncbi.github.io/robotframework-pageobjects
Other
84 stars 75 forks source link

Allow keywords to return None #51

Open dpsfrishberg opened 9 years ago

dpsfrishberg commented 9 years ago

Sometimes, in the course of Robotic events, a page object method needs to return None. We currently require that all keywords return either self, an instance of another page class, or, at least, some value other than None. This is so that page object authors are consciously deciding whether their keyword switches to a new page. This causes a problem, though, when the actual return value of a getter needs to be None, which is sometimes the case. This exception often gets in the way of debugging other problems in a test, forcing knowledge of this requirement on test authors.

After discussion with @hellmanj, we decided that this is likely more common than the problem we are trying to prevent: namely, you use a keyword that should take you to a new page, but the page object author forgot to return that page, and so you get the old page's version of the keyword instead of the new one. (This only happens if two pages define the same keyword that does slightly different things. Otherwise, you'll just get a message saying the keyword you tried to use couldn't be found.)

Therefore, we should take out the code (https://github.com/ncbi/robotframework-pageobjects/blob/master/robotpageobjects/page.py#L53, https://github.com/ncbi/robotframework-pageobjects/blob/master/robotpageobjects/page.py#L294) that requires returning a page object.

@hellmanj also suggests augmenting the exception that tells you that a keyword couldn't be found, with something reminding you that you need to return a page object from each keyword that takes you to a new page.

hellmanj commented 9 years ago

Well, technically you don't need to return a page object from each keyword if we make this change, so the message should say something to the effect of "If you just navigated to a different page and intend to use keywords from a different Page Object, you should return that new Page Object in the keyword which did the navigating". Hopefully there's a less verbose way to say that.

Never mind, what you wrote makes sense.