Class: DotDiff::ElementHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/dotdiff/element_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(driver, elements = DotDiff.js_elements_to_hide) ⇒ ElementHandler

Returns a new instance of ElementHandler.



5
6
7
8
# File 'lib/dotdiff/element_handler.rb', line 5

def initialize(driver, elements = DotDiff.js_elements_to_hide)
  @driver = driver
  @elements = elements
end

Instance Attribute Details

#driverObject

Returns the value of attribute driver.



3
4
5
# File 'lib/dotdiff/element_handler.rb', line 3

def driver
  @driver
end

Instance Method Details

#element_exists?(xpath) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/dotdiff/element_handler.rb', line 31

def element_exists?(xpath)
  # TODO: Allow custom overriding beyond Capybara.default_max_wait_time
  driver.find(:xpath, xpath, wait: 2, visible: :all) rescue nil
end

#elementsObject



36
37
38
# File 'lib/dotdiff/element_handler.rb', line 36

def elements
  @elements ||= []
end

#hideObject



10
11
12
13
14
15
16
# File 'lib/dotdiff/element_handler.rb', line 10

def hide
  elements.each do |xpath|
    if element_exists?(xpath)
      driver.execute_script("#{js_element(xpath)}.style.visibility = 'hidden'")
    end
  end
end

#js_element(xpath) ⇒ Object



26
27
28
29
# File 'lib/dotdiff/element_handler.rb', line 26

def js_element(xpath)
  "document.evaluate(\"#{xpath}\", "\
  "document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue"
end

#showObject



18
19
20
21
22
23
24
# File 'lib/dotdiff/element_handler.rb', line 18

def show
  elements.each do |xpath|
    if element_exists?(xpath)
      driver.execute_script("#{js_element(xpath)}.style.visibility = ''")
    end
  end
end