soda 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/SodaXML.rb ADDED
@@ -0,0 +1,129 @@
1
+ ###############################################################################
2
+ # Copyright (c) 2010, SugarCRM, Inc.
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ # * Redistributions of source code must retain the above copyright
8
+ # notice, this list of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above copyright
10
+ # notice, this list of conditions and the following disclaimer in the
11
+ # documentation and/or other materials provided with the distribution.
12
+ # * Neither the name of SugarCRM, Inc. nor the
13
+ # names of its contributors may be used to endorse or promote products
14
+ # derived from this software without specific prior written permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
+ # ARE DISCLAIMED. IN NO EVENT SHALL SugarCRM, Inc. BE LIABLE FOR ANY
20
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ ###############################################################################
27
+
28
+ ###############################################################################
29
+ # Needed Ruby libs:
30
+ ###############################################################################
31
+ require 'rubygems'
32
+ require 'libxml'
33
+ require 'SodaUtils'
34
+
35
+ ###############################################################################
36
+ # SodaXML -- Class
37
+ # This class converts XML documents into Soda Meta Data.
38
+ # A valid Soda XML file always should start with <soda> and end with </soda>
39
+ #
40
+ ###############################################################################
41
+ class SodaXML
42
+ attr_accessor :doc
43
+
44
+ ###############################################################################
45
+ # processChildren -- Method
46
+ # This method walks through the node and converts it into Soda Markup
47
+ # *Tag(node) names indicate what action to take
48
+ # *attributes are mapped directly over
49
+ # *child nodes map to the children attribute
50
+ #
51
+ # Params:
52
+ # node: This is the root doc from the XML parser from a soda file.
53
+ #
54
+ # Results:
55
+ # retutns an array of hashes.
56
+ #
57
+ ###############################################################################
58
+ def processChildren(node)
59
+ children = []
60
+
61
+ for child in node.children()
62
+ if (child.name == 'text')
63
+ next
64
+ end
65
+
66
+ cur = Hash.new()
67
+ cur['line_number'] = "#{child.line_num}"
68
+ cur['do'] = "#{child.name}"
69
+
70
+ case child.name
71
+ when /javascript/i
72
+ cur['content'] = child.content
73
+ when /ruby/i
74
+ cur['content'] = child.content
75
+ when /comment/i
76
+ cur['content'] = child.content
77
+ when /whitelist/i
78
+ cur['content'] = child.content
79
+ end
80
+
81
+ child.attributes.each do | attribute |
82
+ cur[attribute.name] = "#{attribute.value}"
83
+ end
84
+
85
+ if child.children?()
86
+ cur['children'] = self.processChildren(child)
87
+ end
88
+
89
+ children.push(cur)
90
+ end
91
+
92
+ return children
93
+ end
94
+
95
+ ###############################################################################
96
+ # parse -- Method
97
+ # This methos parses the XML document and returns Soda markup.
98
+ #
99
+ # Params:
100
+ # file: The soda XML file to parse into soda meta data.
101
+ #
102
+ # Results:
103
+ # returns an array of hashes from the processChildren method.
104
+ #
105
+ ###############################################################################
106
+ def parse(file)
107
+ data = nil
108
+ parser = nil
109
+ doc = nil
110
+
111
+ begin
112
+ LibXML::XML.default_line_numbers = true
113
+ parser = LibXML::XML::Parser.file(file)
114
+ doc = parser.parse()
115
+ data = processChildren(doc.root)
116
+ rescue Exception => e
117
+ $curSoda.rep.log("Failed to parse XML file: \"#{file}\"!\n",
118
+ SodaUtils::ERROR)
119
+ $curSoda.rep.ReportException(e, true, file)
120
+
121
+ data = nil
122
+ ensure
123
+ # make sure this exception doesn't make it up to the soda level #
124
+ end
125
+
126
+ return data
127
+ end
128
+ end
129
+
@@ -0,0 +1,87 @@
1
+ ###############################################################################
2
+ # Copyright (c) 2010, SugarCRM, Inc.
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ # * Redistributions of source code must retain the above copyright
8
+ # notice, this list of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above copyright
10
+ # notice, this list of conditions and the following disclaimer in the
11
+ # documentation and/or other materials provided with the distribution.
12
+ # * Neither the name of SugarCRM, Inc. nor the
13
+ # names of its contributors may be used to endorse or promote products
14
+ # derived from this software without specific prior written permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
+ # ARE DISCLAIMED. IN NO EVENT SHALL SugarCRM, Inc. BE LIABLE FOR ANY
20
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ ###############################################################################
27
+
28
+ ###############################################################################
29
+ # SodaCheckBoxField -- Class
30
+ # This is a simple class for dealing with Checkbox fields.
31
+ #
32
+ ###############################################################################
33
+ class SodaCheckBoxField < SodaField
34
+
35
+ ###############################################################################
36
+ # set -- Method
37
+ # This sets the value for a given field.
38
+ #
39
+ # Params:
40
+ # field: The field to set a value on.
41
+ # value: The value to set.
42
+ #
43
+ # Results:
44
+ #
45
+ ###############################################################################
46
+ def self.set(field, value)
47
+ result = 0
48
+
49
+ if (!field.enabled?)
50
+ $curSoda.rep.ReportFailure(
51
+ "Error: Trying to set a value for a disabled Element!\n")
52
+ else
53
+ value = self.getStringTrue(value)
54
+ field.set(value)
55
+ result = 0
56
+ end
57
+
58
+ return result
59
+ end
60
+
61
+ ###############################################################################
62
+ # assert -- Method
63
+ #
64
+ #
65
+ #
66
+ ###############################################################################
67
+ def self.assert(field, value)
68
+ result = nil
69
+
70
+ if (value.kind_of? Regexp)
71
+ $curSoda.rep.log("Warning: Regex does not work on checkbox fields\n")
72
+ end
73
+
74
+ value = self.getStringTrue(value)
75
+ $curSoda.rep.log("Field Value: #{field.checked?()}\n")
76
+
77
+ if (value)
78
+ result = field.checked?()
79
+ else
80
+ result = !field.checked?()
81
+ end
82
+
83
+ return result
84
+ end
85
+
86
+ end
87
+
@@ -0,0 +1,37 @@
1
+ ###############################################################################
2
+ # Copyright (c) 2010, SugarCRM, Inc.
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ # * Redistributions of source code must retain the above copyright
8
+ # notice, this list of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above copyright
10
+ # notice, this list of conditions and the following disclaimer in the
11
+ # documentation and/or other materials provided with the distribution.
12
+ # * Neither the name of SugarCRM, Inc. nor the
13
+ # names of its contributors may be used to endorse or promote products
14
+ # derived from this software without specific prior written permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
+ # ARE DISCLAIMED. IN NO EVENT SHALL SugarCRM, Inc. BE LIABLE FOR ANY
20
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ ###############################################################################
27
+
28
+ ###############################################################################
29
+ # SodaFileField -- Class
30
+ # This is just an empty class...
31
+ #
32
+ #
33
+ ###############################################################################
34
+ class SodaFileField < SodaField
35
+
36
+
37
+ end
@@ -0,0 +1,40 @@
1
+ ###############################################################################
2
+ # Copyright (c) 2010, SugarCRM, Inc.
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ # * Redistributions of source code must retain the above copyright
8
+ # notice, this list of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above copyright
10
+ # notice, this list of conditions and the following disclaimer in the
11
+ # documentation and/or other materials provided with the distribution.
12
+ # * Neither the name of SugarCRM, Inc. nor the
13
+ # names of its contributors may be used to endorse or promote products
14
+ # derived from this software without specific prior written permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
+ # ARE DISCLAIMED. IN NO EVENT SHALL SugarCRM, Inc. BE LIABLE FOR ANY
20
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ ###############################################################################
27
+
28
+ class SodaLiField < SodaField
29
+
30
+ def self.assert(field, value)
31
+ comp = "#{field.text}"
32
+
33
+ if (comp =~ /#{value}/)
34
+ return true
35
+ else
36
+ return false
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,44 @@
1
+ ###############################################################################
2
+ # Copyright (c) 2010, SugarCRM, Inc.
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ # * Redistributions of source code must retain the above copyright
8
+ # notice, this list of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above copyright
10
+ # notice, this list of conditions and the following disclaimer in the
11
+ # documentation and/or other materials provided with the distribution.
12
+ # * Neither the name of SugarCRM, Inc. nor the
13
+ # names of its contributors may be used to endorse or promote products
14
+ # derived from this software without specific prior written permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
+ # ARE DISCLAIMED. IN NO EVENT SHALL SugarCRM, Inc. BE LIABLE FOR ANY
20
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ ###############################################################################
27
+
28
+ class SodaRadioField < SodaCheckBoxField
29
+
30
+ def self.set(field, value)
31
+ result = 0
32
+ if (!field.enabled?)
33
+ result = -1
34
+ $curSoda.rep.ReportFailure(
35
+ "Error: Trying to set value for a disabled Element!\n")
36
+ else
37
+ field.set()
38
+ result = 0
39
+ end
40
+
41
+ return result
42
+ end
43
+
44
+ end
@@ -0,0 +1,59 @@
1
+ ###############################################################################
2
+ # Copyright (c) 2010, SugarCRM, Inc.
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ # * Redistributions of source code must retain the above copyright
8
+ # notice, this list of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above copyright
10
+ # notice, this list of conditions and the following disclaimer in the
11
+ # documentation and/or other materials provided with the distribution.
12
+ # * Neither the name of SugarCRM, Inc. nor the
13
+ # names of its contributors may be used to endorse or promote products
14
+ # derived from this software without specific prior written permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
+ # ARE DISCLAIMED. IN NO EVENT SHALL SugarCRM, Inc. BE LIABLE FOR ANY
20
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ ###############################################################################
27
+
28
+ class SodaSelectField < SodaField
29
+
30
+ def self.set(field, value)
31
+ result = 0
32
+
33
+ if (!field.enabled?)
34
+ result = -1
35
+ $curSoda.rep.ReportFailure(
36
+ "Error: Trying to set a value for a disabled Element!\n")
37
+ else
38
+ begin
39
+ field.select(value)
40
+ result = 0
41
+ rescue
42
+ field.select_value(value)
43
+ result = 0
44
+ end
45
+ end
46
+
47
+ return result
48
+ end
49
+
50
+ def self.assert(field, value)
51
+ return field.selected?(value)
52
+ end
53
+
54
+ def self.getAllContents(field)
55
+ return field.getAllContents
56
+ end
57
+
58
+ end
59
+
@@ -0,0 +1,363 @@
1
+ ###############################################################################
2
+ # Copyright (c) 2010, SugarCRM, Inc.
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ # * Redistributions of source code must retain the above copyright
8
+ # notice, this list of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above copyright
10
+ # notice, this list of conditions and the following disclaimer in the
11
+ # documentation and/or other materials provided with the distribution.
12
+ # * Neither the name of SugarCRM, Inc. nor the
13
+ # names of its contributors may be used to endorse or promote products
14
+ # derived from this software without specific prior written permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
+ # ARE DISCLAIMED. IN NO EVENT SHALL SugarCRM, Inc. BE LIABLE FOR ANY
20
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ ###############################################################################
27
+
28
+ ###############################################################################
29
+ # SodaField -- Class
30
+ #
31
+ #
32
+ #
33
+ #
34
+ ###############################################################################
35
+ class SodaField
36
+
37
+ require 'FieldUtils'
38
+
39
+ ###############################################################################
40
+ #
41
+ ###############################################################################
42
+ def self.assert(field, value)
43
+ comp = (!field.value.empty?)? field.value: field.text
44
+ $curSoda.rep.log("Field Value: #{field.value}\n")
45
+ if value.kind_of? Regexp
46
+ return value.match(comp)
47
+ end
48
+ return value == comp
49
+ end
50
+
51
+ ###############################################################################
52
+ # jsevent - Method
53
+ # THis method fires a javascript event.
54
+ #
55
+ # Params:
56
+ # field: The field to fire the event on.
57
+ # jsevent: The event to fire: onmoseover...
58
+ #
59
+ # Results:
60
+ # None.
61
+ #
62
+ ###############################################################################
63
+ def self.jsevent(field, jsevent, wait = true)
64
+ info = nil
65
+ elm_type = nil
66
+ msg = "Firing JavaScript Event: '#{jsevent}' for Element: "
67
+
68
+ begin
69
+ tmp = FieldUtils.WatirFieldToStr(field, $curSoda.rep)
70
+ tmp = "Unknown" if (tmp == nil)
71
+ $curSoda.rep.log("#{msg}#{tmp}.\n")
72
+
73
+ if (Watir::Browser.default !~ /ie/i)
74
+ self.focus(field)
75
+ end
76
+
77
+ field.fire_event("#{jsevent}", wait)
78
+ rescue Exception => e
79
+ $curSoda.rep.ReportException(e, true)
80
+ ensure
81
+ end
82
+
83
+ $curSoda.rep.log("JavaScript Event finished.\n")
84
+ end
85
+
86
+ ###############################################################################
87
+ #
88
+ ###############################################################################
89
+ def self.uploadFile(fieldname, file)
90
+ $curSoda.file_field(:value, fieldname).set(file)
91
+ end
92
+
93
+ ###############################################################################
94
+ # set -- Method
95
+ # This method sets the value for the field. Checks to make sure that the
96
+ # field is enabled before trying to set.
97
+ #
98
+ # Params:
99
+ # field: this is the watir object for the field.
100
+ # value: The vale to set the field to.
101
+ #
102
+ # Results:
103
+ # returns 0 on success, or -1 on error
104
+ #
105
+ ###############################################################################
106
+ def self.set(field, value)
107
+ result = 0
108
+ msg = "Setting Element: "
109
+
110
+ begin
111
+ tmp = FieldUtils.WatirFieldToStr(field, $curSoda.rep)
112
+ tmp = "Unknown" if (tmp == nil)
113
+ $curSoda.rep.log("#{msg}#{tmp}: Value => '#{value}'.\n")
114
+
115
+ if (!field.enabled?)
116
+ $curSoda.rep.ReportFailure(
117
+ "Error: Trying to set a value for a disabled Element!\n")
118
+ result = -1
119
+ else
120
+ field.set(value)
121
+ result = 0
122
+ end
123
+ rescue Exception => e
124
+ $curSoda.rep.ReportException(e, true)
125
+ result = -1
126
+ ensure
127
+ end
128
+
129
+ return result
130
+ end
131
+
132
+ ###############################################################################
133
+ # append -- Method:
134
+ # This method appends a value to the existing value for a watir text
135
+ # field. Checks that the field is enabled before appending.
136
+ #
137
+ # Params:
138
+ # field: this is the watir object for the field.
139
+ # value: this is the vale to append to the field.
140
+ #
141
+ # Results:
142
+ # returns -1 on error, or 0 on success.
143
+ #
144
+ ###############################################################################
145
+ def self.append(field, value)
146
+ result = 0
147
+ msg = "Appending to Element: "
148
+
149
+ begin
150
+ tmp = FieldUtils.WatirFieldToStr(field, $curSoda.rep)
151
+ tmp = "Unknown" if (tmp == nil)
152
+ $curSoda.rep.log("#{msg}#{tmp}: Value => '#{value}'.\n")
153
+
154
+ if (!field.enabled?)
155
+ $curSoda.rep.ReportFailure(
156
+ "Error: Trying to set a value for a disabled Element!\n")
157
+ result = -1
158
+ else
159
+ field.append(value)
160
+ result = 0
161
+ end
162
+ rescue Exception => e
163
+ $curSoda.rep.ReportException(e, true)
164
+ result = -1
165
+ ensure
166
+ end
167
+
168
+ $curSoda.rep.log("Append finished.\n")
169
+
170
+ return result
171
+ end
172
+
173
+ ###############################################################################
174
+ # alertHack -- Method
175
+ # This method auto answers java alerts & confirms.
176
+ #
177
+ # Input: alert: true or false, to cancel or ok dialog.
178
+ #
179
+ # Output: always retutns true.
180
+ #
181
+ ###############################################################################
182
+ def self.alertHack(alert = nil, modify = true)
183
+ if (alert == nil)
184
+ return true
185
+ end
186
+
187
+ begin
188
+ if (modify)
189
+ if (Watir::Browser.default == 'firefox')
190
+ alertConfirm = "var old_alert = browser.contentWindow.alert;"
191
+ alertConfirm += "var old_confirm = browser.contentWindow."+
192
+ "confirm;"
193
+ alertConfirm += "browser.contentWindow.alert = function()"+
194
+ "{return #{alert};};"
195
+ alertConfirm += "browser.contentWindow.confirm = function()"+
196
+ "{return #{alert};};"
197
+ if (alert)
198
+ alertConfirm += "browser.contentWindow.onbeforeunload = null;"
199
+ end
200
+ $jssh_socket.send(alertConfirm + "\n", 0)
201
+ $curSoda.browser.read_socket();
202
+ end
203
+
204
+ if (Watir::Browser.default == 'ie')
205
+ alertConfirm = "var old_alert = window.alert;"
206
+ alertConfirm += "var old_confirm = window.confirm;"
207
+ alertConfirm += "window.alert = function(){return #{alert};};"
208
+ alertConfirm += "window.confirm = function(){return #{alert};};"
209
+ if (alert)
210
+ alertConfirm += "window.onbeforeunload = null;"
211
+ end
212
+ $curSoda.browser.document.parentWindow.eval(alertConfirm + "\n")
213
+ end
214
+ else
215
+ if (Watir::Browser.default == 'firefox')
216
+ alertConfirm = "browser.contentWindow.alert = old_alert;"
217
+ alertConfirm += "browser.contentWindow.confirm = old_confirm;"
218
+ if (alert)
219
+ alertConfirm += "browser.contentWindow.onbeforeunload = null;"
220
+ end
221
+ $jssh_socket.send(alertConfirm + "\n", 0)
222
+ $curSoda.browser.read_socket();
223
+ end
224
+
225
+ if (Watir::Browser.default == 'ie')
226
+ alertConfirm = "var old_alert = window.alert;"
227
+ alertConfirm += "var old_confirm = window.confirm;"
228
+ alertConfirm += "window.alert = old_alert;"
229
+ alertConfirm += "window.confirm = old_confirm;"
230
+ if (alert)
231
+ alertConfirm += "window.onbeforeunload = null;"
232
+ end
233
+ $curSoda.browser.document.parentWindow.eval(alertConfirm + "\n")
234
+ end
235
+ end
236
+ rescue Exception => e
237
+ $curSoda.rep.ReportException(e, true)
238
+ ensure
239
+ end
240
+ end
241
+
242
+ ###############################################################################
243
+ # click -- Method
244
+ # This method fires a watir element object's click method.
245
+ #
246
+ # Params:
247
+ # field: This is the watir object to click.
248
+ # sugarwait: true/false, will calling SodaUtils.WaitSugarAjaxDone if true.
249
+ #
250
+ # Results:
251
+ # Always returns 0
252
+ #
253
+ ###############################################################################
254
+ def self.click(field, sugarwait = false)
255
+ result = 0
256
+ msg = "Clicking element: "
257
+ retry_count = 10
258
+ i = 0
259
+
260
+ begin
261
+ self.focus(field)
262
+ rescue Exception => e
263
+ if (Watir::Browser.default !~ /ie/i)
264
+ $curSoda.rep.ReportException(e, true)
265
+ end
266
+ ensure
267
+ end
268
+
269
+ for i in 0..retry_count
270
+ result = 0
271
+
272
+ begin
273
+ tmp = FieldUtils.WatirFieldToStr(field, $curSoda.rep)
274
+ tmp = "Unknown" if (tmp == nil)
275
+
276
+ $curSoda.rep.log("#{msg}#{tmp}.\n")
277
+ field.click()
278
+ $curSoda.browser.wait()
279
+
280
+ if (sugarwait)
281
+ SodaUtils.WaitSugarAjaxDone($curSoda.browser, $curSoda.rep)
282
+ end
283
+ rescue Exception => e
284
+ result = -1
285
+
286
+ if (e.message !~ /missing ; before statement/i)
287
+ $curSoda.rep.ReportException(e, true)
288
+ break
289
+ else
290
+ sleep(1)
291
+ end
292
+ ensure
293
+ end
294
+
295
+ break if (result == 0)
296
+ $curSoda.rep.log("Retying: #{i}\n", SodaUtils::WARN)
297
+ end
298
+
299
+ $curSoda.rep.log("Click finished.\n")
300
+
301
+ return result
302
+ end
303
+
304
+ ###############################################################################
305
+ #
306
+ ###############################################################################
307
+ def self.focus(field)
308
+ return field.focus
309
+ end
310
+
311
+ ###############################################################################
312
+ #
313
+ ###############################################################################
314
+ def self.clear(field)
315
+ return field.clear
316
+ end
317
+
318
+ ###############################################################################
319
+ #
320
+ ###############################################################################
321
+ def self.getValue(field)
322
+ return field.value
323
+ end
324
+
325
+ ###############################################################################
326
+ #
327
+ ###############################################################################
328
+ def self.getText(field)
329
+ return field.text()
330
+ end
331
+
332
+ ###############################################################################
333
+ #
334
+ ###############################################################################
335
+ def self.enabled(field)
336
+ return field.enabled?()
337
+ end
338
+
339
+ ###############################################################################
340
+ #
341
+ ###############################################################################
342
+ def self.disabled(field)
343
+ return field.disabled()
344
+ end
345
+
346
+ ###############################################################################
347
+ # return true or false based on a string value
348
+ ###############################################################################
349
+ def self.getStringTrue(value)
350
+ if value.is_a?(String)
351
+ value.downcase!
352
+
353
+ if value == 'true' or value == 'yes' or value == '1'
354
+ return true
355
+ else
356
+ return false
357
+ end
358
+ end
359
+
360
+ return value
361
+ end
362
+
363
+ end