Why is the execution time for present? twice as long as visible? in ruby/watir? -


after reading several web pages including testing justin ko says

  • exists? – returns whether element exists.
  • present? – returns true if element exists , visible on page
  • visible? – if parent element isn’t visible cannot write element. reliable way determine iterate dom element tree checking every element make sure it’s visible.

from that

  1. i predict exists? fastest, because checks see if element exists.
  2. that present? 2nd fastest checks existence , visibility.
  3. that visible? slowest because (as read it) has iterate dom element tree.

simply checking 1 element sounds constant-time while iteration sounds linear-time.

i happened running time tests , thought interesting time above methods well. 1 of predictions wrong.

exists? fastest; coming in faster visible? however, present? twice slow visible?

i tried calling methods in different order , enclosing them in 1.upto(10) loop average out times. same results.

something happening here don't understand , i'd understand. know why present? takes twice long visible? or @ least have hypothesis?

it makes sense present? slowest because checks existence and visibility.

https://github.com/watir/watir-webdriver/blob/6212504320559a90966052506c5e9e26b7d16533/lib/watir-webdriver/elements/element.rb#l406

def present?   exists? && visible? end 

it make sense take long exists? , visible? combined.


Comments