After attending the PushToTest-sponsored Selenium: You’re Doing It Wrong webinar in May, I (foolishly, as it turns out!) followed almost all of presenter Adam Goucher’s advice, including the part about not necessarily following all of his advice! Specifically, I continued to put Selenium API calls (such as is_text_present) within the tests of my Python page object framework, albeit only for the assertions, because I thought the assertions should exist in the tests rather than in the page objects. At yesterday’s Create Robust Selenium Tests with Page Objects webinar (also sponsored by PushToTest and also presented by Adam Goucher), I learned that keeping API calls out of the tests does not mean keeping assertions out of the tests, and I learned what could be achieved by maintaining the former. The two biggest “wins” I took away from this super useful webinar are:
- While API calls should not appear in the tests, the assertions themselves should exist there. These assertions should take the form of calls to assertion methods located within the page objects.
- If one adheres to this “no API calls within the tests” strategy, one can theoretically switch test frameworks without having to modify one’s tests! Since I’m still using Selenium-1 but envision transitioning to Selenium-2 within the next year, this point really hit home with me.
The webinar covered a wealth of other useful info for those of us trying to implement our automated tests using the page objects model: the concept of “page portion objects”; an explanation of the “one and only place” a sleep command should appear; a recommended order of attack for developing a test within a PO framework; lots of code samples, etc.
If you’re a Selenium test developer who’s not yet an expert on the PO model, I heartily recommend you check out the screencast of this presentation, which should be available soon on PushToTest’s ScreenCast page. You can also follow PushToTest Founder & CEO Frank Cohen on twitter.com/fcohen; he’ll send out a tweet as soon as the webinar has been published.