Search code examples
geb

Navigator.find function in GEB erases predicates. Is it good practice?


The following surprised me a lot! Predicates in the following statements will be removed

String selector = 'ul'
Map predicates = [class: 'catalog']

navigator.find predicates, selector

I found the following comments regarding this behavior:

/**
 * Optimizes the selector if the predicates contains `class` or `id` keys that map to strings. Note this method has
 * a side-effect in that it _removes_ those keys from the predicates map.
 */

My question. Is it really rule of good manners to change something in data coming to the function as an argument?

I remember such cases from C++ but in java world priority of integrity is higher that optimizing code at the expense of function caller!

I met this behavior in my program and spent lot of time to figure out why my definition structure is changing during execution. Thoughts of memory leaks were coming already.


Solution

  • It indeed is a bad practice and should not be done. I never thought that someone might reuse the predicate map passed to Navigator.find() but your use case is completely valid.

    Please create a ticket for this in Geb's issue tracker.