Caching elements
Element caching is a performance optimization technique that reduces test execution time by eliminating unnecessary repeated searches for frequently accessed elements. When an element is cached, Kolibrium first finds the element then stores the result for all future usages, minimizing DOM (Document Object Model) searches and improving performance.
Caching mechanics
Default behavior
By default, Kolibrium automatically caches elements. The first element lookup is stored and reused in subsequent accesses. This reduces overhead of repeated element searches.
Disabling caching
By setting cacheLookup = false
, Kolibrium will perform a new DOM search each time the element is accessed. This is useful for dynamic pages with frequently changing content.
val dynamicContent by driver.className(
locator = "changing-content",
cacheLookup = false // A new lookup will be performed each time the element is accessed.
)
val dynamicList by driver.classNames(
locator = "dynamic-items",
cacheLookup = false // A new lookup will be performed each time the elements are accessed.
)
Use this feature with caution.
Disabled cacheLookup
can significantly increase the number of issued findElement(s)
commands because Kolibrium doesn't store the result when it locates an element. Instead, it always relocates the element first, which can lead to unnecessary overhead.