Class: Citronella::Ui::WebUi

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

Instance Method Summary collapse

Constructor Details

#initialize(driver, webdriver_wait, logger, locator, function_name, class_name) ⇒ WebUi

Returns a new instance of WebUi.

Parameters:

  • driver (Webdriver)

    The web driver object.

  • webdriver_wait (Integer)

    The timeout for webdriver wait.

  • logger (Boolean)

    A flag indicating whether to log actions.

  • locator (Hash)

    The locator for the web element.

  • function_name (String)

    The name of the function.

  • class_name (String)

    The name of the class.



37
38
39
40
41
42
43
44
45
# File 'lib/web_ui.rb', line 37

def initialize(driver, webdriver_wait, logger, locator, function_name,
               class_name)
  @driver = driver
  @wait = webdriver_wait
  @logger = logger
  @locator = locator
  @function_name = function_name
  @class_name = class_name
end

Instance Method Details

#clickObject

Clicks on the web element.



82
83
84
85
86
# File 'lib/web_ui.rb', line 82

def click
  Citronella::Log.logger(@logger, @class_name, @function_name, __method__)
  el = webdriver_wait(@driver.find_element(@locator), displayed=true)
  el.click
end

#get_elementWebdriver::Element

Returns a web element using find_element method.

Returns:

  • (Webdriver::Element)

    The web element.



92
93
94
95
96
# File 'lib/web_ui.rb', line 92

def get_element
  Citronella::Log.logger(@logger, @class_name, @function_name,
                         __method__.to_s)
  webdriver_wait(@driver.find_element(@locator))
end

#get_elementsArray<Webdriver::Element>

Returns a list of web elements using find_elements method.

Returns:

  • (Array<Webdriver::Element>)

    The list of web elements.



102
103
104
105
106
# File 'lib/web_ui.rb', line 102

def get_elements
  Citronella::Log.logger(@logger, @class_name, @function_name,
                         __method__.to_s)
  webdriver_wait(@driver.find_elements(@locator))
end

#send_keys(text, clear = false, return_key = false) ⇒ Object

Sends keys to the web element.

Parameters:

  • text (String)

    The text to be sent.

  • clear (Boolean) (defaults to: false)

    Flag indicating whether to clear the field before sending keys.

  • return_key (Boolean) (defaults to: false)

    Flag indicating whether to send a return key.



70
71
72
73
74
75
76
77
78
# File 'lib/web_ui.rb', line 70

def send_keys(text, clear=false, return_key=false)
  Citronella::Log.logger(@logger, @class_name, @function_name, __method__)
  el = webdriver_wait(@driver.find_element(@locator), displayed=true)
  el.send_keys text

  if return_key
    el.send_keys :return
  end
end