firewatir 1.6.5 → 1.6.6.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +461 -0
- data/LICENSE +31 -31
- data/README.rdoc +112 -0
- data/VERSION +1 -0
- data/lib/firewatir.rb +41 -40
- data/lib/firewatir/container.rb +491 -491
- data/lib/firewatir/document.rb +239 -239
- data/lib/firewatir/element.rb +1364 -1364
- data/lib/firewatir/element_collections.rb +314 -314
- data/lib/firewatir/elements/button.rb +15 -15
- data/lib/firewatir/elements/file_field.rb +29 -29
- data/lib/firewatir/elements/form.rb +40 -40
- data/lib/firewatir/elements/frame.rb +55 -55
- data/lib/firewatir/elements/hidden.rb +56 -56
- data/lib/firewatir/elements/image.rb +139 -139
- data/lib/firewatir/elements/input_element.rb +44 -44
- data/lib/firewatir/elements/link.rb +76 -76
- data/lib/firewatir/elements/non_control_element.rb +53 -53
- data/lib/firewatir/elements/non_control_elements.rb +108 -108
- data/lib/firewatir/elements/not_used.rb +278 -278
- data/lib/firewatir/elements/option.rb +130 -130
- data/lib/firewatir/elements/radio_check_common.rb +163 -163
- data/lib/firewatir/elements/select_list.rb +188 -188
- data/lib/firewatir/elements/table.rb +218 -218
- data/lib/firewatir/elements/table_cell.rb +54 -54
- data/lib/firewatir/elements/table_row.rb +100 -100
- data/lib/firewatir/elements/text_field.rb +218 -218
- data/lib/firewatir/exceptions.rb +10 -10
- data/lib/firewatir/firefox.rb +984 -1040
- data/lib/firewatir/jssh_socket.rb +100 -100
- data/lib/firewatir/winClicker.rb +122 -122
- data/lib/firewatir/x11.rb +192 -192
- data/rakefile.rb +15 -0
- data/unittests/attach_to_new_window_test.rb +49 -49
- data/unittests/bug_fixes_test.rb +195 -195
- data/unittests/buttons_xpath_test.rb +88 -88
- data/unittests/checkbox_test.rb +158 -158
- data/unittests/checkbox_xpath_test.rb +107 -107
- data/unittests/div_test.rb +275 -275
- data/unittests/ff_test.rb +47 -0
- data/unittests/filefield_test.rb +49 -49
- data/unittests/filefield_xpath_test.rb +35 -35
- data/unittests/form_test.rb +296 -296
- data/unittests/frame_test.rb +159 -159
- data/unittests/hidden_test.rb +85 -85
- data/unittests/hidden_xpath_test.rb +72 -72
- data/unittests/html/JavascriptClick.html +42 -42
- data/unittests/html/blankpage.html +11 -11
- data/unittests/html/buttons1.html +61 -61
- data/unittests/html/checkboxes1.html +70 -70
- data/unittests/html/complex_table.html +36 -36
- data/unittests/html/cssTest.html +42 -42
- data/unittests/html/div.html +72 -72
- data/unittests/html/div_xml.html +20 -20
- data/unittests/html/fileupload.html +45 -45
- data/unittests/html/formTest1.html +38 -38
- data/unittests/html/forms2.html +45 -45
- data/unittests/html/forms3.html +132 -132
- data/unittests/html/forms4.html +27 -27
- data/unittests/html/frame_buttons.html +3 -3
- data/unittests/html/frame_links.html +3 -3
- data/unittests/html/frame_multi.html +4 -4
- data/unittests/html/iframeTest.html +14 -14
- data/unittests/html/iframeTest1.html +13 -13
- data/unittests/html/iframeTest2.html +5 -5
- data/unittests/html/images1.html +66 -66
- data/unittests/html/javascriptevents.html +35 -35
- data/unittests/html/link_pass.html +10 -10
- data/unittests/html/links1.html +42 -42
- data/unittests/html/links2.html +10 -10
- data/unittests/html/modal_dialog.html +8 -8
- data/unittests/html/modal_dialog_launcher.html +11 -11
- data/unittests/html/nestedFrames.html +6 -6
- data/unittests/html/new_browser.html +17 -17
- data/unittests/html/new_browser_popup.html +7 -7
- data/unittests/html/pass.html +9 -9
- data/unittests/html/popups1.html +60 -60
- data/unittests/html/pre.html +27 -27
- data/unittests/html/radioButtons1.html +70 -70
- data/unittests/html/redirect.html +10 -10
- data/unittests/html/redirect1.html +8 -8
- data/unittests/html/redirect2.html +8 -8
- data/unittests/html/redirect3.html +8 -8
- data/unittests/html/select_tealeaf.html +54 -54
- data/unittests/html/selectboxes1.html +55 -55
- data/unittests/html/simple_table.html +26 -26
- data/unittests/html/simple_table_buttons.html +104 -104
- data/unittests/html/simple_table_columns.html +74 -74
- data/unittests/html/table1.html +165 -165
- data/unittests/html/tableCell_using_xpath.html +19 -19
- data/unittests/html/textarea.html +30 -30
- data/unittests/html/textfields1.html +62 -62
- data/unittests/html/textsearch.html +44 -44
- data/unittests/images_test.rb +198 -198
- data/unittests/images_xpath_test.rb +118 -118
- data/unittests/javascript_test.rb +75 -75
- data/unittests/links_test.rb +231 -231
- data/unittests/links_xpath_test.rb +79 -79
- data/unittests/mozilla_all_tests.rb +7 -7
- data/unittests/pre_test.rb +75 -75
- data/unittests/radios_test.rb +166 -166
- data/unittests/radios_xpath_test.rb +101 -101
- data/unittests/redirect_test.rb +41 -41
- data/unittests/selectbox_test.rb +142 -142
- data/unittests/selectbox_xpath_test.rb +129 -129
- data/unittests/setup.rb +29 -29
- data/unittests/table_test.rb +385 -385
- data/unittests/table_xpath_test.rb +185 -185
- data/unittests/textfields_test.rb +234 -234
- data/unittests/textfields_xpath_test.rb +113 -113
- metadata +51 -19
- data/lib/firewatir/version.rb +0 -5
@@ -1,54 +1,54 @@
|
|
1
|
-
module FireWatir
|
2
|
-
#
|
3
|
-
# Description:
|
4
|
-
# Class for Table Cell.
|
5
|
-
#
|
6
|
-
class TableCell < Element
|
7
|
-
attr_accessor :element_name
|
8
|
-
|
9
|
-
# Description:
|
10
|
-
# Locate the table cell element on the page.
|
11
|
-
#
|
12
|
-
def locate
|
13
|
-
case @how
|
14
|
-
when :jssh_name
|
15
|
-
@element_name = @what
|
16
|
-
when :xpath
|
17
|
-
@element_name = element_by_xpath(@container, @what)
|
18
|
-
else
|
19
|
-
@element_name = locate_tagged_element("TD", @how, @what)
|
20
|
-
end
|
21
|
-
@o = self
|
22
|
-
end
|
23
|
-
|
24
|
-
#
|
25
|
-
# Description:
|
26
|
-
# Initializes the instance of table cell object.
|
27
|
-
#
|
28
|
-
# Input:
|
29
|
-
# - how - Attribute to identify the table cell element.
|
30
|
-
# - what - Value of that attribute.
|
31
|
-
#
|
32
|
-
def initialize(container, how, what)
|
33
|
-
@how = how
|
34
|
-
@what = what
|
35
|
-
@container = container
|
36
|
-
#super nil
|
37
|
-
end
|
38
|
-
|
39
|
-
alias to_s text
|
40
|
-
|
41
|
-
#
|
42
|
-
# Description:
|
43
|
-
# Gets the col span of table cell.
|
44
|
-
#
|
45
|
-
# Output:
|
46
|
-
# Colspan of table cell.
|
47
|
-
#
|
48
|
-
def colspan
|
49
|
-
assert_exists
|
50
|
-
@o.colSpan
|
51
|
-
end
|
52
|
-
|
53
|
-
end # TableCell
|
54
|
-
end # FireWatir
|
1
|
+
module FireWatir
|
2
|
+
#
|
3
|
+
# Description:
|
4
|
+
# Class for Table Cell.
|
5
|
+
#
|
6
|
+
class TableCell < Element
|
7
|
+
attr_accessor :element_name
|
8
|
+
|
9
|
+
# Description:
|
10
|
+
# Locate the table cell element on the page.
|
11
|
+
#
|
12
|
+
def locate
|
13
|
+
case @how
|
14
|
+
when :jssh_name
|
15
|
+
@element_name = @what
|
16
|
+
when :xpath
|
17
|
+
@element_name = element_by_xpath(@container, @what)
|
18
|
+
else
|
19
|
+
@element_name = locate_tagged_element("TD", @how, @what)
|
20
|
+
end
|
21
|
+
@o = self
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# Description:
|
26
|
+
# Initializes the instance of table cell object.
|
27
|
+
#
|
28
|
+
# Input:
|
29
|
+
# - how - Attribute to identify the table cell element.
|
30
|
+
# - what - Value of that attribute.
|
31
|
+
#
|
32
|
+
def initialize(container, how, what)
|
33
|
+
@how = how
|
34
|
+
@what = what
|
35
|
+
@container = container
|
36
|
+
#super nil
|
37
|
+
end
|
38
|
+
|
39
|
+
alias to_s text
|
40
|
+
|
41
|
+
#
|
42
|
+
# Description:
|
43
|
+
# Gets the col span of table cell.
|
44
|
+
#
|
45
|
+
# Output:
|
46
|
+
# Colspan of table cell.
|
47
|
+
#
|
48
|
+
def colspan
|
49
|
+
assert_exists
|
50
|
+
@o.colSpan
|
51
|
+
end
|
52
|
+
|
53
|
+
end # TableCell
|
54
|
+
end # FireWatir
|
@@ -1,100 +1,100 @@
|
|
1
|
-
module FireWatir
|
2
|
-
#
|
3
|
-
# Description:
|
4
|
-
# Class for Table row element.
|
5
|
-
#
|
6
|
-
class TableRow < Element
|
7
|
-
attr_accessor :element_name
|
8
|
-
|
9
|
-
#
|
10
|
-
# Description:
|
11
|
-
# Locate the table row element on the page.
|
12
|
-
#
|
13
|
-
def locate
|
14
|
-
@o = nil
|
15
|
-
case @how
|
16
|
-
when :jssh_name
|
17
|
-
@element_name = @what
|
18
|
-
when :xpath
|
19
|
-
@element_name = element_by_xpath(@container, @what)
|
20
|
-
else
|
21
|
-
@element_name = locate_tagged_element("TR", @how, @what)
|
22
|
-
end
|
23
|
-
@o = self
|
24
|
-
end
|
25
|
-
|
26
|
-
#
|
27
|
-
# Description:
|
28
|
-
# Initializes the instance of table row object.
|
29
|
-
#
|
30
|
-
# Input:
|
31
|
-
# - how - Attribute to identify the table row element.
|
32
|
-
# - what - Value of that attribute.
|
33
|
-
#
|
34
|
-
def initialize(container, how, what)
|
35
|
-
@how = how
|
36
|
-
@what = what
|
37
|
-
@container = container
|
38
|
-
#super nil
|
39
|
-
end
|
40
|
-
|
41
|
-
#
|
42
|
-
# Description:
|
43
|
-
# Gets the length of columns in table row.
|
44
|
-
#
|
45
|
-
# Output:
|
46
|
-
# Length of columns in table row.
|
47
|
-
#
|
48
|
-
def column_count
|
49
|
-
assert_exists
|
50
|
-
arr_cells = cells
|
51
|
-
return arr_cells.length
|
52
|
-
end
|
53
|
-
|
54
|
-
#
|
55
|
-
# Description:
|
56
|
-
# Get cell at specified index in a row.
|
57
|
-
#
|
58
|
-
# Input:
|
59
|
-
# key - column index.
|
60
|
-
#
|
61
|
-
# Output:
|
62
|
-
# Table cell element at specified index.
|
63
|
-
#
|
64
|
-
def [] (key)
|
65
|
-
assert_exists
|
66
|
-
arr_cells = cells
|
67
|
-
return arr_cells[key - 1]
|
68
|
-
end
|
69
|
-
|
70
|
-
#
|
71
|
-
# Description:
|
72
|
-
# Iterate over each cell in a row.
|
73
|
-
#
|
74
|
-
def each
|
75
|
-
assert_exists
|
76
|
-
arr_cells = cells
|
77
|
-
for i in 0..arr_cells.length - 1 do
|
78
|
-
yield arr_cells[i]
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
#
|
83
|
-
# Description:
|
84
|
-
# Get array of all cells in Table Row
|
85
|
-
#
|
86
|
-
# Output:
|
87
|
-
# Array containing Table Cell elements.
|
88
|
-
#
|
89
|
-
def cells
|
90
|
-
assert_exists
|
91
|
-
arr_cells = get_cells
|
92
|
-
row_cells = Array.new(arr_cells.length)
|
93
|
-
for i in 0..arr_cells.length - 1 do
|
94
|
-
row_cells[i] = TableCell.new(@container, :jssh_name, arr_cells[i])
|
95
|
-
end
|
96
|
-
return row_cells
|
97
|
-
end
|
98
|
-
|
99
|
-
end # TableRow
|
100
|
-
end # FireWatir
|
1
|
+
module FireWatir
|
2
|
+
#
|
3
|
+
# Description:
|
4
|
+
# Class for Table row element.
|
5
|
+
#
|
6
|
+
class TableRow < Element
|
7
|
+
attr_accessor :element_name
|
8
|
+
|
9
|
+
#
|
10
|
+
# Description:
|
11
|
+
# Locate the table row element on the page.
|
12
|
+
#
|
13
|
+
def locate
|
14
|
+
@o = nil
|
15
|
+
case @how
|
16
|
+
when :jssh_name
|
17
|
+
@element_name = @what
|
18
|
+
when :xpath
|
19
|
+
@element_name = element_by_xpath(@container, @what)
|
20
|
+
else
|
21
|
+
@element_name = locate_tagged_element("TR", @how, @what)
|
22
|
+
end
|
23
|
+
@o = self
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# Description:
|
28
|
+
# Initializes the instance of table row object.
|
29
|
+
#
|
30
|
+
# Input:
|
31
|
+
# - how - Attribute to identify the table row element.
|
32
|
+
# - what - Value of that attribute.
|
33
|
+
#
|
34
|
+
def initialize(container, how, what)
|
35
|
+
@how = how
|
36
|
+
@what = what
|
37
|
+
@container = container
|
38
|
+
#super nil
|
39
|
+
end
|
40
|
+
|
41
|
+
#
|
42
|
+
# Description:
|
43
|
+
# Gets the length of columns in table row.
|
44
|
+
#
|
45
|
+
# Output:
|
46
|
+
# Length of columns in table row.
|
47
|
+
#
|
48
|
+
def column_count
|
49
|
+
assert_exists
|
50
|
+
arr_cells = cells
|
51
|
+
return arr_cells.length
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# Description:
|
56
|
+
# Get cell at specified index in a row.
|
57
|
+
#
|
58
|
+
# Input:
|
59
|
+
# key - column index.
|
60
|
+
#
|
61
|
+
# Output:
|
62
|
+
# Table cell element at specified index.
|
63
|
+
#
|
64
|
+
def [] (key)
|
65
|
+
assert_exists
|
66
|
+
arr_cells = cells
|
67
|
+
return arr_cells[key - 1]
|
68
|
+
end
|
69
|
+
|
70
|
+
#
|
71
|
+
# Description:
|
72
|
+
# Iterate over each cell in a row.
|
73
|
+
#
|
74
|
+
def each
|
75
|
+
assert_exists
|
76
|
+
arr_cells = cells
|
77
|
+
for i in 0..arr_cells.length - 1 do
|
78
|
+
yield arr_cells[i]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
#
|
83
|
+
# Description:
|
84
|
+
# Get array of all cells in Table Row
|
85
|
+
#
|
86
|
+
# Output:
|
87
|
+
# Array containing Table Cell elements.
|
88
|
+
#
|
89
|
+
def cells
|
90
|
+
assert_exists
|
91
|
+
arr_cells = get_cells
|
92
|
+
row_cells = Array.new(arr_cells.length)
|
93
|
+
for i in 0..arr_cells.length - 1 do
|
94
|
+
row_cells[i] = TableCell.new(@container, :jssh_name, arr_cells[i])
|
95
|
+
end
|
96
|
+
return row_cells
|
97
|
+
end
|
98
|
+
|
99
|
+
end # TableRow
|
100
|
+
end # FireWatir
|
@@ -1,218 +1,218 @@
|
|
1
|
-
module FireWatir
|
2
|
-
#
|
3
|
-
# Description:
|
4
|
-
# Class for Text Field element.
|
5
|
-
#
|
6
|
-
class TextField < InputElement
|
7
|
-
INPUT_TYPES = ["text", "password", "textarea"]
|
8
|
-
|
9
|
-
# Gets the size of the text field element.
|
10
|
-
def_wrap :size
|
11
|
-
# Gets max length of the text field element.
|
12
|
-
def_wrap :maxlength_string, :maxlength
|
13
|
-
def maxlength
|
14
|
-
maxlength_string.to_i
|
15
|
-
end
|
16
|
-
# Returns true if the text field is read only, false otherwise.
|
17
|
-
def_wrap :readonly?, :readOnly
|
18
|
-
|
19
|
-
#
|
20
|
-
# Description:
|
21
|
-
# Used to populate the properties in to_s method
|
22
|
-
#
|
23
|
-
#def text_string_creator
|
24
|
-
# n = []
|
25
|
-
# n << "length:".ljust(TO_S_SIZE) + self.size.to_s
|
26
|
-
# n << "max length:".ljust(TO_S_SIZE) + self.maxlength.to_s
|
27
|
-
# n << "read only:".ljust(TO_S_SIZE) + self.readonly?.to_s
|
28
|
-
#
|
29
|
-
# return n
|
30
|
-
#end
|
31
|
-
#private :text_string_creator
|
32
|
-
|
33
|
-
# TODO: Impelement the to_s method.
|
34
|
-
def to_s
|
35
|
-
assert_exists
|
36
|
-
super({"length" => "size","max length" => "maxlength","read only" => "readOnly" })
|
37
|
-
end
|
38
|
-
|
39
|
-
#
|
40
|
-
# Description:
|
41
|
-
# Checks if object is read-only or not.
|
42
|
-
#
|
43
|
-
def assert_not_readonly
|
44
|
-
raise ObjectReadOnlyException, "Textfield #{@how} and #{@what} is read only." if self.readonly?
|
45
|
-
end
|
46
|
-
|
47
|
-
#
|
48
|
-
# Description:
|
49
|
-
# Checks if the provided text matches with the contents of text field. Text can be a string or regular expression.
|
50
|
-
#
|
51
|
-
# Input:
|
52
|
-
# - containsThis - Text to verify.
|
53
|
-
#
|
54
|
-
# Output:
|
55
|
-
# True if provided text matches with the contents of text field, false otherwise.
|
56
|
-
#
|
57
|
-
def verify_contains( containsThis )
|
58
|
-
assert_exists
|
59
|
-
if containsThis.kind_of? String
|
60
|
-
return true if self.value == containsThis
|
61
|
-
elsif containsThis.kind_of? Regexp
|
62
|
-
return true if self.value.match(containsThis) != nil
|
63
|
-
end
|
64
|
-
return false
|
65
|
-
end
|
66
|
-
|
67
|
-
# this method is used to drag the entire contents of the text field to another text field
|
68
|
-
# 19 Jan 2005 - It is added as prototype functionality, and may change
|
69
|
-
# * destination_how - symbol, :id, :name how we identify the drop target
|
70
|
-
# * destination_what - string or regular expression, the name, id, etc of the text field that will be the drop target
|
71
|
-
# TODO: Can we have support for this in Firefox.
|
72
|
-
#def drag_contents_to( destination_how , destination_what)
|
73
|
-
# assert_exists
|
74
|
-
# destination = element.text_field(destination_how, destination_what)
|
75
|
-
# raise UnknownObjectException , "Unable to locate destination using #{destination_how } and #{destination_what } " if destination.exists? == false
|
76
|
-
|
77
|
-
# @o.focus
|
78
|
-
# @o.select()
|
79
|
-
# value = self.value
|
80
|
-
|
81
|
-
# @o.fireEvent("onSelect")
|
82
|
-
# @o.fireEvent("ondragstart")
|
83
|
-
# @o.fireEvent("ondrag")
|
84
|
-
# destination.fireEvent("onDragEnter")
|
85
|
-
# destination.fireEvent("onDragOver")
|
86
|
-
# destination.fireEvent("ondrop")
|
87
|
-
|
88
|
-
# @o.fireEvent("ondragend")
|
89
|
-
# destination.value= ( destination.value + value.to_s )
|
90
|
-
# self.value = ""
|
91
|
-
#end
|
92
|
-
# alias dragContentsTo drag_contents_to
|
93
|
-
|
94
|
-
#
|
95
|
-
# Description:
|
96
|
-
# Clears the contents of the text field.
|
97
|
-
# Raises ObjectDisabledException if text field is disabled.
|
98
|
-
# Raises ObjectReadOnlyException if text field is read only.
|
99
|
-
#
|
100
|
-
def clear
|
101
|
-
assert_exists
|
102
|
-
assert_enabled
|
103
|
-
assert_not_readonly
|
104
|
-
|
105
|
-
highlight(:set)
|
106
|
-
|
107
|
-
@o.scrollIntoView
|
108
|
-
@o.focus
|
109
|
-
@o.select()
|
110
|
-
@o.fireEvent("onSelect")
|
111
|
-
@o.value = ""
|
112
|
-
@o.fireEvent("onKeyPress")
|
113
|
-
@o.fireEvent("onChange")
|
114
|
-
@container.wait()
|
115
|
-
highlight(:clear)
|
116
|
-
end
|
117
|
-
|
118
|
-
#
|
119
|
-
# Description:
|
120
|
-
# Append the provided text to the contents of the text field.
|
121
|
-
# Raises ObjectDisabledException if text field is disabled.
|
122
|
-
# Raises ObjectReadOnlyException if text field is read only.
|
123
|
-
#
|
124
|
-
# Input:
|
125
|
-
# - setThis - Text to be appended.
|
126
|
-
#
|
127
|
-
def append( setThis)
|
128
|
-
assert_exists
|
129
|
-
assert_enabled
|
130
|
-
assert_not_readonly
|
131
|
-
|
132
|
-
highlight(:set)
|
133
|
-
@o.scrollIntoView
|
134
|
-
@o.focus
|
135
|
-
doKeyPress( setThis )
|
136
|
-
highlight(:clear)
|
137
|
-
end
|
138
|
-
|
139
|
-
#
|
140
|
-
# Description:
|
141
|
-
# Sets the contents of the text field to the provided text. Overwrite the existing contents.
|
142
|
-
# Raises ObjectDisabledException if text field is disabled.
|
143
|
-
# Raises ObjectReadOnlyException if text field is read only.
|
144
|
-
#
|
145
|
-
# Input:
|
146
|
-
# - setThis - Text to be set.
|
147
|
-
#
|
148
|
-
def set( setThis )
|
149
|
-
assert_exists
|
150
|
-
assert_enabled
|
151
|
-
assert_not_readonly
|
152
|
-
|
153
|
-
highlight(:set)
|
154
|
-
@o.scrollIntoView
|
155
|
-
@o.focus
|
156
|
-
@o.select()
|
157
|
-
@o.fireEvent("onSelect")
|
158
|
-
@o.value = ""
|
159
|
-
@o.fireEvent("onKeyPress")
|
160
|
-
doKeyPress( setThis )
|
161
|
-
highlight(:clear)
|
162
|
-
@o.fireEvent("onChange")
|
163
|
-
@o.fireEvent("onBlur")
|
164
|
-
end
|
165
|
-
|
166
|
-
#
|
167
|
-
# Description:
|
168
|
-
# Sets the text of the text field withoud firing the events like onKeyPress, onKeyDown etc. This should not be used generally, but it
|
169
|
-
# is useful in situations where you need to set large text to the text field and you know that you don't have any event to be
|
170
|
-
# fired.
|
171
|
-
#
|
172
|
-
# Input:
|
173
|
-
# - v - Text to be set.
|
174
|
-
#
|
175
|
-
#def value=(v)
|
176
|
-
# assert_exists
|
177
|
-
# @o.value = v.to_s
|
178
|
-
#end
|
179
|
-
|
180
|
-
#
|
181
|
-
# Description:
|
182
|
-
# Used to set the value of text box and fires the event onKeyPress, onKeyDown, onKeyUp after each character.
|
183
|
-
# Shouldnot be used externally. Used internally by set and append methods.
|
184
|
-
#
|
185
|
-
# Input:
|
186
|
-
# - value - The string to enter into the text field
|
187
|
-
#
|
188
|
-
def doKeyPress( value )
|
189
|
-
begin
|
190
|
-
max = maxlength
|
191
|
-
if (max > 0 && value.length > max)
|
192
|
-
original_value = value
|
193
|
-
value = original_value[0...max]
|
194
|
-
element.log " Supplied string is #{suppliedValue.length} chars, which exceeds the max length (#{max}) of the field. Using value: #{value}"
|
195
|
-
end
|
196
|
-
rescue
|
197
|
-
# probably a text area - so it doesnt have a max Length
|
198
|
-
end
|
199
|
-
for i in 0..value.length-1
|
200
|
-
#sleep element.typingspeed # typing speed
|
201
|
-
c = value[i,1]
|
202
|
-
#element.log " adding c.chr " + c #.chr.to_s
|
203
|
-
@o.value = "#{(@o.value.to_s + c)}" #c.chr
|
204
|
-
@o.fireEvent("onKeyDown")
|
205
|
-
@o.fireEvent("onKeyPress")
|
206
|
-
@o.fireEvent("onKeyUp")
|
207
|
-
end
|
208
|
-
|
209
|
-
end
|
210
|
-
private :doKeyPress
|
211
|
-
|
212
|
-
alias readOnly? :readonly?
|
213
|
-
alias getContents value
|
214
|
-
alias maxLength maxlength
|
215
|
-
|
216
|
-
end # TextField
|
217
|
-
end # FireWatir
|
218
|
-
|
1
|
+
module FireWatir
|
2
|
+
#
|
3
|
+
# Description:
|
4
|
+
# Class for Text Field element.
|
5
|
+
#
|
6
|
+
class TextField < InputElement
|
7
|
+
INPUT_TYPES = ["text", "password", "textarea"]
|
8
|
+
|
9
|
+
# Gets the size of the text field element.
|
10
|
+
def_wrap :size
|
11
|
+
# Gets max length of the text field element.
|
12
|
+
def_wrap :maxlength_string, :maxlength
|
13
|
+
def maxlength
|
14
|
+
maxlength_string.to_i
|
15
|
+
end
|
16
|
+
# Returns true if the text field is read only, false otherwise.
|
17
|
+
def_wrap :readonly?, :readOnly
|
18
|
+
|
19
|
+
#
|
20
|
+
# Description:
|
21
|
+
# Used to populate the properties in to_s method
|
22
|
+
#
|
23
|
+
#def text_string_creator
|
24
|
+
# n = []
|
25
|
+
# n << "length:".ljust(TO_S_SIZE) + self.size.to_s
|
26
|
+
# n << "max length:".ljust(TO_S_SIZE) + self.maxlength.to_s
|
27
|
+
# n << "read only:".ljust(TO_S_SIZE) + self.readonly?.to_s
|
28
|
+
#
|
29
|
+
# return n
|
30
|
+
#end
|
31
|
+
#private :text_string_creator
|
32
|
+
|
33
|
+
# TODO: Impelement the to_s method.
|
34
|
+
def to_s
|
35
|
+
assert_exists
|
36
|
+
super({"length" => "size","max length" => "maxlength","read only" => "readOnly" })
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# Description:
|
41
|
+
# Checks if object is read-only or not.
|
42
|
+
#
|
43
|
+
def assert_not_readonly
|
44
|
+
raise ObjectReadOnlyException, "Textfield #{@how} and #{@what} is read only." if self.readonly?
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Description:
|
49
|
+
# Checks if the provided text matches with the contents of text field. Text can be a string or regular expression.
|
50
|
+
#
|
51
|
+
# Input:
|
52
|
+
# - containsThis - Text to verify.
|
53
|
+
#
|
54
|
+
# Output:
|
55
|
+
# True if provided text matches with the contents of text field, false otherwise.
|
56
|
+
#
|
57
|
+
def verify_contains( containsThis )
|
58
|
+
assert_exists
|
59
|
+
if containsThis.kind_of? String
|
60
|
+
return true if self.value == containsThis
|
61
|
+
elsif containsThis.kind_of? Regexp
|
62
|
+
return true if self.value.match(containsThis) != nil
|
63
|
+
end
|
64
|
+
return false
|
65
|
+
end
|
66
|
+
|
67
|
+
# this method is used to drag the entire contents of the text field to another text field
|
68
|
+
# 19 Jan 2005 - It is added as prototype functionality, and may change
|
69
|
+
# * destination_how - symbol, :id, :name how we identify the drop target
|
70
|
+
# * destination_what - string or regular expression, the name, id, etc of the text field that will be the drop target
|
71
|
+
# TODO: Can we have support for this in Firefox.
|
72
|
+
#def drag_contents_to( destination_how , destination_what)
|
73
|
+
# assert_exists
|
74
|
+
# destination = element.text_field(destination_how, destination_what)
|
75
|
+
# raise UnknownObjectException , "Unable to locate destination using #{destination_how } and #{destination_what } " if destination.exists? == false
|
76
|
+
|
77
|
+
# @o.focus
|
78
|
+
# @o.select()
|
79
|
+
# value = self.value
|
80
|
+
|
81
|
+
# @o.fireEvent("onSelect")
|
82
|
+
# @o.fireEvent("ondragstart")
|
83
|
+
# @o.fireEvent("ondrag")
|
84
|
+
# destination.fireEvent("onDragEnter")
|
85
|
+
# destination.fireEvent("onDragOver")
|
86
|
+
# destination.fireEvent("ondrop")
|
87
|
+
|
88
|
+
# @o.fireEvent("ondragend")
|
89
|
+
# destination.value= ( destination.value + value.to_s )
|
90
|
+
# self.value = ""
|
91
|
+
#end
|
92
|
+
# alias dragContentsTo drag_contents_to
|
93
|
+
|
94
|
+
#
|
95
|
+
# Description:
|
96
|
+
# Clears the contents of the text field.
|
97
|
+
# Raises ObjectDisabledException if text field is disabled.
|
98
|
+
# Raises ObjectReadOnlyException if text field is read only.
|
99
|
+
#
|
100
|
+
def clear
|
101
|
+
assert_exists
|
102
|
+
assert_enabled
|
103
|
+
assert_not_readonly
|
104
|
+
|
105
|
+
highlight(:set)
|
106
|
+
|
107
|
+
@o.scrollIntoView
|
108
|
+
@o.focus
|
109
|
+
@o.select()
|
110
|
+
@o.fireEvent("onSelect")
|
111
|
+
@o.value = ""
|
112
|
+
@o.fireEvent("onKeyPress")
|
113
|
+
@o.fireEvent("onChange")
|
114
|
+
@container.wait()
|
115
|
+
highlight(:clear)
|
116
|
+
end
|
117
|
+
|
118
|
+
#
|
119
|
+
# Description:
|
120
|
+
# Append the provided text to the contents of the text field.
|
121
|
+
# Raises ObjectDisabledException if text field is disabled.
|
122
|
+
# Raises ObjectReadOnlyException if text field is read only.
|
123
|
+
#
|
124
|
+
# Input:
|
125
|
+
# - setThis - Text to be appended.
|
126
|
+
#
|
127
|
+
def append( setThis)
|
128
|
+
assert_exists
|
129
|
+
assert_enabled
|
130
|
+
assert_not_readonly
|
131
|
+
|
132
|
+
highlight(:set)
|
133
|
+
@o.scrollIntoView
|
134
|
+
@o.focus
|
135
|
+
doKeyPress( setThis )
|
136
|
+
highlight(:clear)
|
137
|
+
end
|
138
|
+
|
139
|
+
#
|
140
|
+
# Description:
|
141
|
+
# Sets the contents of the text field to the provided text. Overwrite the existing contents.
|
142
|
+
# Raises ObjectDisabledException if text field is disabled.
|
143
|
+
# Raises ObjectReadOnlyException if text field is read only.
|
144
|
+
#
|
145
|
+
# Input:
|
146
|
+
# - setThis - Text to be set.
|
147
|
+
#
|
148
|
+
def set( setThis )
|
149
|
+
assert_exists
|
150
|
+
assert_enabled
|
151
|
+
assert_not_readonly
|
152
|
+
|
153
|
+
highlight(:set)
|
154
|
+
@o.scrollIntoView
|
155
|
+
@o.focus
|
156
|
+
@o.select()
|
157
|
+
@o.fireEvent("onSelect")
|
158
|
+
@o.value = ""
|
159
|
+
@o.fireEvent("onKeyPress")
|
160
|
+
doKeyPress( setThis )
|
161
|
+
highlight(:clear)
|
162
|
+
@o.fireEvent("onChange")
|
163
|
+
@o.fireEvent("onBlur")
|
164
|
+
end
|
165
|
+
|
166
|
+
#
|
167
|
+
# Description:
|
168
|
+
# Sets the text of the text field withoud firing the events like onKeyPress, onKeyDown etc. This should not be used generally, but it
|
169
|
+
# is useful in situations where you need to set large text to the text field and you know that you don't have any event to be
|
170
|
+
# fired.
|
171
|
+
#
|
172
|
+
# Input:
|
173
|
+
# - v - Text to be set.
|
174
|
+
#
|
175
|
+
#def value=(v)
|
176
|
+
# assert_exists
|
177
|
+
# @o.value = v.to_s
|
178
|
+
#end
|
179
|
+
|
180
|
+
#
|
181
|
+
# Description:
|
182
|
+
# Used to set the value of text box and fires the event onKeyPress, onKeyDown, onKeyUp after each character.
|
183
|
+
# Shouldnot be used externally. Used internally by set and append methods.
|
184
|
+
#
|
185
|
+
# Input:
|
186
|
+
# - value - The string to enter into the text field
|
187
|
+
#
|
188
|
+
def doKeyPress( value )
|
189
|
+
begin
|
190
|
+
max = maxlength
|
191
|
+
if (max > 0 && value.length > max)
|
192
|
+
original_value = value
|
193
|
+
value = original_value[0...max]
|
194
|
+
element.log " Supplied string is #{suppliedValue.length} chars, which exceeds the max length (#{max}) of the field. Using value: #{value}"
|
195
|
+
end
|
196
|
+
rescue
|
197
|
+
# probably a text area - so it doesnt have a max Length
|
198
|
+
end
|
199
|
+
for i in 0..value.length-1
|
200
|
+
#sleep element.typingspeed # typing speed
|
201
|
+
c = value[i,1]
|
202
|
+
#element.log " adding c.chr " + c #.chr.to_s
|
203
|
+
@o.value = "#{(@o.value.to_s + c)}" #c.chr
|
204
|
+
@o.fireEvent("onKeyDown")
|
205
|
+
@o.fireEvent("onKeyPress")
|
206
|
+
@o.fireEvent("onKeyUp")
|
207
|
+
end
|
208
|
+
|
209
|
+
end
|
210
|
+
private :doKeyPress
|
211
|
+
|
212
|
+
alias readOnly? :readonly?
|
213
|
+
alias getContents value
|
214
|
+
alias maxLength maxlength
|
215
|
+
|
216
|
+
end # TextField
|
217
|
+
end # FireWatir
|
218
|
+
|