Posts

Showing posts from 2014

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

Foreward I 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. Foreward What is PageFactory? Charlie and the Page Factory A Factory in Chicago that Makes Miniature Models… of Factories 1. Instance an ElementLocatorFactory by giving it a SearchContext 2. Instance a FieldDecorator by giving it the ElementLocatorFactory 3. Use the FieldDecorator to assign references to the page object’s WebElement fields Summary What is PageFactory? Selenium WebDriver comes with a fancy class called PageFactory . It allows you to write your page object’s lik