Class: HTMLElement
- Inherits:
-
Object
- Object
- HTMLElement
- Defined in:
- lib/function/html_element.rb
Direct Known Subclasses
Constant Summary collapse
- TAB_TYPE_ID =
'id'.to_sym
- TAB_TYPE_VALUE =
'value'.to_sym
- TAB_TYPE_NAME =
'name'.to_sym
- TAB_TYPE_CLASS =
'class'.to_sym
- TAB_TYPE_TEXT =
'text'.to_sym
- TAB_TYPE_HREF =
'href'.to_sym
- TAB_TYPE_TITLE =
'title'.to_sym
- TAB_TYPE_URL =
'url'.to_sym
- TAB_TYPE_ACTION =
'action'.to_sym
- TAB_TYPE_INDEX =
'index'.to_sym
- TAB_TYPE_SRC =
'src'.to_sym
- TAB_TYPE_LENGTH =
'length'.to_sym
- TAB_TYPE_MAXLENGTH =
'maxlength'.to_sym
- TEXT_FIELD_SET =
text_field
1
- TEXT_FIELD_SET_VALUE =
2
- TEXT_FIELD_SET_APPEND =
3
- TEXT_FIELD_FOCUS =
4
- SELECT_LIST_SELECT =
select_list
1
- SELECT_LIST_SELECT_VALUE =
2
- FIRE_EVENT_ON_MOUSE_OVER =
fire_event
1
Instance Attribute Summary collapse
-
#browser ⇒ Object
Returns the value of attribute browser.
Instance Method Summary collapse
- #assert_equal(value, elem, type) ⇒ Object
-
#assert_text(text) ⇒ Object
0.0.6.
-
#assert_text_false(text) ⇒ Object
Assert False text in page.
- #attach_new_window(arg, value) ⇒ Object
- #check_html_exists?(elem) ⇒ Boolean
- #clear_checkbox(argname) ⇒ Object
- #click_button(arg, value) ⇒ Object
- #click_div(arg, value) ⇒ Object
- #click_image(arg, value) ⇒ Object
- #click_link(arg, value) ⇒ Object
- #click_span(arg, value) ⇒ Object
-
#fire_event(element, type = FIRE_EVENT_ON_MOUSE_OVER) ⇒ Object
Javascript event:
. -
#get_div(arg, value) ⇒ Object
Div.
- #get_form(arg, value) ⇒ Object
-
#get_frame(arg, value) ⇒ Object
Frame.
- #get_select_list(arg, value) ⇒ Object
-
#get_table(arg, value) ⇒ Object
Table.
- #goto(url) ⇒ Object
-
#initialize ⇒ HTMLElement
constructor
A new instance of HTMLElement.
-
#remove_all_cookies ⇒ Object
Remove all Cookies on Browser.
- #rescue_wait_retry(exception = Watir::Exception::UnknownObjectException, times = ProgramConfig::TIMEOUT, seconds = ProgramConfig::SLEEP, &block) ⇒ Object
-
#set_checkbox(arg, value) ⇒ Object
Checkbox.
- #set_file_field(arg, value, text) ⇒ Object
-
#set_radio(arg, value) ⇒ Object
Radio.
- #set_select_list(arg, value, type = SELECT_LIST_SELECT) ⇒ Object
- #set_text_field(arg, value, text, type = TEXT_FIELD_SET) ⇒ Object
-
#submit_form(arg, value) ⇒ Object
Form.
- #verify_text_field_value(arg, text) ⇒ Object
- #wait_until_html_loaded(elem) ⇒ Object
- #xxx ⇒ Object
Constructor Details
#initialize ⇒ HTMLElement
Returns a new instance of HTMLElement.
34 35 36 |
# File 'lib/function/html_element.rb', line 34 def initialize @browser = Watir::Browser::new ProgramConfig::BROWSER end |
Instance Attribute Details
#browser ⇒ Object
Returns the value of attribute browser.
32 33 34 |
# File 'lib/function/html_element.rb', line 32 def browser @browser end |
Instance Method Details
#assert_equal(value, elem, type) ⇒ Object
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/function/html_element.rb', line 232 def assert_equal(value,elem,type) case type when TAB_TYPE_TEXT then start_time = Time.now while (value != elem.text) do sleep ProgramConfig::SLEEP if Time.now - start_time> ProgramConfig::TIMEOUT raise RuntimeError, "(assert_equal) Timed out after #{ProgramConfig::TIMEOUT} seconds" end end when TAB_TYPE_VALUE then start_time = Time.now while (value != elem.value) do sleep ProgramConfig::SLEEP if Time.now - start_time> ProgramConfig::TIMEOUT raise RuntimeError, "(assert_equal) Timed out after #{ProgramConfig::TIMEOUT} seconds" end end when TAB_TYPE_TITLE then start_time = Time.now while (value != elem.title) do sleep ProgramConfig::SLEEP if Time.now - start_time> ProgramConfig::TIMEOUT raise RuntimeError, "(assert_equal) Timed out after #{ProgramConfig::TIMEOUT} seconds" end end when TAB_TYPE_LENGTH then start_time = Time.now while (value != elem.length) do sleep ProgramConfig::SLEEP if Time.now - start_time> ProgramConfig::TIMEOUT raise RuntimeError, "(assert_equal) Timed out after #{ProgramConfig::TIMEOUT} seconds" end end when TAB_TYPE_MAXLENGTH then start_time = Time.now while (value != elem.maxlength) do sleep ProgramConfig::SLEEP if Time.now - start_time> ProgramConfig::TIMEOUT raise RuntimeError, "(assert_equal) Timed out after #{ProgramConfig::TIMEOUT} seconds" end end when TAB_TYPE_URL then start_time = Time.now while (value != elem.url) do sleep ProgramConfig::SLEEP if Time.now - start_time> ProgramConfig::TIMEOUT raise RuntimeError, "(assert_equal) Timed out after #{ProgramConfig::TIMEOUT} seconds" end end end end |
#assert_text(text) ⇒ Object
0.0.6
211 212 213 214 215 216 217 218 219 |
# File 'lib/function/html_element.rb', line 211 def assert_text(text) #0.0.6 start_time = Time.now while !@browser.text.include?(text) do sleep ProgramConfig::SLEEP if Time.now - start_time> ProgramConfig::TIMEOUT raise RuntimeError, "Timed out assert after #{ProgramConfig::TIMEOUT} seconds" end end end |
#assert_text_false(text) ⇒ Object
Assert False text in page
222 223 224 225 226 227 228 229 230 |
# File 'lib/function/html_element.rb', line 222 def assert_text_false(text) start_time = Time.now while @browser.text.include?(text) do sleep ProgramConfig::SLEEP if Time.now - start_time> ProgramConfig::TIMEOUT raise RuntimeError, "Timed out assert after #{ProgramConfig::TIMEOUT} seconds" end end end |
#attach_new_window(arg, value) ⇒ Object
150 151 152 153 154 155 156 157 158 |
# File 'lib/function/html_element.rb', line 150 def attach_new_window(arg,value) begin ff1 = @browser.attach(arg,value) rescue Exception => e sleep ProgramConfig::SLEEP retry end return ff1 end |
#check_html_exists?(elem) ⇒ Boolean
189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/function/html_element.rb', line 189 def check_html_exists?(elem) start_time = Time.now while (!elem.exists?) do sleep ProgramConfig::SLEEP if Time.now - start_time> ProgramConfig::TIMEOUT puts "Timed out after #{ProgramConfig::TIMEOUT} seconds" false end end true end |
#clear_checkbox(argname) ⇒ Object
125 126 127 128 |
# File 'lib/function/html_element.rb', line 125 def clear_checkbox(argname) wait_until_html_loaded(@browser.checkbox(arg, value)) @browser.checkbox(arg, value).clear end |
#click_button(arg, value) ⇒ Object
51 52 53 |
# File 'lib/function/html_element.rb', line 51 def (arg,value) rescue_wait_retry{@browser.(arg,value).click} end |
#click_div(arg, value) ⇒ Object
59 60 61 |
# File 'lib/function/html_element.rb', line 59 def click_div(arg,value) rescue_wait_retry{@browser.div(arg,value).click} end |
#click_image(arg, value) ⇒ Object
55 56 57 |
# File 'lib/function/html_element.rb', line 55 def click_image(arg,value) rescue_wait_retry{@browser.image(arg,value).click} end |
#click_link(arg, value) ⇒ Object
47 48 49 |
# File 'lib/function/html_element.rb', line 47 def click_link(arg,value) rescue_wait_retry{@browser.link(arg,value).click} end |
#click_span(arg, value) ⇒ Object
63 64 65 |
# File 'lib/function/html_element.rb', line 63 def click_span(arg,value) rescue_wait_retry{@browser.span(arg,value).click} end |
#fire_event(element, type = FIRE_EVENT_ON_MOUSE_OVER) ⇒ Object
Javascript event:
161 162 163 164 165 166 |
# File 'lib/function/html_element.rb', line 161 def fire_event(element,type = FIRE_EVENT_ON_MOUSE_OVER) wait_until_html_loaded(element) if type == FIRE_EVENT_ON_MOUSE_OVER then element.fire_event("onMouseOver") end end |
#get_div(arg, value) ⇒ Object
Div
114 115 116 117 |
# File 'lib/function/html_element.rb', line 114 def get_div(arg,value) wait_until_html_loaded( @browser.div(arg, value) ) return @browser.div(arg, value) end |
#get_form(arg, value) ⇒ Object
96 97 98 99 |
# File 'lib/function/html_element.rb', line 96 def get_form(arg,value) wait_until_html_loaded(@browser.form(arg,value)) return @browser.form(arg,value) end |
#get_frame(arg, value) ⇒ Object
Frame
102 103 104 105 |
# File 'lib/function/html_element.rb', line 102 def get_frame(arg,value) wait_until_html_loaded(@browser.frame(arg,value)) return @browser.frame(arg,value) end |
#get_select_list(arg, value) ⇒ Object
139 140 141 142 |
# File 'lib/function/html_element.rb', line 139 def get_select_list(arg,value) wait_until_html_loaded(@browser.select_list(arg, value)) return @browser.select_list(arg, value) end |
#get_table(arg, value) ⇒ Object
Table
108 109 110 111 |
# File 'lib/function/html_element.rb', line 108 def get_table(arg,value) wait_until_html_loaded( @browser.table(arg,value) ) return @browser.table(arg,value) end |
#goto(url) ⇒ Object
38 39 40 |
# File 'lib/function/html_element.rb', line 38 def goto(url) @browser.goto(url) end |
#remove_all_cookies ⇒ Object
Remove all Cookies on Browser
169 170 171 172 |
# File 'lib/function/html_element.rb', line 169 def #0.0.8 jssh_command = "Components.classes[\"@mozilla.org/cookiemanager;1\"].getService(Components.interfaces.nsICookieManager).removeAll();" $jssh_socket.send("#{jssh_command}\n", 0) end |
#rescue_wait_retry(exception = Watir::Exception::UnknownObjectException, times = ProgramConfig::TIMEOUT, seconds = ProgramConfig::SLEEP, &block) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/function/html_element.rb', line 174 def rescue_wait_retry(exception = Watir::Exception::UnknownObjectException, times = ProgramConfig::TIMEOUT, seconds = ProgramConfig::SLEEP, &block) begin return yield rescue exception => e puts "Caught #{exception}: #{e}. Sleeping #{seconds} seconds." sleep(seconds) @browser.wait if (times -= 1)> 0 puts "Retrying... #{times} times left" retry end end yield end |
#set_checkbox(arg, value) ⇒ Object
Checkbox
120 121 122 123 |
# File 'lib/function/html_element.rb', line 120 def set_checkbox(arg,value) wait_until_html_loaded(@browser.checkbox(arg, value)) @browser.checkbox(arg, value).set end |
#set_file_field(arg, value, text) ⇒ Object
85 86 87 88 |
# File 'lib/function/html_element.rb', line 85 def set_file_field(arg,value,text) wait_until_html_loaded(@browser.file_field(arg,value)) @browser.file_field(arg,value).set(text) end |
#set_radio(arg, value) ⇒ Object
Radio
145 146 147 148 |
# File 'lib/function/html_element.rb', line 145 def set_radio(arg,value) wait_until_html_loaded(@browser.radio(arg, value)) @browser.radio(arg, value).set end |
#set_select_list(arg, value, type = SELECT_LIST_SELECT) ⇒ Object
130 131 132 133 134 135 136 137 |
# File 'lib/function/html_element.rb', line 130 def set_select_list(arg,value,type = SELECT_LIST_SELECT) wait_until_html_loaded(@browser.select_list(arg, value)) if type == SELECT_LIST_SELECT then @browser.select_list(arg, value).select(value) elsif type == SELECT_LIST_SELECT_VALUE then @browser.select_list(arg, value).select_value(value) end end |
#set_text_field(arg, value, text, type = TEXT_FIELD_SET) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/function/html_element.rb', line 67 def set_text_field(arg,value,text,type = TEXT_FIELD_SET) wait_until_html_loaded(@browser.text_field(arg,value)) if type == TEXT_FIELD_SET then @browser.text_field(arg,value).set(text) elsif type == TEXT_FIELD_SET_VALUE then @browser.text_field(arg,value).value = text elsif type == TEXT_FIELD_SET_APPEND then @browser.text_field(arg,value).append(text) elsif type == TEXT_FIELD_FOCUS then @browser.text_field(arg,value).focus end end |
#submit_form(arg, value) ⇒ Object
Form
91 92 93 94 |
# File 'lib/function/html_element.rb', line 91 def submit_form(arg,value) wait_until_html_loaded(@browser.form(arg,value)) @browser.form(arg,value).submit end |
#verify_text_field_value(arg, text) ⇒ Object
80 81 82 83 |
# File 'lib/function/html_element.rb', line 80 def verify_text_field_value(arg,text) wait_until_html_loaded( @browser.text_field(arg,text) ) assert(@browser.text_field(arg,text).verify_contains(text) ) end |
#wait_until_html_loaded(elem) ⇒ Object
201 202 203 204 205 206 207 208 209 |
# File 'lib/function/html_element.rb', line 201 def wait_until_html_loaded(elem) start_time = Time.now while (!elem.exists?) do sleep ProgramConfig::SLEEP if Time.now - start_time> ProgramConfig::TIMEOUT raise RuntimeError, "Timed out after #{ProgramConfig::TIMEOUT} seconds" end end end |
#xxx ⇒ Object
42 43 44 45 |
# File 'lib/function/html_element.rb', line 42 def xxx @browser.close # sleep(5) end |