watir 3.0.0.rc3 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +5 -0
- data/lib/watir.rb +1 -0
- data/lib/watir/loader.rb +2 -0
- data/lib/watir/version.rb +3 -0
- data/watir.gemspec +18 -54
- metadata +32 -278
- data/CHANGES +0 -712
- data/LICENSE +0 -34
- data/README.rdoc +0 -101
- data/VERSION +0 -1
- data/bin/watir-console +0 -7
- data/lib/watir/IEDialog/Release/IEDialog.dll +0 -0
- data/lib/watir/close_all.rb +0 -31
- data/lib/watir/container.rb +0 -110
- data/lib/watir/contrib/enabled_popup.rb +0 -21
- data/lib/watir/contrib/ie-new-process.rb +0 -27
- data/lib/watir/contrib/page_checker.rb +0 -29
- data/lib/watir/cookies.rb +0 -80
- data/lib/watir/core.rb +0 -43
- data/lib/watir/dialogs/file_field.rb +0 -34
- data/lib/watir/dialogs/javascript.rb +0 -43
- data/lib/watir/drag_and_drop_helper.rb +0 -68
- data/lib/watir/element.rb +0 -441
- data/lib/watir/element_collection.rb +0 -109
- data/lib/watir/form.rb +0 -96
- data/lib/watir/frame.rb +0 -47
- data/lib/watir/ie-class.rb +0 -765
- data/lib/watir/ie-process.rb +0 -47
- data/lib/watir/ie.rb +0 -20
- data/lib/watir/image.rb +0 -111
- data/lib/watir/input_elements.rb +0 -480
- data/lib/watir/irb-history.rb +0 -31
- data/lib/watir/link.rb +0 -46
- data/lib/watir/locator.rb +0 -243
- data/lib/watir/logger.rb +0 -19
- data/lib/watir/modal_dialog.rb +0 -72
- data/lib/watir/module.rb +0 -12
- data/lib/watir/non_control_elements.rb +0 -114
- data/lib/watir/page-container.rb +0 -108
- data/lib/watir/process.rb +0 -20
- data/lib/watir/screen_capture.rb +0 -115
- data/lib/watir/supported_elements.rb +0 -172
- data/lib/watir/table.rb +0 -224
- data/lib/watir/win32.rb +0 -40
- data/lib/watir/win32ole.rb +0 -16
- data/lib/watir/win32ole/1.8.7/win32ole.so +0 -0
- data/lib/watir/win32ole/1.9.3/win32ole.so +0 -0
- data/lib/watir/window.rb +0 -68
- data/lib/watir/xpath_locator.rb +0 -52
- data/rakefile.rb +0 -54
- data/unittests/all_tests.rb +0 -10
- data/unittests/buttons_xpath_test.rb +0 -68
- data/unittests/checkbox_test.rb +0 -163
- data/unittests/checkbox_xpath_test.rb +0 -106
- data/unittests/click_no_wait_test.rb +0 -23
- data/unittests/close_all_test.rb +0 -17
- data/unittests/core_tests.rb +0 -17
- data/unittests/css_selector_test.rb +0 -44
- data/unittests/css_test.rb +0 -38
- data/unittests/dialog_test.rb +0 -64
- data/unittests/div2_xpath_test.rb +0 -21
- data/unittests/div_test.rb +0 -170
- data/unittests/div_xpath_test.rb +0 -95
- data/unittests/document_standards.rb +0 -63
- data/unittests/element_collection_indexes_test.rb +0 -57
- data/unittests/element_collections_test.rb +0 -100
- data/unittests/element_test.rb +0 -47
- data/unittests/errorchecker_test.rb +0 -31
- data/unittests/filefield_test.rb +0 -43
- data/unittests/filefield_xpath_test.rb +0 -35
- data/unittests/form_test.rb +0 -282
- data/unittests/form_xpath_test.rb +0 -254
- data/unittests/frame_test.rb +0 -165
- data/unittests/google_form_test.rb +0 -15
- data/unittests/html/JavascriptClick.html +0 -39
- data/unittests/html/blankpage.html +0 -11
- data/unittests/html/buttons1.html +0 -40
- data/unittests/html/checkboxes1.html +0 -89
- data/unittests/html/click_no_wait.html +0 -14
- data/unittests/html/complex_table.html +0 -35
- data/unittests/html/cssTest.html +0 -42
- data/unittests/html/depot_store.html +0 -59
- data/unittests/html/div.html +0 -92
- data/unittests/html/div_xml.html +0 -21
- data/unittests/html/fileupload.html +0 -44
- data/unittests/html/formTest1.html +0 -38
- data/unittests/html/forms2.html +0 -44
- data/unittests/html/forms3.html +0 -131
- data/unittests/html/forms4.html +0 -26
- data/unittests/html/frame_buttons.html +0 -4
- data/unittests/html/frame_links.html +0 -4
- data/unittests/html/frame_multi.html +0 -5
- data/unittests/html/google_india.html +0 -119
- data/unittests/html/ie7_document_standards.html +0 -9
- data/unittests/html/ie8_document_standards.html +0 -9
- data/unittests/html/ie9_document_standards.html +0 -9
- data/unittests/html/iframe.html +0 -3
- data/unittests/html/iframeTest.html +0 -17
- data/unittests/html/iframeTest1.html +0 -7
- data/unittests/html/iframeTest2.html +0 -5
- data/unittests/html/images/1.gif +0 -0
- data/unittests/html/images/2.GIF +0 -0
- data/unittests/html/images/3.GIF +0 -0
- data/unittests/html/images/button.jpg +0 -0
- data/unittests/html/images/circle.jpg +0 -0
- data/unittests/html/images/map.GIF +0 -0
- data/unittests/html/images/map2.gif +0 -0
- data/unittests/html/images/minus.GIF +0 -0
- data/unittests/html/images/originaltriangle.jpg +0 -0
- data/unittests/html/images/plus.gif +0 -0
- data/unittests/html/images/square.jpg +0 -0
- data/unittests/html/images/triangle.jpg +0 -0
- data/unittests/html/images1.html +0 -65
- data/unittests/html/javascriptevents.html +0 -33
- data/unittests/html/link_pass.html +0 -11
- data/unittests/html/links1.html +0 -37
- data/unittests/html/links2.html +0 -11
- data/unittests/html/links_multi.html +0 -12
- data/unittests/html/list_matters.html +0 -720
- data/unittests/html/lists.html +0 -18
- data/unittests/html/map_test.html +0 -30
- data/unittests/html/modal_dialog.html +0 -10
- data/unittests/html/modal_dialog_launcher.html +0 -12
- data/unittests/html/multiple_specifiers.html +0 -64
- data/unittests/html/nestedFrames.html +0 -6
- data/unittests/html/new_browser.html +0 -17
- data/unittests/html/pass.html +0 -13
- data/unittests/html/popups1.html +0 -59
- data/unittests/html/pre.html +0 -29
- data/unittests/html/quirks_document_standards.html +0 -8
- data/unittests/html/radioButtons1.html +0 -71
- data/unittests/html/select_tealeaf.html +0 -54
- data/unittests/html/selectboxes1.html +0 -52
- data/unittests/html/simple_table.html +0 -25
- data/unittests/html/simple_table_buttons.html +0 -104
- data/unittests/html/simple_table_columns.html +0 -75
- data/unittests/html/table1.html +0 -179
- data/unittests/html/tableCell_using_xpath.html +0 -19
- data/unittests/html/table_and_tablerow_to_a.html +0 -174
- data/unittests/html/textarea.html +0 -30
- data/unittests/html/textfields1.html +0 -100
- data/unittests/html/textsearch.html +0 -44
- data/unittests/html/wallofcheckboxes.html +0 -1003
- data/unittests/html/xpath_nbsp.html +0 -11
- data/unittests/html/zeroindex.html +0 -11
- data/unittests/ie_exists_test.rb +0 -16
- data/unittests/ie_mock.rb +0 -94
- data/unittests/ie_test.rb +0 -54
- data/unittests/images_test.rb +0 -156
- data/unittests/images_xpath_test.rb +0 -90
- data/unittests/index_specifier_test.rb +0 -31
- data/unittests/js_events_test.rb +0 -31
- data/unittests/links_multi_test.rb +0 -34
- data/unittests/links_test.rb +0 -131
- data/unittests/links_xpath_test.rb +0 -38
- data/unittests/lists_test.rb +0 -23
- data/unittests/map_test.rb +0 -98
- data/unittests/minmax_test.rb +0 -37
- data/unittests/navigate_test.rb +0 -38
- data/unittests/nbsp_xpath_test.rb +0 -16
- data/unittests/no_wait_test.rb +0 -28
- data/unittests/non_core_tests.rb +0 -12
- data/unittests/other/all_tests_concurrent.rb +0 -57
- data/unittests/other/navigate_exception_test.rb +0 -24
- data/unittests/other/rexml_unit_test.rb +0 -27
- data/unittests/other/screen_capture_test.rb +0 -53
- data/unittests/other/testcase_method_order_test.rb +0 -36
- data/unittests/other/testcase_verify_test.rb +0 -25
- data/unittests/other/wait_until_test.rb +0 -102
- data/unittests/pagecontainstext_test.rb +0 -69
- data/unittests/parent_child_test.rb +0 -27
- data/unittests/perf_test.rb +0 -20
- data/unittests/pre_test.rb +0 -49
- data/unittests/radios_test.rb +0 -181
- data/unittests/radios_xpath_test.rb +0 -100
- data/unittests/security_setting_test.rb +0 -24
- data/unittests/selectbox_test.rb +0 -144
- data/unittests/selectbox_xpath_test.rb +0 -102
- data/unittests/setup.rb +0 -70
- data/unittests/speed_settings_test.rb +0 -67
- data/unittests/table_cell_using_xpath_test.rb +0 -34
- data/unittests/table_test.rb +0 -296
- data/unittests/table_xpath_test.rb +0 -109
- data/unittests/test_tests.rb +0 -9
- data/unittests/textarea_test.rb +0 -92
- data/unittests/textarea_xpath_test.rb +0 -77
- data/unittests/textfield_for_ch_char_test.rb +0 -32
- data/unittests/textfields_test.rb +0 -184
- data/unittests/textfields_xpath_test.rb +0 -110
- data/unittests/version_test.rb +0 -15
- data/unittests/win32ole_so_test.rb +0 -35
- data/unittests/window_tests.rb +0 -10
- data/unittests/windows/attach_to_existing_window_test.rb +0 -52
- data/unittests/windows/attach_to_new_window_test.rb +0 -74
- data/unittests/windows/close_window_test.rb +0 -20
- data/unittests/windows/frame_links_test.rb +0 -23
- data/unittests/windows/ie-each_test.rb +0 -46
- data/unittests/windows/modal_dialog_test.rb +0 -95
- data/unittests/windows/new_process_test.rb +0 -24
- data/unittests/windows/new_test.rb +0 -58
- data/unittests/windows/open_close_test.rb +0 -19
- data/unittests/windows/send_keys_test.rb +0 -26
- data/unittests/xpath_tests.rb +0 -11
- data/watir-rdoc.rb +0 -7
data/lib/watir/core.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
# these require statements are needed for Watir
|
2
|
-
# to work with minimum functionality
|
3
|
-
require 'timeout'
|
4
|
-
require 'watir/win32ole'
|
5
|
-
|
6
|
-
# these are required already in commonwatir, but not when using click_no_wait!
|
7
|
-
require 'watir/util'
|
8
|
-
require 'watir/exceptions'
|
9
|
-
require 'watir/matches'
|
10
|
-
require 'watir/wait'
|
11
|
-
require 'watir/wait_helper'
|
12
|
-
require 'watir/element_extensions'
|
13
|
-
|
14
|
-
require 'logger'
|
15
|
-
require 'watir/logger'
|
16
|
-
require 'watir/container'
|
17
|
-
require 'watir/xpath_locator'
|
18
|
-
require 'watir/locator'
|
19
|
-
require 'watir/page-container'
|
20
|
-
require 'watir/ie-class'
|
21
|
-
require 'watir/drag_and_drop_helper'
|
22
|
-
require 'watir/element'
|
23
|
-
require 'watir/element_collection'
|
24
|
-
require 'watir/form'
|
25
|
-
require 'watir/frame'
|
26
|
-
require 'watir/input_elements'
|
27
|
-
require 'watir/non_control_elements'
|
28
|
-
require 'watir/table'
|
29
|
-
require 'watir/image'
|
30
|
-
require 'watir/link'
|
31
|
-
require 'watir/window'
|
32
|
-
require 'watir/cookies'
|
33
|
-
|
34
|
-
require 'watir/win32'
|
35
|
-
require 'watir/modal_dialog'
|
36
|
-
|
37
|
-
require 'watir/module'
|
38
|
-
|
39
|
-
require 'rautomation'
|
40
|
-
require 'watir/dialogs/file_field'
|
41
|
-
require 'watir/dialogs/javascript'
|
42
|
-
|
43
|
-
require 'watir/supported_elements'
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module Watir
|
2
|
-
class FileField < InputElement
|
3
|
-
def set(file_path)
|
4
|
-
assert_file_exists(file_path)
|
5
|
-
assert_exists
|
6
|
-
click_no_wait
|
7
|
-
set_file_name file_path.gsub(File::SEPARATOR, File::ALT_SEPARATOR)
|
8
|
-
open_button.click
|
9
|
-
end
|
10
|
-
|
11
|
-
alias_method :value=, :set
|
12
|
-
|
13
|
-
def assert_file_exists(file_path)
|
14
|
-
raise Errno::ENOENT, "#{file_path} has to exist to set!" unless File.exists?(file_path)
|
15
|
-
end
|
16
|
-
|
17
|
-
def set_file_name(path_to_file)
|
18
|
-
file_upload_window.text_field(:class => 'Edit', :index => 0).set path_to_file
|
19
|
-
end
|
20
|
-
|
21
|
-
def open_button
|
22
|
-
file_upload_window.button(:value => /&Open|&Abrir/)
|
23
|
-
end
|
24
|
-
|
25
|
-
def cancel_button
|
26
|
-
file_upload_window.button(:value => /Cancel/)
|
27
|
-
end
|
28
|
-
|
29
|
-
def file_upload_window
|
30
|
-
@window ||= RAutomation::Window.new(:title => /^choose file( to upload)?|Elegir archivos para cargar$/i)
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
module Watir
|
2
|
-
|
3
|
-
class JavascriptDialog
|
4
|
-
WINDOW_TITLES = ['Message from webpage', 'Windows Internet Explorer','Microsoft Internet Explorer',/Mensaje de p.*/]
|
5
|
-
|
6
|
-
def initialize(opts={})
|
7
|
-
@opts = opts
|
8
|
-
end
|
9
|
-
|
10
|
-
def exists?
|
11
|
-
javascript_dialog_window.exists?
|
12
|
-
end
|
13
|
-
|
14
|
-
def button(value)
|
15
|
-
javascript_dialog_window.button(:value => value)
|
16
|
-
end
|
17
|
-
|
18
|
-
def close
|
19
|
-
javascript_dialog_window.close
|
20
|
-
end
|
21
|
-
|
22
|
-
def text
|
23
|
-
javascript_dialog_window.text
|
24
|
-
end
|
25
|
-
|
26
|
-
def javascript_dialog_window
|
27
|
-
@window ||= ::RAutomation::Window.new(:title => @opts[:title] || /^(#{WINDOW_TITLES.join('|')})$/)
|
28
|
-
end
|
29
|
-
|
30
|
-
Watir::Container.module_eval do
|
31
|
-
def javascript_dialog(opts={})
|
32
|
-
JavascriptDialog.new(opts)
|
33
|
-
end
|
34
|
-
|
35
|
-
alias_method :dialog, :javascript_dialog
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
@@ -1,68 +0,0 @@
|
|
1
|
-
module Watir
|
2
|
-
module DragAndDropHelper
|
3
|
-
|
4
|
-
def drag_and_drop_on(target)
|
5
|
-
perform_action do
|
6
|
-
assert_target target
|
7
|
-
drop_x, drop_y = target.send :source_x_y
|
8
|
-
drag_to drop_x, drop_y
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def drag_and_drop_by(distance_x, distance_y)
|
13
|
-
perform_action do
|
14
|
-
drag_x, drag_y = source_x_y
|
15
|
-
drag_to drag_x + distance_x, drag_y + distance_y
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def drag_to(drop_x, drop_y)
|
22
|
-
drag_x, drag_y = source_x_y
|
23
|
-
mouse = page_container.rautomation.mouse
|
24
|
-
mouse.move :x => drag_x , :y => drag_y
|
25
|
-
mouse.press
|
26
|
-
mouse.move :x => drop_x, :y => drop_y
|
27
|
-
mouse.release
|
28
|
-
end
|
29
|
-
|
30
|
-
def source_x_y
|
31
|
-
center_x_y_absolute left_edge_absolute, top_edge_absolute
|
32
|
-
end
|
33
|
-
|
34
|
-
def assert_target(target)
|
35
|
-
target.assert_exists
|
36
|
-
target.assert_enabled
|
37
|
-
end
|
38
|
-
|
39
|
-
def top_edge
|
40
|
-
ole_object.getBoundingClientRect.top.to_i
|
41
|
-
end
|
42
|
-
|
43
|
-
def top_edge_absolute
|
44
|
-
top_edge + page_container.document.parentWindow.screenTop.to_i
|
45
|
-
end
|
46
|
-
|
47
|
-
def left_edge
|
48
|
-
ole_object.getBoundingClientRect.left.to_i
|
49
|
-
end
|
50
|
-
|
51
|
-
def left_edge_absolute
|
52
|
-
left_edge + page_container.document.parentWindow.screenLeft.to_i
|
53
|
-
end
|
54
|
-
|
55
|
-
def right_edge
|
56
|
-
ole_object.getBoundingClientRect.right.to_i
|
57
|
-
end
|
58
|
-
|
59
|
-
def bottom_edge
|
60
|
-
ole_object.getBoundingClientRect.bottom.to_i
|
61
|
-
end
|
62
|
-
|
63
|
-
def center_x_y_absolute x, y
|
64
|
-
return (right_edge - left_edge) / 2 + x, (bottom_edge - top_edge) / 2 + y
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
end
|
data/lib/watir/element.rb
DELETED
@@ -1,441 +0,0 @@
|
|
1
|
-
module Watir
|
2
|
-
# Base class for html elements.
|
3
|
-
# This is not a class that users would normally access.
|
4
|
-
class Element # Wrapper
|
5
|
-
include Comparable
|
6
|
-
include ElementExtensions
|
7
|
-
include Exception
|
8
|
-
include Container # presumes @container is defined
|
9
|
-
include DragAndDropHelper
|
10
|
-
|
11
|
-
attr_accessor :container
|
12
|
-
|
13
|
-
# number of spaces that separate the property from the value in the to_s method
|
14
|
-
TO_S_SIZE = 14
|
15
|
-
|
16
|
-
def initialize(container, specifiers)
|
17
|
-
set_container container
|
18
|
-
raise ArgumentError, "#{specifiers.inspect} has to be Hash" unless specifiers.is_a?(Hash)
|
19
|
-
|
20
|
-
@o = specifiers[:ole_object]
|
21
|
-
@specifiers = specifiers
|
22
|
-
end
|
23
|
-
|
24
|
-
def <=> other
|
25
|
-
assert_exists
|
26
|
-
other.assert_exists
|
27
|
-
ole_object.sourceindex <=> other.ole_object.sourceindex
|
28
|
-
end
|
29
|
-
|
30
|
-
alias_method :eql?, :==
|
31
|
-
|
32
|
-
def locate
|
33
|
-
@o = @container.locator_for(TaggedElementLocator, @specifiers, self.class).locate
|
34
|
-
end
|
35
|
-
|
36
|
-
# Return the ole object, allowing any methods of the DOM that Watir doesn't support to be used.
|
37
|
-
def ole_object
|
38
|
-
@o
|
39
|
-
end
|
40
|
-
|
41
|
-
def ole_object=(o)
|
42
|
-
@o = o
|
43
|
-
end
|
44
|
-
|
45
|
-
def inspect
|
46
|
-
'#<%s:0x%x located=%s specifiers=%s>' % [self.class, hash*2, !!ole_object, @specifiers.inspect]
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def self.attr_ole(method_name, ole_method_name=nil)
|
52
|
-
class_eval %Q[
|
53
|
-
def #{method_name}
|
54
|
-
assert_exists
|
55
|
-
ole_method_name = '#{ole_method_name || method_name.to_s.gsub(/\?$/, '')}'
|
56
|
-
ole_object.invoke(ole_method_name) rescue attribute_value(ole_method_name) || '' rescue ''
|
57
|
-
end]
|
58
|
-
end
|
59
|
-
|
60
|
-
public
|
61
|
-
|
62
|
-
def assert_exists
|
63
|
-
locate
|
64
|
-
unless ole_object
|
65
|
-
exception_class = self.is_a?(Frame) ? UnknownFrameException : UnknownObjectException
|
66
|
-
raise exception_class.new(Watir::Exception.message_for_unable_to_locate(@specifiers))
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def assert_enabled
|
71
|
-
raise ObjectDisabledException, "object #{@specifiers.inspect} is disabled" unless enabled?
|
72
|
-
end
|
73
|
-
|
74
|
-
# return the id of the element
|
75
|
-
attr_ole :id
|
76
|
-
# return the title of the element
|
77
|
-
attr_ole :title
|
78
|
-
# return the class name of the element
|
79
|
-
# raise an ObjectNotFound exception if the object cannot be found
|
80
|
-
attr_ole :class_name, :className
|
81
|
-
# return the unique COM number for the element
|
82
|
-
attr_ole :unique_number, :uniqueNumber
|
83
|
-
# Return the outer html of the object - see http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/outerhtml.asp?frame=true
|
84
|
-
attr_ole :html, :outerHTML
|
85
|
-
|
86
|
-
def tag_name
|
87
|
-
assert_exists
|
88
|
-
@o.tagName.downcase
|
89
|
-
end
|
90
|
-
|
91
|
-
# returns specific Element subclass for current Element
|
92
|
-
def to_subtype
|
93
|
-
assert_exists
|
94
|
-
|
95
|
-
tag = tag_name
|
96
|
-
if tag == "html"
|
97
|
-
element(:ole_object => ole_object)
|
98
|
-
elsif tag == "input"
|
99
|
-
send(ole_object.invoke('type'), :ole_object => ole_object)
|
100
|
-
elsif tag == "select"
|
101
|
-
select_list(:ole_object => ole_object)
|
102
|
-
elsif respond_to?(tag.downcase)
|
103
|
-
send(tag.downcase, :ole_object => ole_object)
|
104
|
-
else
|
105
|
-
self
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
# send keys to element
|
110
|
-
def send_keys(*keys)
|
111
|
-
focus
|
112
|
-
page_container.send_keys *keys
|
113
|
-
end
|
114
|
-
|
115
|
-
# return the css style as a string
|
116
|
-
def style
|
117
|
-
assert_exists
|
118
|
-
# this works for IE9
|
119
|
-
ole_object.currentStyle.cssText
|
120
|
-
rescue WIN32OLERuntimeError
|
121
|
-
ole_object.style.cssText
|
122
|
-
end
|
123
|
-
|
124
|
-
# Return the innerText of the object or an empty string if the object is
|
125
|
-
# not visible
|
126
|
-
# Raise an ObjectNotFound exception if the object cannot be found
|
127
|
-
def text
|
128
|
-
assert_exists
|
129
|
-
visible? ? ole_object.innerText.strip : ""
|
130
|
-
end
|
131
|
-
|
132
|
-
def __ole_inner_elements
|
133
|
-
assert_exists
|
134
|
-
ole_object.all
|
135
|
-
end
|
136
|
-
|
137
|
-
def document
|
138
|
-
assert_exists
|
139
|
-
ole_object
|
140
|
-
end
|
141
|
-
|
142
|
-
# Return the element immediately containing self.
|
143
|
-
def parent
|
144
|
-
assert_exists
|
145
|
-
parent_element = ole_object.parentelement
|
146
|
-
return unless parent_element
|
147
|
-
Element.new(self, :ole_object => parent_element).to_subtype
|
148
|
-
end
|
149
|
-
|
150
|
-
def typingspeed
|
151
|
-
@container.typingspeed
|
152
|
-
end
|
153
|
-
|
154
|
-
def type_keys
|
155
|
-
@type_keys || @container.type_keys
|
156
|
-
end
|
157
|
-
|
158
|
-
def activeObjectHighLightColor
|
159
|
-
@container.activeObjectHighLightColor
|
160
|
-
end
|
161
|
-
|
162
|
-
# Return an array with many of the properties, in a format to be used by the to_s method
|
163
|
-
def string_creator
|
164
|
-
n = []
|
165
|
-
n << "id:".ljust(TO_S_SIZE) + self.id.to_s
|
166
|
-
return n
|
167
|
-
end
|
168
|
-
|
169
|
-
private :string_creator
|
170
|
-
|
171
|
-
# Display basic details about the object. Sample output for a button is shown.
|
172
|
-
# Raises UnknownObjectException if the object is not found.
|
173
|
-
# name b4
|
174
|
-
# type button
|
175
|
-
# id b5
|
176
|
-
# value Disabled Button
|
177
|
-
# disabled true
|
178
|
-
def to_s
|
179
|
-
assert_exists
|
180
|
-
return string_creator.join("\n")
|
181
|
-
end
|
182
|
-
|
183
|
-
# This method is responsible for setting and clearing the colored highlighting on the currently active element.
|
184
|
-
# use :set to set the highlight
|
185
|
-
# :clear to clear the highlight
|
186
|
-
# TODO: Make this two methods: set_highlight & clear_highlight
|
187
|
-
# TODO: Remove begin/rescue blocks
|
188
|
-
def highlight(set_or_clear)
|
189
|
-
if set_or_clear == :set
|
190
|
-
begin
|
191
|
-
@original_color ||= ole_object.style.backgroundColor
|
192
|
-
ole_object.style.backgroundColor = @container.activeObjectHighLightColor
|
193
|
-
rescue
|
194
|
-
@original_color = nil
|
195
|
-
end
|
196
|
-
else
|
197
|
-
begin
|
198
|
-
ole_object.style.backgroundColor = @original_color if @original_color
|
199
|
-
rescue
|
200
|
-
# we could be here for a number of reasons...
|
201
|
-
# e.g. page may have reloaded and the reference is no longer valid
|
202
|
-
ensure
|
203
|
-
@original_color = nil
|
204
|
-
end
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
private :highlight
|
209
|
-
|
210
|
-
# This method clicks the active element.
|
211
|
-
# raises: UnknownObjectException if the object is not found
|
212
|
-
# ObjectDisabledException if the object is currently disabled
|
213
|
-
def click
|
214
|
-
click!
|
215
|
-
@container.wait
|
216
|
-
end
|
217
|
-
|
218
|
-
def right_click
|
219
|
-
perform_action {fire_event("oncontextmenu"); @container.wait}
|
220
|
-
end
|
221
|
-
|
222
|
-
def double_click
|
223
|
-
perform_action {fire_event("ondblclick"); @container.wait}
|
224
|
-
end
|
225
|
-
|
226
|
-
def replace_method(method)
|
227
|
-
method == 'click' ? 'click!' : method
|
228
|
-
end
|
229
|
-
|
230
|
-
private :replace_method
|
231
|
-
|
232
|
-
def build_method(method_name, *args)
|
233
|
-
arguments = args.map do |argument|
|
234
|
-
if argument.is_a?(String)
|
235
|
-
argument = "'#{argument}'"
|
236
|
-
else
|
237
|
-
argument = argument.inspect
|
238
|
-
end
|
239
|
-
end
|
240
|
-
"#{replace_method(method_name)}(#{arguments.join(',')})"
|
241
|
-
end
|
242
|
-
|
243
|
-
private :build_method
|
244
|
-
|
245
|
-
def generate_ruby_code(element, method_name, *args)
|
246
|
-
# needs to be done like this to avoid segfault on ruby 1.9.3
|
247
|
-
tag_name = @specifiers[:tag_name].join("' << '")
|
248
|
-
element = "#{self.class}.new(#{@page_container.attach_command}, :tag_name => Array.new << '#{tag_name}', :unique_number => #{unique_number})"
|
249
|
-
method = build_method(method_name, *args)
|
250
|
-
ruby_code = "$:.unshift(#{$LOAD_PATH.map {|p| "'#{p}'" }.join(").unshift(")});" <<
|
251
|
-
"require '#{File.expand_path(File.dirname(__FILE__))}/core';#{element}.#{method};"
|
252
|
-
ruby_code
|
253
|
-
end
|
254
|
-
|
255
|
-
private :generate_ruby_code
|
256
|
-
|
257
|
-
def spawned_no_wait_command(command)
|
258
|
-
command = "-e #{command.inspect}"
|
259
|
-
unless $DEBUG
|
260
|
-
"start rubyw #{command}"
|
261
|
-
else
|
262
|
-
puts "#no_wait command:"
|
263
|
-
command = "ruby #{command}"
|
264
|
-
puts command
|
265
|
-
command
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
private :spawned_no_wait_command
|
270
|
-
|
271
|
-
def click!
|
272
|
-
perform_action do
|
273
|
-
# Not sure why but in IE9 Document mode, passing a parameter
|
274
|
-
# to click seems to work. Firing the onClick event breaks other tests
|
275
|
-
# so this seems to be the safest change and also works fine in IE8
|
276
|
-
ole_object.click(0)
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
# Flash the element the specified number of times.
|
281
|
-
# Defaults to 10 flashes.
|
282
|
-
def flash number=10
|
283
|
-
assert_exists
|
284
|
-
number.times do
|
285
|
-
highlight(:set)
|
286
|
-
sleep 0.05
|
287
|
-
highlight(:clear)
|
288
|
-
sleep 0.05
|
289
|
-
end
|
290
|
-
nil
|
291
|
-
end
|
292
|
-
|
293
|
-
# Executes a user defined "fireEvent" for objects with JavaScript events tied to them such as DHTML menus.
|
294
|
-
# usage: allows a generic way to fire javascript events on page objects such as "onMouseOver", "onClick", etc.
|
295
|
-
# raises: UnknownObjectException if the object is not found
|
296
|
-
# ObjectDisabledException if the object is currently disabled
|
297
|
-
def fire_event(event)
|
298
|
-
perform_action {dispatch_event(event); @container.wait}
|
299
|
-
end
|
300
|
-
|
301
|
-
def dispatch_event(event)
|
302
|
-
assert_exists
|
303
|
-
|
304
|
-
if IE.version_parts.first.to_i >= 9 && container.page_container.document.documentMode.to_i >= 9
|
305
|
-
ole_object.dispatchEvent(create_event(event))
|
306
|
-
else
|
307
|
-
ole_object.fireEvent(event)
|
308
|
-
end
|
309
|
-
end
|
310
|
-
|
311
|
-
def create_event(event)
|
312
|
-
event =~ /on(.*)/i
|
313
|
-
event = $1 if $1
|
314
|
-
event.downcase!
|
315
|
-
# See http://www.howtocreate.co.uk/tutorials/javascript/domevents
|
316
|
-
case event
|
317
|
-
when 'abort', 'blur', 'change', 'error', 'focus', 'load',
|
318
|
-
'reset', 'resize', 'scroll', 'select', 'submit', 'unload'
|
319
|
-
event_name = :initEvent
|
320
|
-
event_type = 'HTMLEvents'
|
321
|
-
event_args = [event, true, true]
|
322
|
-
when 'select'
|
323
|
-
event_name = :initUIEvent
|
324
|
-
event_type = 'UIEvent'
|
325
|
-
event_args = [event, true, true, @container.page_container.document.parentWindow.window,0]
|
326
|
-
when 'keydown', 'keypress', 'keyup'
|
327
|
-
event_name = :initKeyboardEvent
|
328
|
-
event_type = 'KeyboardEvent'
|
329
|
-
# 'type', bubbles, cancelable, windowObject, ctrlKey, altKey, shiftKey, metaKey, keyCode, charCode
|
330
|
-
event_args = [event, true, true, @container.page_container.document.parentWindow.window, false, false, false, false, 0, 0]
|
331
|
-
when 'click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup',
|
332
|
-
'contextmenu', 'drag', 'dragstart', 'dragenter', 'dragover', 'dragleave', 'dragend', 'drop', 'selectstart'
|
333
|
-
event_name = :initMouseEvent
|
334
|
-
event_type = 'MouseEvents'
|
335
|
-
# 'type', bubbles, cancelable, windowObject, detail, screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget
|
336
|
-
event_args = [event, true, true, @container.page_container.document.parentWindow.window, 1, 0, 0, 0, 0, false, false, false, false, 0, @container.page_container.document]
|
337
|
-
else
|
338
|
-
raise UnhandledEventException, "Don't know how to trigger event '#{event}'"
|
339
|
-
end
|
340
|
-
event = @container.page_container.document.createEvent(event_type)
|
341
|
-
event.send event_name, *event_args
|
342
|
-
event
|
343
|
-
end
|
344
|
-
|
345
|
-
# This method sets focus on the active element.
|
346
|
-
# raises: UnknownObjectException if the object is not found
|
347
|
-
# ObjectDisabledException if the object is currently disabled
|
348
|
-
def focus
|
349
|
-
assert_exists
|
350
|
-
assert_enabled
|
351
|
-
@page_container.focus
|
352
|
-
ole_object.focus(0)
|
353
|
-
end
|
354
|
-
|
355
|
-
def focused?
|
356
|
-
assert_exists
|
357
|
-
assert_enabled
|
358
|
-
@page_container.document.activeElement.uniqueNumber == unique_number
|
359
|
-
end
|
360
|
-
|
361
|
-
# Returns whether this element actually exists.
|
362
|
-
def exists?
|
363
|
-
begin
|
364
|
-
locate
|
365
|
-
rescue WIN32OLERuntimeError, UnknownObjectException
|
366
|
-
@o = nil
|
367
|
-
end
|
368
|
-
!!@o
|
369
|
-
end
|
370
|
-
|
371
|
-
alias :exist? :exists?
|
372
|
-
|
373
|
-
# Returns true if the element is enabled, false if it isn't.
|
374
|
-
# raises: UnknownObjectException if the object is not found
|
375
|
-
def enabled?
|
376
|
-
assert_exists
|
377
|
-
!disabled?
|
378
|
-
end
|
379
|
-
|
380
|
-
def disabled?
|
381
|
-
assert_exists
|
382
|
-
false
|
383
|
-
end
|
384
|
-
|
385
|
-
# If any parent element isn't visible then we cannot write to the
|
386
|
-
# element. The only realiable way to determine this is to iterate
|
387
|
-
# up the DOM element tree checking every element to make sure it's
|
388
|
-
# visible.
|
389
|
-
def visible?
|
390
|
-
# Now iterate up the DOM element tree and return false if any
|
391
|
-
# parent element isn't visible
|
392
|
-
assert_exists
|
393
|
-
object = @o
|
394
|
-
while object
|
395
|
-
begin
|
396
|
-
if object.currentstyle.invoke('visibility') =~ /^hidden$/i
|
397
|
-
return false
|
398
|
-
end
|
399
|
-
if object.currentstyle.invoke('display') =~ /^none$/i
|
400
|
-
return false
|
401
|
-
end
|
402
|
-
rescue WIN32OLERuntimeError
|
403
|
-
end
|
404
|
-
object = object.parentElement
|
405
|
-
end
|
406
|
-
true
|
407
|
-
end
|
408
|
-
|
409
|
-
# Get attribute value for any attribute of the element.
|
410
|
-
# Returns null if attribute doesn't exist.
|
411
|
-
def attribute_value(attribute_name)
|
412
|
-
assert_exists
|
413
|
-
ole_object.getAttribute(attribute_name)
|
414
|
-
end
|
415
|
-
|
416
|
-
def perform_action
|
417
|
-
assert_exists
|
418
|
-
assert_enabled
|
419
|
-
highlight(:set)
|
420
|
-
yield
|
421
|
-
highlight(:clear)
|
422
|
-
end
|
423
|
-
|
424
|
-
private :perform_action
|
425
|
-
|
426
|
-
def method_missing(method_name, *args, &block)
|
427
|
-
meth = method_name.to_s
|
428
|
-
if meth =~ /(.*)_no_wait/ && self.respond_to?($1)
|
429
|
-
perform_action do
|
430
|
-
ruby_code = generate_ruby_code(self, $1, *args)
|
431
|
-
system(spawned_no_wait_command(ruby_code))
|
432
|
-
end
|
433
|
-
elsif meth =~ /^data_(.*)/
|
434
|
-
self.send(:attribute_value, meth.gsub("_", "-")) || ''
|
435
|
-
else
|
436
|
-
super
|
437
|
-
end
|
438
|
-
end
|
439
|
-
|
440
|
-
end
|
441
|
-
end
|