Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Caching Support

semperos edited this page Oct 31, 2011 · 13 revisions

Selenium-WebDriver provides some developer-facing caching facilities, specifically when leveraging their built-in PageObject design pattern API. However, this does not mesh with Clojure as naturally as it does in the Java API.

For this reason, clj-webdriver provides its own caching mechanisms for caching page elements based on Fogus' clache caching library. Due to the design of Selenium-WebDriver, the objects that point to page elements are only valid within the lifetime of a given page load; if you refresh the page, or navigate away from and back to a given page, the objects used to discover elements initially will no longer be valid. For this reason, clj-webdriver's caching functionality is particularly effective for large pages or form-based pages, where you will re-use certain elements repeatedly, and do not want to incur the cost of refinding them for every operation.

Quick-n-Easy

By default, clj-webdriver allows you to initialize an empty element cache by passing a "cache spec" to the new-driver function. This spec requires the following bits of information:

  • The caching strategy that should be used (all strategies supported by Fogus' clache library are supported by clj-webdriver)
  • Arguments that should be passed to the respective clache constructor for the caching strategy chosen
  • Either an :include or :exclude seq (vector), which should contain cache rules for inclusion or exclusion (whitelisting or blacklisting respectively)

Access the Cache Directly

The protocol used to implement clj-webdriver's caching support is exposed publicly, so you can manipulate the cache safely by looking at the IElementCache protocol and calling its functions.

Clone this wiki locally