Class: RoboTest::Locator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(how, what, options = { "hidden" => false, "ajax_load" => false }) ⇒ Locator

Returns a new instance of Locator.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/robotest/locator.rb', line 8

def initialize(
    how,
    what,
    options = {
      "hidden" => false,
      "ajax_load" => false
    }
  )
  @how = how
  @what = what
  @options = options
end

Instance Attribute Details

#howObject

Returns the value of attribute how.



4
5
6
# File 'lib/robotest/locator.rb', line 4

def how
  @how
end

#options(driver = $focus_driver) ⇒ Object

Returns the value of attribute options.



6
7
8
# File 'lib/robotest/locator.rb', line 6

def options
  @options
end

#whatObject

Returns the value of attribute what.



5
6
7
# File 'lib/robotest/locator.rb', line 5

def what
  @what
end

Instance Method Details

#attribute(name, driver = $focus_driver) ⇒ Object



57
58
59
# File 'lib/robotest/locator.rb', line 57

def attribute(name, driver = $focus_driver)
  driver.find_element(self).attribute(name)
end

#check(driver = $focus_driver) ⇒ Object



174
175
176
# File 'lib/robotest/locator.rb', line 174

def check(driver = $focus_driver)
  self.click unless self.is_checked?
end

#clear(driver = $focus_driver) ⇒ Object

Text box methods



186
187
188
# File 'lib/robotest/locator.rb', line 186

def clear(driver = $focus_driver)
  driver.find_element(self).clear
end

#clear_and_send_keys(*args) ⇒ Object



194
195
196
197
# File 'lib/robotest/locator.rb', line 194

def clear_and_send_keys(*args)
  clear($focus_driver)
  send_keys(*args)
end

#click(driver = $focus_driver) ⇒ Object

Methods inherited and overriden from Selenium #



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/robotest/locator.rb', line 29

def click(driver = $focus_driver)
  begin
    driver.find_element(self).click
    puts "Clicked - #{self.how} => #{self.what}"
  rescue Exception => e
    if(e.message.include?("is not clickable at point") || e.message.include?("element not visible") || e.message.include?("stale element reference"))
      sleep 3
      locator = Locator.new(@how,@what,@options)
      locator.click
    else
      puts "Not clicked at - #{self.how} => #{self.what}"
      puts e.message
    end
  end
end

#click_if_present(driver = $focus_driver) ⇒ Object



140
141
142
# File 'lib/robotest/locator.rb', line 140

def click_if_present(driver = $focus_driver)
  click(driver) if is_present?(driver)
end

#click_if_present_with_wait(timeout = , driver = $focus_driver) ⇒ Object



144
145
146
# File 'lib/robotest/locator.rb', line 144

def click_if_present_with_wait(timeout = $conf["implicit_wait"], driver = $focus_driver)
  click(driver) if is_present_with_wait?(timeout, driver)
end

#css_value(prop, driver = $focus_driver) ⇒ Object



61
62
63
# File 'lib/robotest/locator.rb', line 61

def css_value(prop, driver = $focus_driver)
  driver.find_element(self).css_value(prop)
end

#displayed?(driver = $focus_driver) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/robotest/locator.rb', line 65

def displayed?(driver = $focus_driver)
  driver.find_element(self).displayed?
end

#enabled?(driver = $focus_driver) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/robotest/locator.rb', line 69

def enabled?(driver = $focus_driver)
  driver.find_element(self).enabled?
end

#get_element(driver = $focus_driver) ⇒ Object



162
163
164
# File 'lib/robotest/locator.rb', line 162

def get_element(driver = $focus_driver)
  driver.find_element(self)
end

#get_value(driver = $focus_driver) ⇒ Object



199
200
201
# File 'lib/robotest/locator.rb', line 199

def get_value(driver = $focus_driver)
  driver.find_element(self).attribute("value")
end

#hash(driver = $focus_driver) ⇒ Object



82
83
84
# File 'lib/robotest/locator.rb', line 82

def hash(driver = $focus_driver)
  driver.find_element(self).hash
end

#is_checked?(driver = $focus_driver) ⇒ Boolean

Check box methods

Returns:

  • (Boolean)


170
171
172
# File 'lib/robotest/locator.rb', line 170

def is_checked?(driver = $focus_driver)
  self.attribute("checked") == "true"
end

#is_enabled_with_wait?(timeout = , driver = $focus_driver) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
76
77
78
79
80
# File 'lib/robotest/locator.rb', line 73

def is_enabled_with_wait?(timeout=$conf["implicit_wait"], driver = $focus_driver)
  index=0
  while driver.find_element(self).enabled? == false
    sleep 1
    break if index == timeout
    index+=1
  end
