Showing posts from 2014

A Case Study of Java's Dynamic Proxies (and other Reflection Bits): Selenium's PageFactory

ForewardI spend a lot of time studying the source code of libraries that I really enjoy using. Since my day job is developing automated web UI tests at Red Hat, Selenium is one of those libraries. At the time I started writing this, I was not very familiar with Java’s reflection capabilities, nor what the heck a “Dynamic Proxy” was. The Proxy pattern is particularly powerful, and java.lang.reflect’s dynamic proxies provide a fairly nice way to do it. Dissecting PageFactory demonstrates.ForewardWhat is PageFactory?Charlie and the Page FactoryA Factory in Chicago that Makes Miniature Models… of Factories1. Instance an ElementLocatorFactory by giving it a SearchContext2. Instance a FieldDecorator by giving it the ElementLocatorFactory3. Use the FieldDecorator to assign references to the page object’s WebElement fieldsSummary What is PageFactory?Selenium WebDriver comes with a fancy class called PageFactory. It allows you to write your page object’s like this:classLoginPage{privateWebEleme…