safariwatir 0.2.6 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/safariwatir.rb +68 -41
- data/safariwatir/scripter.rb +31 -3
- metadata +5 -5
data/safariwatir.rb
CHANGED
@@ -13,12 +13,35 @@ module Watir
|
|
13
13
|
def text
|
14
14
|
@scripter.document_text
|
15
15
|
end
|
16
|
+
|
17
|
+
def title
|
18
|
+
@scripter.document_title
|
19
|
+
end
|
16
20
|
end
|
17
21
|
|
18
22
|
module Container
|
19
23
|
attr_reader :scripter
|
20
24
|
private :scripter
|
21
25
|
|
26
|
+
DEFAULT_TYPING_LAG = 0.08
|
27
|
+
|
28
|
+
def set_fast_speed
|
29
|
+
@scripter.typing_lag = 0
|
30
|
+
end
|
31
|
+
|
32
|
+
def set_slow_speed
|
33
|
+
@scripter.typing_lag = DEFAULT_TYPING_LAG
|
34
|
+
end
|
35
|
+
|
36
|
+
def speed=(how_fast)
|
37
|
+
case how_fast
|
38
|
+
when :fast : set_fast_speed
|
39
|
+
when :slow : set_slow_speed
|
40
|
+
else
|
41
|
+
raise ArgumentError, "Invalid speed: #{how_fast}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
22
45
|
module Clickable
|
23
46
|
def click
|
24
47
|
@scripter.highlight(self) do
|
@@ -71,30 +94,23 @@ module Watir
|
|
71
94
|
end
|
72
95
|
|
73
96
|
def operate(&block)
|
74
|
-
|
97
|
+
scripter_suffix = OPERATIONS[how]
|
98
|
+
if scripter_suffix.nil?
|
99
|
+
raise "SafariWatir does not currently support finding by #{how}"
|
100
|
+
end
|
101
|
+
@scripter.send("operate_by_#{scripter_suffix}", self, &block)
|
75
102
|
end
|
76
103
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
88
|
-
def operate_by_text(&block)
|
89
|
-
@scripter.operate_on_link(self, &block)
|
90
|
-
end
|
91
|
-
def operate_by_url(&block)
|
92
|
-
@scripter.operate_on_link(self, &block)
|
93
|
-
end
|
94
|
-
def operate_by_value(&block)
|
95
|
-
@scripter.operate_by_input_value(self, &block)
|
96
|
-
end
|
97
|
-
alias_method :operate_by_caption, :operate_by_value
|
104
|
+
OPERATIONS = {
|
105
|
+
:id => "id",
|
106
|
+
:index => "index",
|
107
|
+
:class => "class",
|
108
|
+
:name => "name",
|
109
|
+
:text => "on_link",
|
110
|
+
:url => "on_link",
|
111
|
+
:value => "input_value",
|
112
|
+
:caption => "input_value"
|
113
|
+
}
|
98
114
|
end
|
99
115
|
|
100
116
|
class Form < HtmlElement
|
@@ -124,6 +140,10 @@ module Watir
|
|
124
140
|
include Clickable
|
125
141
|
include Container
|
126
142
|
|
143
|
+
def html
|
144
|
+
@scripter.get_html_for(self)
|
145
|
+
end
|
146
|
+
|
127
147
|
def text
|
128
148
|
@scripter.get_text_for(self)
|
129
149
|
end
|
@@ -205,6 +225,22 @@ module Watir
|
|
205
225
|
Option.new(@scripter, self, how, what)
|
206
226
|
end
|
207
227
|
|
228
|
+
def selected_values
|
229
|
+
values = []
|
230
|
+
index = 1
|
231
|
+
loop do
|
232
|
+
option = option(:index, index)
|
233
|
+
break unless option.exists?
|
234
|
+
values << option if option.selected?
|
235
|
+
index += 1
|
236
|
+
end
|
237
|
+
values.map {|o| o.text } #TODO?
|
238
|
+
end
|
239
|
+
|
240
|
+
def selected_value
|
241
|
+
selected_values.first
|
242
|
+
end
|
243
|
+
|
208
244
|
def speak
|
209
245
|
@scripter.speak_options_for(self)
|
210
246
|
end
|
@@ -230,6 +266,14 @@ module Watir
|
|
230
266
|
end
|
231
267
|
alias :exist? :exists?
|
232
268
|
|
269
|
+
def selected?
|
270
|
+
@scripter.option_selected?(self)
|
271
|
+
end
|
272
|
+
|
273
|
+
def text
|
274
|
+
@scripter.get_text_for(self)
|
275
|
+
end
|
276
|
+
|
233
277
|
def tag; "OPTION"; end
|
234
278
|
end
|
235
279
|
|
@@ -288,6 +332,8 @@ module Watir
|
|
288
332
|
class TableCell < ContentElement
|
289
333
|
def initialize(scripter, how, what, row = nil)
|
290
334
|
@scripter = scripter.for_table(self)
|
335
|
+
set_slow_speed # TODO: Need to inherit this somehow
|
336
|
+
|
291
337
|
@how = how
|
292
338
|
@what = what
|
293
339
|
@row = row
|
@@ -416,8 +462,6 @@ module Watir
|
|
416
462
|
include Container
|
417
463
|
include PageContainer
|
418
464
|
|
419
|
-
DEFAULT_TYPING_LAG = 0.08
|
420
|
-
|
421
465
|
def self.start(url = nil)
|
422
466
|
safari = new
|
423
467
|
safari.goto(url) if url
|
@@ -429,23 +473,6 @@ module Watir
|
|
429
473
|
@scripter.ensure_window_ready
|
430
474
|
set_slow_speed
|
431
475
|
end
|
432
|
-
|
433
|
-
def set_fast_speed
|
434
|
-
@scripter.typing_lag = 0
|
435
|
-
end
|
436
|
-
|
437
|
-
def set_slow_speed
|
438
|
-
@scripter.typing_lag = DEFAULT_TYPING_LAG
|
439
|
-
end
|
440
|
-
|
441
|
-
def speed=(how_fast)
|
442
|
-
case how_fast
|
443
|
-
when :fast : set_fast_speed
|
444
|
-
when :slow : set_slow_speed
|
445
|
-
else
|
446
|
-
raise ArgumentError, "Invalid speed: #{how_fast}"
|
447
|
-
end
|
448
|
-
end
|
449
476
|
|
450
477
|
def close
|
451
478
|
scripter.close
|
data/safariwatir/scripter.rb
CHANGED
@@ -120,6 +120,10 @@ if (element) {
|
|
120
120
|
execute(element.operate { %|return element.innerText| }, element)
|
121
121
|
end
|
122
122
|
|
123
|
+
def get_html_for(element = @element)
|
124
|
+
execute(element.operate { %|return element.innerHTML| }, element)
|
125
|
+
end
|
126
|
+
|
123
127
|
def operate_by_table_cell(element = @element)
|
124
128
|
%|var element = document;
|
125
129
|
if (element == undefined) {
|
@@ -137,7 +141,11 @@ if (element == undefined) {
|
|
137
141
|
end
|
138
142
|
|
139
143
|
def document_html
|
140
|
-
execute(%|return document.
|
144
|
+
execute(%|return document.all[0].outerHTML;|)
|
145
|
+
end
|
146
|
+
|
147
|
+
def document_title
|
148
|
+
execute(%|return document.title;|)
|
141
149
|
end
|
142
150
|
|
143
151
|
def focus(element)
|
@@ -196,11 +204,10 @@ if (selected == -1) {
|
|
196
204
|
element_exists?(element) { handle_option(element) }
|
197
205
|
end
|
198
206
|
|
199
|
-
def handle_option(select_list
|
207
|
+
def handle_option(select_list)
|
200
208
|
%|var option_found = false;
|
201
209
|
for (var i = 0; i < element.options.length; i++) {
|
202
210
|
if (element.options[i].#{select_list.how} == '#{select_list.what}') {
|
203
|
-
#{selection}
|
204
211
|
option_found = true;
|
205
212
|
}
|
206
213
|
}
|
@@ -209,6 +216,21 @@ if (!option_found) {
|
|
209
216
|
}|
|
210
217
|
end
|
211
218
|
private :handle_option
|
219
|
+
|
220
|
+
def option_selected?(element = @element)
|
221
|
+
element_exists?(element) { handle_selected(element) == "true" }
|
222
|
+
end
|
223
|
+
|
224
|
+
def handle_selected(select_list)
|
225
|
+
%|var selected = false;
|
226
|
+
for (var i = 0; i < element.options.length; i++) {
|
227
|
+
if (element.options[i].#{select_list.how} == '#{select_list.what}' && element.options[i].selected) {
|
228
|
+
selected = true;
|
229
|
+
}
|
230
|
+
}
|
231
|
+
return selected;|
|
232
|
+
end
|
233
|
+
private :handle_option
|
212
234
|
|
213
235
|
def clear_text_input(element = @element)
|
214
236
|
execute(element.operate { %|element.value = '';| }, element)
|
@@ -342,6 +364,12 @@ for (var i = 0; i < elements.length; i++) {
|
|
342
364
|
}
|
343
365
|
}|, yield)
|
344
366
|
end
|
367
|
+
|
368
|
+
def operate_by_class(element)
|
369
|
+
js.operate(%|
|
370
|
+
var elements = document.getElementsByClassName('#{element.what}');
|
371
|
+
var element = elements[0];|, yield)
|
372
|
+
end
|
345
373
|
|
346
374
|
# Checkboxes/Radios have the same name, different values
|
347
375
|
def handle_form_element_name_match(element)
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: safariwatir
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Hoover
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-08-17 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -35,7 +35,7 @@ files:
|
|
35
35
|
- safariwatir/core_ext.rb
|
36
36
|
- safariwatir/scripter.rb
|
37
37
|
- watir/exceptions.rb
|
38
|
-
has_rdoc:
|
38
|
+
has_rdoc: true
|
39
39
|
homepage: http://safariwatir.rubyforge.org/
|
40
40
|
post_install_message:
|
41
41
|
rdoc_options: []
|
@@ -58,7 +58,7 @@ requirements:
|
|
58
58
|
- Mac OS X running Safari
|
59
59
|
- Some features require you to turn on "Enable access for assistive devices" in System Preferences > Universal Access
|
60
60
|
rubyforge_project: safariwatir
|
61
|
-
rubygems_version: 1.
|
61
|
+
rubygems_version: 1.1.1
|
62
62
|
signing_key:
|
63
63
|
specification_version: 2
|
64
64
|
summary: Automated testing tool for web applications.
|