end

#is_not_present_with_wait?(timeout = , driver = $focus_driver) ⇒ Boolean

Returns:

  • (Boolean)


135
136
137
138
# File 'lib/robotest/locator.rb', line 135

def is_not_present_with_wait?(timeout=$conf["implicit_wait"],driver=$focus_driver)
  Wait.wait_for_element_hide(self,timeout,driver)
  return !is_present?(driver)
end

#is_present?(driver = $focus_driver) ⇒ Boolean

Returns:

  • (Boolean)


118
119
120
121
122
123
124
125
126
127
128
# File 'lib/robotest/locator.rb', line 118

def is_present?(driver=$focus_driver)
  driver.driver.manage.timeouts.implicit_wait = 0
  begin
    return driver.driver.find_element(self.how,self.what).displayed?
  rescue Exception => e
    driver.driver.manage.timeouts.implicit_wait = $conf["implicit_wait"]
    return false
  ensure
    driver.driver.manage.timeouts.implicit_wait = $conf["implicit_wait"]
  end
end

#is_present_with_wait?(timeout = , driver = $focus_driver) ⇒ Boolean

Returns:

  • (Boolean)


130
131
132
133
# File 'lib/robotest/locator.rb', line 130

def is_present_with_wait?(timeout=$conf["implicit_wait"],driver=$focus_driver)
  Wait.wait_for_element(self,timeout,driver)
  is_present?(driver)
end

#location(driver = $focus_driver) ⇒ Object



86
87
88
# File 'lib/robotest/locator.rb', line 86

def location(driver = $focus_driver)
  driver.find_element(self).location
end

#location_once_scrolled_into_view(driver = $focus_driver) ⇒ Object



90
91
92
# File 'lib/robotest/locator.rb', line 90

def location_once_scrolled_into_view(driver = $focus_driver)
  driver.find_element(self).location_once_scrolled_into_view
end

#mouse_over(index = 1, driver = $focus_driver) ⇒ Object



152
153
154
155
# File 'lib/robotest/locator.rb', line 152

def mouse_over(index = 1, driver = $focus_driver)
  element = driver.find_elements(self)[index-1]
  driver.action.move_to(element).perform
end

#move_and_click(driver = $focus_driver) ⇒ Object



157
158
159
160
# File 'lib/robotest/locator.rb', line 157

def move_and_click(driver = $focus_driver)
  element = driver.find_element(self)
  driver.action.move_to(element).click.perform
end

#property(driver = $focus_driver) ⇒ Object



94
95
96
# File 'lib/robotest/locator.rb', line 94

def property(driver = $focus_driver)
  driver.find_element(self).property
end

#selected?(driver = $focus_driver) ⇒ Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/robotest/locator.rb', line 98

def selected?(driver = $focus_driver)
  driver.find_element(self).selected?
end

#send_keys(*args) ⇒ Object



190
191
192
# File 'lib/robotest/locator.rb', line 190

def send_keys(*args)
  $focus_driver.find_element(self).send_keys(*args)
end

#size(driver = $focus_driver) ⇒ Object



102
103
104
# File 'lib/robotest/locator.rb', line 102

def size(driver = $focus_driver)
  driver.find_element(self).size
end

#style(prop, driver = $focus_driver) ⇒ Object



106
107
108
# File 'lib/robotest/locator.rb', line 106

def style(prop, driver = $focus_driver)
  driver.find_element(self).style(prop)
end

#submit(driver = $focus_driver) ⇒ Object



110
111
112
# File 'lib/robotest/locator.rb', line 110

def submit(driver = $focus_driver)
  driver.find_element(self).submit
end

#tag_name(driver = $focus_driver) ⇒ Object



114
115
116
# File 'lib/robotest/locator.rb', line 114

def tag_name(driver = $focus_driver)
  driver.find_element(self).tag_name
end

#text(driver = $focus_driver) ⇒ Object



45
46
47
# File 'lib/robotest/locator.rb', line 45

def text(driver = $focus_driver)
  return driver.find_element(self).text
end

#texts(driver = $focus_driver) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/robotest/locator.rb', line 49

def texts(driver = $focus_driver)
  elements_text = []
  driver.find_elements(self).each do |element|
    elements_text.push(element.text)
  end
  return elements_text
end

#to_sObject



148
149
150
# File 'lib/robotest/locator.rb', line 148

def to_s
  return "How ===> #{@how}\nWhat ===> #{@what}\nOptions ===> #{@options}"
end

#uncheck(driver = $focus_driver) ⇒ Object



178
179
180
# File 'lib/robotest/locator.rb', line 178

def uncheck(driver = $focus_driver)
  self.click if self.is_checked?
end