sahi 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/sahi.rb +180 -9
- data/test/elementstub_test.rb +92 -7
- data/test/sahi_test.rb +436 -327
- metadata +8 -10
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4fc17be0dcd8a323688ef2554ac53d1753fa8959
|
4
|
+
data.tar.gz: dccf4f8ab3a528997966c27f712d66393f482e71
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eaf53930e206010fb36a9e7b4942e41db34790b65c86c92e303171c7885708b04aa5db2a1bbf9a94caa4b1a84a19c5c1bb131b3ed7e63f3552fbe52e12ee0e17
|
7
|
+
data.tar.gz: 763f56c89466f704a7056f219a6f2b10fbecda3cf08ed822a86a771c66b64b4fc5b2f67ed8610229b5bec1e988e10ba167b3df4f98523db6e495c736aa6e7b23
|
data/lib/sahi.rb
CHANGED
@@ -111,7 +111,7 @@ module Sahi
|
|
111
111
|
|
112
112
|
def exec_command(cmd, qs={})
|
113
113
|
res = response("http://#{@proxy_host}:#{@proxy_port}/_s_/dyn/Driver_" + cmd, {"sahisid"=>@sahisid}.update(qs))
|
114
|
-
return res
|
114
|
+
return res.force_encoding("UTF-8")
|
115
115
|
end
|
116
116
|
|
117
117
|
def response(url, qs={})
|
@@ -147,23 +147,93 @@ module Sahi
|
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
150
|
+
def prepare_window_action(oldTitle)
|
151
|
+
len = oldTitle.length
|
152
|
+
if (len > 30)
|
153
|
+
len = 30
|
154
|
+
end
|
155
|
+
titleToUse = fetch("_sahi.trim(#{Utils.quoted(oldTitle[0..30].strip)})")
|
156
|
+
newTitle = titleToUse.gsub(/[^0-9a-zA-Z ]/, '') + ' _' + Time.now.getutc.to_s
|
157
|
+
execute_step("window.document.title =" + Utils.quoted(newTitle))
|
158
|
+
wait(2);
|
159
|
+
return newTitle
|
160
|
+
end
|
161
|
+
|
162
|
+
def window_action(action)
|
163
|
+
title = fetch("window.top.document.title")
|
164
|
+
title = prepare_window_action(title)
|
165
|
+
puts ">" + title + "<"
|
166
|
+
exec_command("windowAction", {"action" => action, "title" => title})
|
167
|
+
end
|
168
|
+
|
169
|
+
def type_key_code_native(key)
|
170
|
+
exec_command("typeKeyCodeNative", {"key" => key})
|
171
|
+
end
|
172
|
+
|
173
|
+
def get_windows(activePeriod=nil)
|
174
|
+
if(activePeriod == nil)
|
175
|
+
str = exec_command("getWindowsAsJSON", {"activePeriod" => -1});
|
176
|
+
else
|
177
|
+
activePeriod = activePeriod * 1000
|
178
|
+
str = exec_command("getWindowsAsJSON", {"activePeriod" => activePeriod});
|
179
|
+
end
|
180
|
+
return JSON.parse(str)
|
181
|
+
end
|
182
|
+
|
183
|
+
def type_native(str)
|
184
|
+
exec_command("typeNative", {"str" => str})
|
185
|
+
end
|
186
|
+
|
187
|
+
def execute_sahi(step)
|
188
|
+
if popup?()
|
189
|
+
step = "_sahi._popup(#{Utils.quoted(@popup_name)})." + step
|
190
|
+
end
|
191
|
+
if domain?()
|
192
|
+
step = "_sahi._domain(#{Utils.quoted(@domain_name)})." + step
|
193
|
+
end
|
194
|
+
#puts step
|
195
|
+
exec_command("setStep", {"step" => step, 'addSahi' => true})
|
196
|
+
i = 0
|
197
|
+
while (i < 500)
|
198
|
+
sleep(0.1)
|
199
|
+
i+=1
|
200
|
+
check_done = exec_command("doneStep")
|
201
|
+
done = "true".eql?(check_done)
|
202
|
+
|
203
|
+
error = check_done.index("error:") == 0
|
204
|
+
return if done
|
205
|
+
if (error)
|
206
|
+
raise check_done
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
150
211
|
def method_missing(m, *args, &block)
|
151
212
|
return ElementStub.new(self, m.to_s, args)
|
152
213
|
end
|
153
214
|
|
154
215
|
# evaluates a javascript expression on the browser and fetches its value
|
155
|
-
|
216
|
+
def fetch(expression)
|
156
217
|
key = "___lastValue___" + Time.now.getutc.to_s;
|
157
218
|
execute_step("_sahi.setServerVarPlain('"+key+"', " + expression + ")")
|
158
219
|
return check_nil(exec_command("getVariable", {"key" => key}))
|
159
|
-
|
220
|
+
end
|
160
221
|
|
161
222
|
# evaluates a javascript expression on the browser and returns true if value is true or "true"
|
162
223
|
def fetch_boolean(expression)
|
163
224
|
return fetch(expression) == "true"
|
164
225
|
end
|
165
226
|
|
166
|
-
|
227
|
+
# returns element attributes of all elements of type attr matching the identifier within relations
|
228
|
+
def collect(els, attr=nil)
|
229
|
+
if(attr == nil)
|
230
|
+
return els.collect_similar()
|
231
|
+
else
|
232
|
+
return fetch("_sahi.collectAttributes(#{Utils.quoted(attr)}, #{Utils.quoted(els.to_type())}, #{els.to_identifiers()})").split(",___sahi___")
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
|
167
237
|
def browser_js=(js)
|
168
238
|
exec_command("setBrowserJS", {"browserJS"=>js})
|
169
239
|
end
|
@@ -270,6 +340,41 @@ module Sahi
|
|
270
340
|
execute_step("_sahi._clearLastPrompt()")
|
271
341
|
end
|
272
342
|
|
343
|
+
# simulates the touch event
|
344
|
+
def touch()
|
345
|
+
execute_step("_sahi._touch(#{self.to_s()})")
|
346
|
+
end
|
347
|
+
|
348
|
+
# simulates the tap event
|
349
|
+
def tap()
|
350
|
+
execute_step("_sahi._tap(#{self.to_s()})")
|
351
|
+
end
|
352
|
+
|
353
|
+
# simulates the touchStart event
|
354
|
+
def touchStart()
|
355
|
+
execute_step("_sahi._touchStart(#{self.to_s()})")
|
356
|
+
end
|
357
|
+
|
358
|
+
# simulates the touchEnd event
|
359
|
+
def touchEnd()
|
360
|
+
execute_step("_sahi._touchEnd(#{self.to_s()})")
|
361
|
+
end
|
362
|
+
|
363
|
+
# simulates the touchCancel event
|
364
|
+
def touchCancel()
|
365
|
+
execute_step("_sahi._touchCancel(#{self.to_s()})")
|
366
|
+
end
|
367
|
+
|
368
|
+
# simulates the touchMove event
|
369
|
+
def touchMove(moveX, moveY, isRelative=true)
|
370
|
+
execute_step("_sahi._touchMove(#{self.to_s()}, moveX, moveY, isRelative)")
|
371
|
+
end
|
372
|
+
|
373
|
+
# simulates the swipe event
|
374
|
+
def swipe(moveX, moveY, isRelative=true)
|
375
|
+
execute_step("_sahi._touchMove(#{self.to_s()}, moveX, moveY, isRelative)")
|
376
|
+
end
|
377
|
+
|
273
378
|
# set an expectation to set given value for specific prompt message
|
274
379
|
def expect_prompt(message, input)
|
275
380
|
execute_step("_sahi._expectPrompt(#{Utils.quoted(message)}, #{Utils.quoted(input) })")
|
@@ -305,6 +410,16 @@ module Sahi
|
|
305
410
|
def title()
|
306
411
|
return fetch("_sahi._title()")
|
307
412
|
end
|
413
|
+
|
414
|
+
# return selection text
|
415
|
+
|
416
|
+
def selection_text(win = nil)
|
417
|
+
if(win != nil)
|
418
|
+
return fetch("_sahi._getSelectionText(#{win.to_s()})")
|
419
|
+
else
|
420
|
+
return fetch("_sahi._getSelectionText()")
|
421
|
+
end
|
422
|
+
end
|
308
423
|
|
309
424
|
# returns true if browser is Internet Explorer
|
310
425
|
def ie?()
|
@@ -408,13 +523,31 @@ module Sahi
|
|
408
523
|
# choose option in a select box
|
409
524
|
def choose(val)
|
410
525
|
@browser.execute_step("_sahi._setSelected(#{self.to_s()}, #{val.to_json})")
|
411
|
-
end
|
526
|
+
end
|
412
527
|
|
413
528
|
# sets the value for textboxes or textareas. Also triggers necessary events.
|
414
529
|
def value=(val)
|
415
530
|
@browser.execute_step("_sahi._setValue(#{self.to_s()}, #{Utils.quoted(val)})")
|
416
531
|
end
|
417
|
-
|
532
|
+
|
533
|
+
# select text for manipulation
|
534
|
+
|
535
|
+
def select_range(rangeStart, rangeEnd, type=nil)
|
536
|
+
if(type!= nil)
|
537
|
+
@browser.execute_step("_sahi._selectRange(#{self.to_s()}, rangeStart, rangeEnd, #{Utils.quoted(type)})")
|
538
|
+
else
|
539
|
+
@browser.execute_step("_sahi._selectRange(#{self.to_s()}, #{rangeStart}, #{rangeEnd})")
|
540
|
+
end
|
541
|
+
end
|
542
|
+
|
543
|
+
def select_text_range(searchText, position=nil)
|
544
|
+
if(position != nil)
|
545
|
+
@browser.execute_step("_sahi._selectTextRange(#{self.to_s()}, #{Utils.quoted(searchText)}, #{Utils.quoted(position)})")
|
546
|
+
else
|
547
|
+
@browser.execute_step("_sahi._selectTextRange(#{self.to_s()}, #{Utils.quoted(searchText)})")
|
548
|
+
end
|
549
|
+
end
|
550
|
+
|
418
551
|
# returns value of textbox or textareas and other relevant input elements
|
419
552
|
def value()
|
420
553
|
return @browser.fetch("_sahi._getValue(#{self.to_s()})")
|
@@ -428,7 +561,7 @@ module Sahi
|
|
428
561
|
else
|
429
562
|
return @browser.fetch("_sahi.getAttribute(#{self.to_s()}, #{Utils.quoted(attr)})")
|
430
563
|
end
|
431
|
-
|
564
|
+
else
|
432
565
|
return @browser.fetch("#{self.to_s()}")
|
433
566
|
end
|
434
567
|
end
|
@@ -479,11 +612,41 @@ module Sahi
|
|
479
612
|
# browser.cell(0).under(browser.cell("Header")) will denote the cell visually under "Header"
|
480
613
|
# browser.cell(0).near(browser.cell("Book")).under(browser.cell("Cost")) may be used to denote the Cost of Book in a grid
|
481
614
|
|
482
|
-
def under(el2)
|
483
|
-
|
615
|
+
def under(el2, offset=nil, limit_under=nil)
|
616
|
+
ar = (offset!=nil || limit_under!=nil) ? [el2, offset, limit_under] : [el2];
|
617
|
+
@identifiers << ElementStub.new(@browser, "under", ar)
|
618
|
+
return self
|
619
|
+
end
|
620
|
+
|
621
|
+
def above(el2, offset=nil, limit_under=nil)
|
622
|
+
ar = (offset!=nil || limit_under!=nil) ? [el2, offset, limit_under] : [el2];
|
623
|
+
@identifiers << ElementStub.new(@browser, "above", ar)
|
624
|
+
return self
|
625
|
+
end
|
626
|
+
|
627
|
+
def above_or_under(el2, offset=nil, limit_under=nil)
|
628
|
+
ar = (offset!=nil || limit_under!=nil) ? [el2, offset, limit_under] : [el2];
|
629
|
+
@identifiers << ElementStub.new(@browser, "aboveOrUnder", ar)
|
630
|
+
return self
|
631
|
+
end
|
632
|
+
|
633
|
+
def right_of(el2, offset=nil, limit_under=nil)
|
634
|
+
ar = (offset!=nil || limit_under!=nil) ? [el2, offset, limit_under] : [el2];
|
635
|
+
@identifiers << ElementStub.new(@browser, "rightOf", ar)
|
484
636
|
return self
|
485
637
|
end
|
486
638
|
|
639
|
+
def left_of(el2, offset=nil, limit_under=nil)
|
640
|
+
ar = (offset!=nil || limit_under!=nil) ? [el2, offset, limit_under] : [el2];
|
641
|
+
@identifiers << ElementStub.new(@browser, "leftOf", ar)
|
642
|
+
return self
|
643
|
+
end
|
644
|
+
|
645
|
+
def left_or_right_of(el2, offset=nil, limit_under=nil)
|
646
|
+
ar = (offset!=nil || limit_under!=nil) ? [el2, offset, limit_under] : [el2];
|
647
|
+
@identifiers << ElementStub.new(@browser, "leftOrRightOf", ar)
|
648
|
+
return self
|
649
|
+
end
|
487
650
|
|
488
651
|
# specifies exacts coordinates to click inside an element. The coordinates are relative to the element. x is from left and y is from top. Can be negative to specify other direction
|
489
652
|
# browser.button("Menu Button with Arrow on side").xy(-5, 10).click will click on the button, 5 pixels from right and 10 pixels from top.
|
@@ -556,6 +719,14 @@ module Sahi
|
|
556
719
|
return "_sahi._#{@type}(#{concat_identifiers(@identifiers).join(", ") })"
|
557
720
|
end
|
558
721
|
|
722
|
+
def to_type
|
723
|
+
return "_#{@type}"
|
724
|
+
end
|
725
|
+
|
726
|
+
def to_identifiers
|
727
|
+
return "#{concat_identifiers(@identifiers).join(", ") }"
|
728
|
+
end
|
729
|
+
|
559
730
|
def concat_identifiers(ids)
|
560
731
|
return ids.collect {|id| id.kind_of?(String) ? Utils.quoted(id) : (id.is_a?(ElementStub) ? id.to_s() : id.to_json())}
|
561
732
|
end
|
data/test/elementstub_test.rb
CHANGED
@@ -24,15 +24,100 @@ class TC_MyTest < Test::Unit::TestCase
|
|
24
24
|
assert_equal("_sahi._div(\"id1\", _sahi._near(_sahi._div(\"id2\")))", stub1.to_s())
|
25
25
|
end
|
26
26
|
|
27
|
-
def test_browser_multi_stubs()
|
28
|
-
|
29
|
-
assert_equal("_sahi._div(\"id\")",
|
30
|
-
assert_equal("_sahi._div(\"id\", \"id2\")",
|
31
|
-
assert_equal("_sahi._div(\"id1\", _sahi._near(_sahi._div(\"id2\")))",
|
27
|
+
def test_browser_multi_stubs()
|
28
|
+
@b = Sahi::Browser.new("", "", "")
|
29
|
+
assert_equal("_sahi._div(\"id\")", @b.div("id").to_s)
|
30
|
+
assert_equal("_sahi._div(\"id\", \"id2\")", @b.div("id", "id2").to_s())
|
31
|
+
assert_equal("_sahi._div(\"id1\", _sahi._near(_sahi._div(\"id2\")))", @b.div("id1").near(@b.div("id2")).to_s())
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_xy()
|
35
|
-
|
36
|
-
assert_equal("_sahi._xy(_sahi._div(\"id\"), 10, 20)",
|
35
|
+
@b = Sahi::Browser.new("", "", "")
|
36
|
+
assert_equal("_sahi._xy(_sahi._div(\"id\"), 10, 20)", @b.div("id").xy(10, 20).to_s)
|
37
37
|
end
|
38
|
+
|
39
|
+
def test_under_no_extra_params()
|
40
|
+
@b = Sahi::Browser.new("", "", "")
|
41
|
+
assert_equal("_sahi._cell(0, _sahi._under(_sahi._cell(\"Heading\")))", @b.cell(0).under(@b.cell("Heading")).to_s)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_right_of_no_extra_params()
|
45
|
+
@b = Sahi::Browser.new("", "", "")
|
46
|
+
assert_equal("_sahi._cell(0, _sahi._rightOf(_sahi._cell(\"Heading\")))", @b.cell(0).right_of(@b.cell("Heading")).to_s)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_left_of_no_extra_params()
|
50
|
+
@b = Sahi::Browser.new("", "", "")
|
51
|
+
assert_equal("_sahi._cell(0, _sahi._leftOf(_sahi._cell(\"Heading\")))", @b.cell(0).left_of(@b.cell("Heading")).to_s)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_left_or_right_of_no_extra_params()
|
55
|
+
@b = Sahi::Browser.new("", "", "")
|
56
|
+
assert_equal("_sahi._cell(0, _sahi._leftOrRightOf(_sahi._cell(\"Heading\")))", @b.cell(0).left_or_right_of(@b.cell("Heading")).to_s)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_above_no_extra_params()
|
60
|
+
@b = Sahi::Browser.new("", "", "")
|
61
|
+
assert_equal("_sahi._cell(0, _sahi._above(_sahi._cell(\"Heading\")))", @b.cell(0).above(@b.cell("Heading")).to_s)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_above_or_under_no_extra_params()
|
65
|
+
@b = Sahi::Browser.new("", "", "")
|
66
|
+
assert_equal("_sahi._cell(0, _sahi._aboveOrUnder(_sahi._cell(\"Heading\")))", @b.cell(0).above_or_under(@b.cell("Heading")).to_s)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_above_extra_params()
|
70
|
+
@b = Sahi::Browser.new("", "", "")
|
71
|
+
assert_equal("_sahi._cell(0, _sahi._above(_sahi._cell(\"Heading\"), [10,5], 20))", @b.cell(0).above(@b.cell("Heading"), [10,5], 20).to_s)
|
72
|
+
assert_equal("_sahi._cell(0, _sahi._above(_sahi._cell(\"Heading\"), 10, 20))", @b.cell(0).above(@b.cell("Heading"), 10, 20).to_s)
|
73
|
+
assert_equal("_sahi._cell(0, _sahi._above(_sahi._cell(\"Heading\"), 10, null))", @b.cell(0).above(@b.cell("Heading"), 10).to_s)
|
74
|
+
assert_equal("_sahi._cell(0, _sahi._above(_sahi._cell(\"Heading\"), null, 20))", @b.cell(0).above(@b.cell("Heading"), nil, 20).to_s)
|
75
|
+
assert_equal("_sahi._cell(0, _sahi._above(_sahi._cell(\"Heading\")))", @b.cell(0).above(@b.cell("Heading"), nil, nil).to_s)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_above_or_under_extra_params()
|
79
|
+
@b = Sahi::Browser.new("", "", "")
|
80
|
+
assert_equal("_sahi._cell(0, _sahi._aboveOrUnder(_sahi._cell(\"Heading\"), [10,5], 20))", @b.cell(0).above_or_under(@b.cell("Heading"), [10,5], 20).to_s)
|
81
|
+
assert_equal("_sahi._cell(0, _sahi._aboveOrUnder(_sahi._cell(\"Heading\"), 10, 20))", @b.cell(0).above_or_under(@b.cell("Heading"), 10, 20).to_s)
|
82
|
+
assert_equal("_sahi._cell(0, _sahi._aboveOrUnder(_sahi._cell(\"Heading\"), 10, null))", @b.cell(0).above_or_under(@b.cell("Heading"), 10).to_s)
|
83
|
+
assert_equal("_sahi._cell(0, _sahi._aboveOrUnder(_sahi._cell(\"Heading\"), null, 20))", @b.cell(0).above_or_under(@b.cell("Heading"), nil, 20).to_s)
|
84
|
+
assert_equal("_sahi._cell(0, _sahi._aboveOrUnder(_sahi._cell(\"Heading\")))", @b.cell(0).above_or_under(@b.cell("Heading"), nil, nil).to_s)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_under_extra_params()
|
88
|
+
@b = Sahi::Browser.new("", "", "")
|
89
|
+
assert_equal("_sahi._cell(0, _sahi._under(_sahi._cell(\"Heading\"), [10,5], 20))", @b.cell(0).under(@b.cell("Heading"), [10,5], 20).to_s)
|
90
|
+
assert_equal("_sahi._cell(0, _sahi._under(_sahi._cell(\"Heading\"), 10, 20))", @b.cell(0).under(@b.cell("Heading"), 10, 20).to_s)
|
91
|
+
assert_equal("_sahi._cell(0, _sahi._under(_sahi._cell(\"Heading\"), 10, null))", @b.cell(0).under(@b.cell("Heading"), 10).to_s)
|
92
|
+
assert_equal("_sahi._cell(0, _sahi._under(_sahi._cell(\"Heading\"), null, 20))", @b.cell(0).under(@b.cell("Heading"), nil, 20).to_s)
|
93
|
+
assert_equal("_sahi._cell(0, _sahi._under(_sahi._cell(\"Heading\")))", @b.cell(0).under(@b.cell("Heading"), nil, nil).to_s)
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_left_of_extra_params()
|
97
|
+
@b = Sahi::Browser.new("", "", "")
|
98
|
+
assert_equal("_sahi._cell(0, _sahi._leftOf(_sahi._cell(\"Heading\"), [10,5], 20))", @b.cell(0).left_of(@b.cell("Heading"), [10,5], 20).to_s)
|
99
|
+
assert_equal("_sahi._cell(0, _sahi._leftOf(_sahi._cell(\"Heading\"), 10, 20))", @b.cell(0).left_of(@b.cell("Heading"), 10, 20).to_s)
|
100
|
+
assert_equal("_sahi._cell(0, _sahi._leftOf(_sahi._cell(\"Heading\"), 10, null))", @b.cell(0).left_of(@b.cell("Heading"), 10).to_s)
|
101
|
+
assert_equal("_sahi._cell(0, _sahi._leftOf(_sahi._cell(\"Heading\"), null, 20))", @b.cell(0).left_of(@b.cell("Heading"), nil, 20).to_s)
|
102
|
+
assert_equal("_sahi._cell(0, _sahi._leftOf(_sahi._cell(\"Heading\")))", @b.cell(0).left_of(@b.cell("Heading"), nil, nil).to_s)
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_right_of_extra_params()
|
106
|
+
@b = Sahi::Browser.new("", "", "")
|
107
|
+
assert_equal("_sahi._cell(0, _sahi._rightOf(_sahi._cell(\"Heading\"), [10,5], 20))", @b.cell(0).right_of(@b.cell("Heading"), [10,5], 20).to_s)
|
108
|
+
assert_equal("_sahi._cell(0, _sahi._rightOf(_sahi._cell(\"Heading\"), 10, 20))", @b.cell(0).right_of(@b.cell("Heading"), 10, 20).to_s)
|
109
|
+
assert_equal("_sahi._cell(0, _sahi._rightOf(_sahi._cell(\"Heading\"), 10, null))", @b.cell(0).right_of(@b.cell("Heading"), 10).to_s)
|
110
|
+
assert_equal("_sahi._cell(0, _sahi._rightOf(_sahi._cell(\"Heading\"), null, 20))", @b.cell(0).right_of(@b.cell("Heading"), nil, 20).to_s)
|
111
|
+
assert_equal("_sahi._cell(0, _sahi._rightOf(_sahi._cell(\"Heading\")))", @b.cell(0).right_of(@b.cell("Heading"), nil, nil).to_s)
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_left_or_right_of_extra_params()
|
115
|
+
@b = Sahi::Browser.new("", "", "")
|
116
|
+
assert_equal("_sahi._cell(0, _sahi._leftOrRightOf(_sahi._cell(\"Heading\"), [10,5], 20))", @b.cell(0).left_or_right_of(@b.cell("Heading"), [10,5], 20).to_s)
|
117
|
+
assert_equal("_sahi._cell(0, _sahi._leftOrRightOf(_sahi._cell(\"Heading\"), 10, 20))", @b.cell(0).left_or_right_of(@b.cell("Heading"), 10, 20).to_s)
|
118
|
+
assert_equal("_sahi._cell(0, _sahi._leftOrRightOf(_sahi._cell(\"Heading\"), 10, null))", @b.cell(0).left_or_right_of(@b.cell("Heading"), 10).to_s)
|
119
|
+
assert_equal("_sahi._cell(0, _sahi._leftOrRightOf(_sahi._cell(\"Heading\"), null, 20))", @b.cell(0).left_or_right_of(@b.cell("Heading"), nil, 20).to_s)
|
120
|
+
assert_equal("_sahi._cell(0, _sahi._leftOrRightOf(_sahi._cell(\"Heading\")))", @b.cell(0).left_or_right_of(@b.cell("Heading"), nil, nil).to_s)
|
121
|
+
end
|
122
|
+
|
38
123
|
end
|
data/test/sahi_test.rb
CHANGED
@@ -3,15 +3,16 @@ require 'sahi'
|
|
3
3
|
|
4
4
|
class SahiDriverTest < Test::Unit::TestCase
|
5
5
|
def setup
|
6
|
-
|
7
|
-
|
6
|
+
@b = init_browser()
|
7
|
+
@browser = @b
|
8
|
+
@b.open
|
8
9
|
@base_url = "http://sahi.co.in"
|
9
10
|
end
|
10
11
|
|
11
12
|
def teardown
|
12
|
-
if @
|
13
|
-
@
|
14
|
-
@
|
13
|
+
if @b
|
14
|
+
@b.set_speed = 100
|
15
|
+
@b.close
|
15
16
|
sleep(1)
|
16
17
|
end
|
17
18
|
end
|
@@ -22,406 +23,454 @@ class SahiDriverTest < Test::Unit::TestCase
|
|
22
23
|
return Sahi::Browser.new(@browser_name)
|
23
24
|
end
|
24
25
|
|
25
|
-
|
26
26
|
def test1
|
27
|
-
@
|
28
|
-
@
|
29
|
-
@
|
30
|
-
@
|
31
|
-
assert_equal("Cell with id", @
|
27
|
+
@b.navigate_to(@base_url + "/demo/formTest.htm")
|
28
|
+
@b.textbox("t1").value = "aaa"
|
29
|
+
@b.link("Back").click
|
30
|
+
@b.link("Table Test").click
|
31
|
+
assert_equal("Cell with id", @b.cell("CellWithId").text)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_file_upload_native_events
|
35
|
+
@b.navigate_to("http://sahi.co.in/demo/")
|
36
|
+
@b.link("File Upload Test").click
|
37
|
+
@b.wait(5) {@b.file("file").visible?}
|
38
|
+
@b.window_action("focus")
|
39
|
+
# focus on the element
|
40
|
+
@b.file("file").focus()
|
41
|
+
@b.wait(5)
|
42
|
+
@b.type_key_code_native(32)
|
43
|
+
@b.wait(7)
|
44
|
+
# type the file path
|
45
|
+
@b.type_native("D:\\abc.txt")
|
46
|
+
@b.wait(1)
|
47
|
+
# press enter
|
48
|
+
@b.type_key_code_native(10)
|
49
|
+
@b.wait(5)
|
50
|
+
@b.submit("Submit Single").click
|
51
|
+
assert(@b.span("abc.txt").exists?)
|
52
|
+
assert(@b.span("abc.txt").visible?)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_select_text_range()
|
56
|
+
@b.navigate_to("http://developer.yahoo.com/yui/examples/editor/icon_editor_clean.html")
|
57
|
+
@b.rte(1).select_text_range("his is some more[1]", "before")
|
58
|
+
@b.link("Insert Image").click
|
59
|
+
|
60
|
+
@b.navigate_to("http://developer.yahoo.com/yui/examples/editor/icon_editor_clean.html",true)
|
61
|
+
@b.rte(1).select_text_range("This is some more[3]", "before")
|
62
|
+
@b.link("Insert Image").click
|
63
|
+
|
64
|
+
@b.navigate_to("http://developer.yahoo.com/yui/examples/editor/icon_editor_clean.html",true)
|
65
|
+
@b.rte(1).select_text_range("This is some more[3]")
|
66
|
+
@b.link("Insert Image").click
|
32
67
|
end
|
33
68
|
|
34
69
|
def xtest_ZK
|
35
|
-
@
|
36
|
-
@
|
37
|
-
@
|
38
|
-
@
|
39
|
-
@
|
40
|
-
@
|
70
|
+
@b.speed = 200
|
71
|
+
@b.navigate_to("http://www.zkoss.org/zkdemo/userguide/")
|
72
|
+
@b.div("Hello World").click
|
73
|
+
@b.span("Pure Java").click
|
74
|
+
@b.div("Various Form").click
|
75
|
+
@b.wait(5000) {@b.textbox("z-intbox[1]").visible?}
|
41
76
|
|
42
|
-
@
|
43
|
-
@
|
44
|
-
@
|
45
|
-
@
|
77
|
+
@b.div("Comboboxes").click
|
78
|
+
@b.textbox("z-combobox-inp").value = "aa"
|
79
|
+
@b.italic("z-combobox-btn").click
|
80
|
+
@b.cell("Simple and Rich").click
|
46
81
|
|
47
|
-
@
|
48
|
-
@
|
49
|
-
@
|
50
|
-
@
|
51
|
-
assert(@
|
82
|
+
@b.italic("z-combobox-btn[1]").click
|
83
|
+
@b.span("The coolest technology").click
|
84
|
+
@b.italic("z-combobox-btn[2]").click
|
85
|
+
@b.image("CogwheelEye-32x32.gif").click
|
86
|
+
assert(@b.textbox("z-combobox-inp[2]").exists?)
|
52
87
|
end
|
53
88
|
|
54
89
|
|
55
90
|
def test_fetch()
|
56
|
-
@
|
57
|
-
assert_equal(@base_url + "/demo/formTest.htm", @
|
91
|
+
@b.navigate_to(@base_url + "/demo/formTest.htm")
|
92
|
+
assert_equal(@base_url + "/demo/formTest.htm", @b.fetch("window.location.href"))
|
58
93
|
end
|
59
94
|
|
60
95
|
def test_accessors()
|
61
|
-
@
|
62
|
-
assert_equal("", @
|
63
|
-
assert(@
|
64
|
-
assert(@
|
65
|
-
@
|
66
|
-
assert_equal("", @
|
67
|
-
assert(@
|
68
|
-
assert_equal("", @
|
69
|
-
assert(@
|
70
|
-
assert_equal("", @
|
71
|
-
assert(@
|
72
|
-
assert_equal("cv1", @
|
73
|
-
assert(@
|
74
|
-
assert_equal("cv2", @
|
75
|
-
assert(@
|
76
|
-
assert_equal("cv3", @
|
77
|
-
assert(@
|
78
|
-
assert_equal("", @
|
79
|
-
assert(@
|
80
|
-
assert_equal("rv1", @
|
81
|
-
assert(@
|
82
|
-
assert_equal("", @
|
83
|
-
assert(@
|
84
|
-
assert_equal("", @
|
85
|
-
assert(@
|
86
|
-
assert_equal("o1", @
|
87
|
-
assert(@
|
88
|
-
assert_equal("o1", @
|
89
|
-
assert(@
|
90
|
-
assert_equal("o1", @
|
91
|
-
assert(@
|
92
|
-
assert(@
|
93
|
-
assert(@
|
94
|
-
assert(@
|
95
|
-
assert(@
|
96
|
-
assert(@
|
97
|
-
assert(@
|
98
|
-
assert(@
|
99
|
-
assert(@
|
100
|
-
assert(@
|
101
|
-
assert(@
|
102
|
-
assert(!@
|
103
|
-
assert(@
|
104
|
-
assert(@
|
96
|
+
@b.navigate_to(@base_url + "/demo/formTest.htm")
|
97
|
+
assert_equal("", @b.textbox("t1").value)
|
98
|
+
assert(@b.textbox(1).exists?)
|
99
|
+
assert(@b.textbox("$a_dollar").exists?)
|
100
|
+
@b.textbox("$a_dollar").value = ("adas")
|
101
|
+
assert_equal("", @b.textbox(1).value)
|
102
|
+
assert(@b.textarea("ta1").exists?)
|
103
|
+
assert_equal("", @b.textarea("ta1").value)
|
104
|
+
assert(@b.textarea(1).exists?)
|
105
|
+
assert_equal("", @b.textarea(1).value)
|
106
|
+
assert(@b.checkbox("c1").exists?)
|
107
|
+
assert_equal("cv1", @b.checkbox("c1").value)
|
108
|
+
assert(@b.checkbox(1).exists?)
|
109
|
+
assert_equal("cv2", @b.checkbox(1).value)
|
110
|
+
assert(@b.checkbox("c1[1]").exists?)
|
111
|
+
assert_equal("cv3", @b.checkbox("c1[1]").value)
|
112
|
+
assert(@b.checkbox(3).exists?)
|
113
|
+
assert_equal("", @b.checkbox(3).value)
|
114
|
+
assert(@b.radio("r1").exists?)
|
115
|
+
assert_equal("rv1", @b.radio("r1").value)
|
116
|
+
assert(@b.password("p1").exists?)
|
117
|
+
assert_equal("", @b.password("p1").value)
|
118
|
+
assert(@b.password(1).exists?)
|
119
|
+
assert_equal("", @b.password(1).value)
|
120
|
+
assert(@b.select("s1").exists?)
|
121
|
+
assert_equal("o1", @b.select("s1").selected_text())
|
122
|
+
assert(@b.select("s1Id[1]").exists?)
|
123
|
+
assert_equal("o1", @b.select("s1Id[1]").selected_text())
|
124
|
+
assert(@b.select(2).exists?)
|
125
|
+
assert_equal("o1", @b.select(2).selected_text())
|
126
|
+
assert(@b.button("button value").exists?)
|
127
|
+
assert(@b.button("btnName[1]").exists?)
|
128
|
+
assert(@b.button("btnId[2]").exists?)
|
129
|
+
assert(@b.button(3).exists?)
|
130
|
+
assert(@b.submit("Add").exists?)
|
131
|
+
assert(@b.submit("submitBtnName[1]").exists?)
|
132
|
+
assert(@b.submit("submitBtnId[2]").exists?)
|
133
|
+
assert(@b.submit(3).exists?)
|
134
|
+
assert(@b.image("imageAlt1").exists?)
|
135
|
+
assert(@b.image("imageId1[1]").exists?)
|
136
|
+
assert(@b.image(2).exists?)
|
137
|
+
assert(!@b.link("Back22").exists?)
|
138
|
+
assert(@b.link("Back").exists?)
|
139
|
+
assert(@b.accessor("document.getElementById('s1Id')").exists?)
|
105
140
|
end
|
106
141
|
|
107
142
|
def test_select()
|
108
|
-
@
|
109
|
-
assert_equal("o1", @
|
110
|
-
@
|
111
|
-
assert_equal("o2", @
|
112
|
-
@
|
113
|
-
assert_equal("o1,o3", @
|
143
|
+
@b.navigate_to(@base_url + "/demo/formTest.htm")
|
144
|
+
assert_equal("o1", @b.select("s1Id[1]").selected_text())
|
145
|
+
@b.select("s1Id[1]").choose("o2")
|
146
|
+
assert_equal("o2", @b.select("s1Id[1]").selected_text())
|
147
|
+
@b.select(3).choose(["o1", "o3"])
|
148
|
+
assert_equal("o1,o3", @b.select(3).selected_text())
|
114
149
|
end
|
115
150
|
|
116
151
|
def test_set_file()
|
117
|
-
@
|
118
|
-
@
|
119
|
-
@
|
120
|
-
assert(@
|
121
|
-
assert_not_nil(@
|
122
|
-
assert_not_nil(@
|
123
|
-
@
|
152
|
+
@b.navigate_to(@base_url + "/demo/php/fileUpload.htm")
|
153
|
+
@b.file("file").file = "scripts/demo/uploadme.txt";
|
154
|
+
@b.submit("Submit Single").click;
|
155
|
+
assert(@b.span("size").exists?)
|
156
|
+
assert_not_nil(@b.span("size").text().index("0.3046875 Kb"))
|
157
|
+
assert_not_nil(@b.span("type").text().index("Single"))
|
158
|
+
@b.link("Back to form").click;
|
124
159
|
end
|
125
160
|
|
126
161
|
def test_multi_file_upload()
|
127
|
-
@
|
128
|
-
@
|
129
|
-
@
|
130
|
-
@
|
131
|
-
assert_not_nil(@
|
132
|
-
assert_not_nil(@
|
133
|
-
assert_not_nil(@
|
162
|
+
@b.navigate_to(@base_url + "/demo/php/fileUpload.htm")
|
163
|
+
@b.file("file[]").file = "scripts/demo/uploadme.txt";
|
164
|
+
@b.file("file[]").file = "scripts/demo/uploadme2.txt";
|
165
|
+
@b.submit("Submit Array").click;
|
166
|
+
assert_not_nil(@b.span("type").text().index("Array"))
|
167
|
+
assert_not_nil(@b.span("file").text().index("uploadme.txt"))
|
168
|
+
assert_not_nil(@b.span("size").text().index("0.3046875 Kb"))
|
134
169
|
|
135
|
-
assert_not_nil(@
|
136
|
-
assert_not_nil(@
|
170
|
+
assert_not_nil(@b.span("file[1]").text().index("uploadme2.txt"))
|
171
|
+
assert_not_nil(@b.span("size[1]").text().index("0.32421875 Kb"))
|
137
172
|
end
|
138
173
|
|
139
174
|
def test_clicks()
|
140
|
-
@
|
141
|
-
assert_not_nil(@
|
142
|
-
@
|
143
|
-
assert_equal("true", @
|
144
|
-
@
|
145
|
-
assert_equal("false", @
|
175
|
+
@b.navigate_to(@base_url + "/demo/formTest.htm")
|
176
|
+
assert_not_nil(@b.checkbox("c1"))
|
177
|
+
@b.checkbox("c1").click;
|
178
|
+
assert_equal("true", @b.checkbox("c1").fetch("checked"))
|
179
|
+
@b.checkbox("c1").click;
|
180
|
+
assert_equal("false", @b.checkbox("c1").fetch("checked"))
|
146
181
|
|
147
|
-
assert_not_nil(@
|
148
|
-
@
|
149
|
-
assert_equal("true", @
|
150
|
-
assert(@
|
151
|
-
assert(!@
|
152
|
-
@
|
153
|
-
assert_equal("false", @
|
154
|
-
assert(@
|
155
|
-
assert(!@
|
182
|
+
assert_not_nil(@b.radio("r1"))
|
183
|
+
@b.radio("r1").click;
|
184
|
+
assert_equal("true", @b.radio("r1").fetch("checked"))
|
185
|
+
assert(@b.radio("r1").checked?)
|
186
|
+
assert(!@b.radio("r1[1]").checked?)
|
187
|
+
@b.radio("r1[1]").click;
|
188
|
+
assert_equal("false", @b.radio("r1").fetch("checked"))
|
189
|
+
assert(@b.radio("r1[1]").checked?)
|
190
|
+
assert(!@b.radio("r1").checked?)
|
156
191
|
end
|
157
192
|
|
158
193
|
def test_links()
|
159
|
-
@
|
160
|
-
@
|
161
|
-
@
|
162
|
-
@
|
163
|
-
@
|
164
|
-
assert(@
|
165
|
-
assert_equal("", @
|
166
|
-
@
|
167
|
-
@
|
168
|
-
@
|
169
|
-
assert(@
|
170
|
-
assert_equal("formTest link with return false", @
|
171
|
-
assert(@
|
194
|
+
@b.navigate_to(@base_url + "/demo/index.htm")
|
195
|
+
@b.link("Link Test").click;
|
196
|
+
@b.link("linkByContent").click;
|
197
|
+
@b.link("Back").click;
|
198
|
+
@b.link("link with return true").click;
|
199
|
+
assert(@b.textarea("ta1").exists?)
|
200
|
+
assert_equal("", @b.textarea("ta1").value)
|
201
|
+
@b.link("Back").click;
|
202
|
+
@b.link("Link Test").click;
|
203
|
+
@b.link("link with return false").click;
|
204
|
+
assert(@b.textbox("t1").exists?)
|
205
|
+
assert_equal("formTest link with return false", @b.textbox("t1").value)
|
206
|
+
assert(@b.link("linkByContent").exists?)
|
172
207
|
|
173
|
-
@
|
174
|
-
assert(@
|
175
|
-
assert_equal("formTest link with returnValue=false", @
|
176
|
-
@
|
177
|
-
assert(@
|
178
|
-
assert_equal("myFn called", @
|
179
|
-
@
|
180
|
-
@
|
181
|
-
@
|
182
|
-
@
|
183
|
-
assert(@
|
184
|
-
assert_equal("myFn called", @
|
185
|
-
@
|
208
|
+
@b.link("link with returnValue=false").click;
|
209
|
+
assert(@b.textbox("t1").exists?)
|
210
|
+
assert_equal("formTest link with returnValue=false", @b.textbox("t1").value)
|
211
|
+
@b.link("added handler using js").click;
|
212
|
+
assert(@b.textbox("t1").exists?)
|
213
|
+
assert_equal("myFn called", @b.textbox("t1").value)
|
214
|
+
@b.textbox("t1").value = ("")
|
215
|
+
@b.image("imgWithLink").click;
|
216
|
+
@b.link("Link Test").click;
|
217
|
+
@b.image("imgWithLinkNoClick").click;
|
218
|
+
assert(@b.textbox("t1").exists?)
|
219
|
+
assert_equal("myFn called", @b.textbox("t1").value)
|
220
|
+
@b.link("Back").click;
|
186
221
|
end
|
187
222
|
|
188
223
|
|
189
224
|
def test_popup_title_name_mix()
|
190
|
-
@
|
191
|
-
@
|
192
|
-
@
|
193
|
-
@
|
225
|
+
@b.navigate_to(@base_url + "/demo/index.htm")
|
226
|
+
@b.link("Window Open Test").click;
|
227
|
+
@b.link("Window Open Test With Title").click;
|
228
|
+
@b.link("Table Test").click;
|
194
229
|
|
195
|
-
popup_popwin = @
|
230
|
+
popup_popwin = @b.popup("popWin")
|
196
231
|
|
197
232
|
popup_popwin.link("Link Test").click;
|
198
|
-
@
|
233
|
+
@b.link("Back").click;
|
199
234
|
|
200
|
-
popup_with_title = @
|
235
|
+
popup_with_title = @b.popup("With Title")
|
201
236
|
|
202
237
|
popup_with_title.link("Form Test").click;
|
203
|
-
@
|
238
|
+
@b.link("Table Test").click;
|
204
239
|
popup_with_title.textbox("t1").value = ("d")
|
205
|
-
@
|
240
|
+
@b.link("Back").click;
|
206
241
|
popup_with_title.textbox(1).value = ("e")
|
207
|
-
@
|
242
|
+
@b.link("Table Test").click;
|
208
243
|
popup_with_title.textbox("name").value = ("f")
|
209
244
|
assert_not_nil(popup_popwin.link("linkByHtml").exists?)
|
210
245
|
|
211
|
-
assert_not_nil(@
|
212
|
-
assert_equal("Cell with id", @
|
246
|
+
assert_not_nil(@b.cell("CellWithId"))
|
247
|
+
assert_equal("Cell with id", @b.cell("CellWithId").text)
|
213
248
|
popup_with_title.link("Break Frames").click;
|
214
249
|
|
215
|
-
popupSahiTests = @
|
250
|
+
popupSahiTests = @b.popup("Sahi Tests")
|
216
251
|
popupSahiTests.close()
|
217
252
|
|
218
253
|
popup_popwin.link("Break Frames").click;
|
219
254
|
popup_popwin.close()
|
220
|
-
@
|
255
|
+
@b.link("Back").click;
|
221
256
|
end
|
222
257
|
|
223
258
|
|
224
259
|
def test_in()
|
225
|
-
@
|
226
|
-
assert_equal("111", @
|
227
|
-
assert_equal("222", @
|
228
|
-
assert_equal("3", @
|
229
|
-
@
|
230
|
-
assert(@
|
260
|
+
@b.navigate_to(@base_url + "/demo/tableTest.htm")
|
261
|
+
assert_equal("111", @b.textarea("ta").near(@b.cell("a1")).value)
|
262
|
+
assert_equal("222", @b.textarea("ta").near(@b.cell("a2")).value)
|
263
|
+
assert_equal("3", @b.table(0).fetch("rows.length"))
|
264
|
+
@b.link("Go back").in(@b.cell("a1").parent_node()).click;
|
265
|
+
assert(@b.link("Link Test").exists?)
|
231
266
|
end
|
232
267
|
|
233
268
|
def test_under()
|
234
|
-
@
|
235
|
-
assert_equal("x1-2", @
|
236
|
-
assert_equal("x1-3", @
|
269
|
+
@b.navigate_to(@base_url + "/demo/tableTest.htm")
|
270
|
+
assert_equal("x1-2", @b.cell(0).near(@b.cell("x1-0")).under(@b.tableHeader("header 3")).text())
|
271
|
+
assert_equal("x1-3", @b.cell(0).near(@b.cell("x1-0")).under(@b.tableHeader("header 4")).text())
|
237
272
|
end
|
238
273
|
|
239
274
|
def test_exists()
|
240
|
-
@
|
241
|
-
assert(@
|
242
|
-
assert(!@
|
243
|
-
end
|
275
|
+
@b.navigate_to(@base_url + "/demo/index.htm")
|
276
|
+
assert(@b.link("Link Test").exists?)
|
277
|
+
assert(!@b.link("Link Test NonExistent").exists?)
|
278
|
+
end
|
279
|
+
|
280
|
+
def test_range()
|
281
|
+
@b.navigate_to(@base_url + "/demo/")
|
282
|
+
@b.link("Form Test").click
|
283
|
+
@b.textarea("ta1").value = "abcdefgh";
|
284
|
+
@b.textarea("ta1").select_range(2,4)
|
285
|
+
assert_equal("cd", @b.selection_text())
|
286
|
+
@b.navigate_to(@base_url + "/demo/", true)
|
287
|
+
@b.link("IFrames Test").click
|
288
|
+
@b.link("Form Test").click
|
289
|
+
@b.textarea("ta1").value = "abcdefgh"
|
290
|
+
@b.textarea("ta1").select_range(2, 4)
|
291
|
+
assert_equal("cd", @b.selection_text())
|
292
|
+
end
|
244
293
|
|
245
294
|
def alert1(message)
|
246
|
-
@
|
247
|
-
@
|
248
|
-
@
|
249
|
-
@
|
295
|
+
@b.navigate_to(@base_url + "/demo/alertTest.htm")
|
296
|
+
@b.textbox("t1").value = ("Message " + message)
|
297
|
+
@b.button("Click For Alert").click;
|
298
|
+
@b.navigate_to("/demo/alertTest.htm")
|
250
299
|
sleep(1)
|
251
|
-
assert_equal("Message " + message, @
|
252
|
-
@
|
253
|
-
assert_nil(@
|
300
|
+
assert_equal("Message " + message, @b.last_alert())
|
301
|
+
@b.clear_last_alert()
|
302
|
+
assert_nil(@b.last_alert())
|
254
303
|
end
|
255
304
|
|
256
305
|
def test_alert()
|
257
306
|
alert1("One")
|
258
307
|
alert1("Two")
|
259
308
|
alert1("Three")
|
260
|
-
@
|
261
|
-
assert_equal("You must correct the following Errors:\nYou must select a messaging price plan.\nYou must select an international messaging price plan.\nYou must enter a value for the Network Lookup Charge", @
|
309
|
+
@b.button("Click For Multiline Alert").click;
|
310
|
+
assert_equal("You must correct the following Errors:\nYou must select a messaging price plan.\nYou must select an international messaging price plan.\nYou must enter a value for the Network Lookup Charge", @b.last_alert())
|
262
311
|
end
|
263
312
|
|
264
313
|
def test_confirm()
|
265
|
-
@
|
266
|
-
@
|
267
|
-
@
|
268
|
-
assert_equal("oked", @
|
269
|
-
@
|
314
|
+
@b.navigate_to(@base_url + "/demo/confirmTest.htm")
|
315
|
+
@b.expect_confirm("Some question?", true)
|
316
|
+
@b.button("Click For Confirm").click;
|
317
|
+
assert_equal("oked", @b.textbox("t1").value)
|
318
|
+
@b.navigate_to("/demo/confirmTest.htm")
|
270
319
|
sleep(1)
|
271
|
-
assert_equal("Some question?", @
|
272
|
-
@
|
273
|
-
assert_nil(@
|
320
|
+
assert_equal("Some question?", @b.last_confirm())
|
321
|
+
@b.clear_last_confirm()
|
322
|
+
assert_nil(@b.last_confirm())
|
274
323
|
|
275
|
-
@
|
276
|
-
@
|
277
|
-
assert_equal("canceled", @
|
278
|
-
assert_equal("Some question?", @
|
279
|
-
@
|
280
|
-
assert_nil(@
|
324
|
+
@b.expect_confirm("Some question?", false)
|
325
|
+
@b.button("Click For Confirm").click;
|
326
|
+
assert_equal("canceled", @b.textbox("t1").value)
|
327
|
+
assert_equal("Some question?", @b.last_confirm())
|
328
|
+
@b.clear_last_confirm()
|
329
|
+
assert_nil(@b.last_confirm())
|
281
330
|
|
282
|
-
@
|
283
|
-
@
|
284
|
-
assert_equal("oked", @
|
285
|
-
assert_equal("Some question?", @
|
286
|
-
@
|
287
|
-
assert_nil(@
|
331
|
+
@b.expect_confirm("Some question?", true)
|
332
|
+
@b.button("Click For Confirm").click;
|
333
|
+
assert_equal("oked", @b.textbox("t1").value)
|
334
|
+
assert_equal("Some question?", @b.last_confirm())
|
335
|
+
@b.clear_last_confirm()
|
336
|
+
assert_nil(@b.last_confirm())
|
288
337
|
end
|
289
338
|
|
290
339
|
def test_prompt()
|
291
|
-
@
|
292
|
-
@
|
293
|
-
@
|
294
|
-
assert_not_nil(@
|
295
|
-
assert_equal("abc", @
|
296
|
-
@
|
297
|
-
@
|
298
|
-
assert_equal("Some prompt?", @
|
299
|
-
@
|
300
|
-
assert_nil(@
|
340
|
+
@b.navigate_to(@base_url + "/demo/promptTest.htm")
|
341
|
+
@b.expect_prompt("Some prompt?", "abc")
|
342
|
+
@b.button("Click For Prompt").click;
|
343
|
+
assert_not_nil(@b.textbox("t1"))
|
344
|
+
assert_equal("abc", @b.textbox("t1").value)
|
345
|
+
@b.navigate_to("/demo/promptTest.htm")
|
346
|
+
@b.wait(2000)
|
347
|
+
assert_equal("Some prompt?", @b.last_prompt())
|
348
|
+
@b.clear_last_prompt()
|
349
|
+
assert_nil(@b.last_prompt())
|
301
350
|
end
|
302
351
|
|
303
352
|
|
304
353
|
def test_visible
|
305
|
-
@
|
306
|
-
@
|
307
|
-
assert(@
|
354
|
+
@b.navigate_to(@base_url + "/demo/index.htm")
|
355
|
+
@b.link("Visible Test").click;
|
356
|
+
assert(@b.spandiv("using display").visible?)
|
308
357
|
|
309
|
-
@
|
310
|
-
assert(!@
|
311
|
-
@
|
312
|
-
assert(@
|
358
|
+
@b.button("Display none").click;
|
359
|
+
assert(!@b.spandiv("using display").visible?)
|
360
|
+
@b.button("Display block").click;
|
361
|
+
assert(@b.spandiv("using display").visible?)
|
313
362
|
|
314
|
-
@
|
315
|
-
assert(!@
|
316
|
-
@
|
317
|
-
assert(@
|
363
|
+
@b.button("Display none").click;
|
364
|
+
assert(!@b.spandiv("using display").visible?)
|
365
|
+
@b.button("Display inline").click;
|
366
|
+
assert(@b.spandiv("using display").visible?)
|
318
367
|
|
319
|
-
assert(@
|
320
|
-
@
|
321
|
-
assert(!@
|
322
|
-
@
|
323
|
-
assert(@
|
368
|
+
assert(@b.spandiv("using visibility").visible?)
|
369
|
+
@b.button("Visibility hidden").click;
|
370
|
+
assert(!@b.spandiv("using visibility").visible?)
|
371
|
+
@b.button("Visibility visible").click;
|
372
|
+
assert(@b.spandiv("using visibility").visible?)
|
324
373
|
|
325
|
-
assert(!@
|
326
|
-
assert(!@
|
374
|
+
assert(!@b.byId("nestedBlockInNone").visible?)
|
375
|
+
assert(!@b.byId("absoluteNestedBlockInNone").visible?)
|
327
376
|
end
|
328
377
|
|
329
378
|
def test_check()
|
330
|
-
@
|
331
|
-
@
|
332
|
-
assert_equal("false", @
|
333
|
-
assert(!@
|
334
|
-
@
|
335
|
-
assert_equal("true", @
|
336
|
-
assert(@
|
337
|
-
@
|
338
|
-
assert_equal("true", @
|
339
|
-
@
|
340
|
-
assert_equal("false", @
|
341
|
-
@
|
342
|
-
assert_equal("false", @
|
343
|
-
@
|
344
|
-
assert_equal("true", @
|
379
|
+
@b.navigate_to(@base_url + "/demo/")
|
380
|
+
@b.link("Form Test").click;
|
381
|
+
assert_equal("false", @b.checkbox("c1").fetch("checked"))
|
382
|
+
assert(!@b.checkbox("c1").checked?)
|
383
|
+
@b.checkbox("c1").check()
|
384
|
+
assert_equal("true", @b.checkbox("c1").fetch("checked"))
|
385
|
+
assert(@b.checkbox("c1").checked?)
|
386
|
+
@b.checkbox("c1").check()
|
387
|
+
assert_equal("true", @b.checkbox("c1").fetch("checked"))
|
388
|
+
@b.checkbox("c1").uncheck()
|
389
|
+
assert_equal("false", @b.checkbox("c1").fetch("checked"))
|
390
|
+
@b.checkbox("c1").uncheck()
|
391
|
+
assert_equal("false", @b.checkbox("c1").fetch("checked"))
|
392
|
+
@b.checkbox("c1").click;
|
393
|
+
assert_equal("true", @b.checkbox("c1").fetch("checked"))
|
345
394
|
end
|
346
395
|
|
347
396
|
def test_focus()
|
348
|
-
@
|
349
|
-
@
|
350
|
-
assert_equal("focused", @
|
351
|
-
@
|
352
|
-
assert_equal("not focused", @
|
353
|
-
@
|
354
|
-
assert_equal("focused", @
|
397
|
+
@b.navigate_to(@base_url + "/demo/focusTest.htm")
|
398
|
+
@b.textbox("t2").focus()
|
399
|
+
assert_equal("focused", @b.textbox("t1").value)
|
400
|
+
@b.textbox("t2").remove_focus()
|
401
|
+
assert_equal("not focused", @b.textbox("t1").value)
|
402
|
+
@b.textbox("t2").focus()
|
403
|
+
assert_equal("focused", @b.textbox("t1").value)
|
355
404
|
end
|
356
405
|
|
357
406
|
def test_title()
|
358
|
-
@
|
359
|
-
assert_equal("Sahi Tests", @
|
360
|
-
@
|
361
|
-
assert_equal("Form Test", @
|
362
|
-
@
|
363
|
-
@
|
364
|
-
assert_equal("With Title", @
|
407
|
+
@b.navigate_to(@base_url + "/demo/index.htm")
|
408
|
+
assert_equal("Sahi Tests", @b.title)
|
409
|
+
@b.link("Form Test").click;
|
410
|
+
assert_equal("Form Test", @b.title)
|
411
|
+
@b.link("Back").click;
|
412
|
+
@b.link("Window Open Test With Title").click;
|
413
|
+
assert_equal("With Title", @b.popup("With Title").title)
|
365
414
|
end
|
366
415
|
|
367
416
|
def test_area()
|
368
|
-
@
|
369
|
-
@
|
370
|
-
assert(@
|
371
|
-
assert(@
|
372
|
-
assert(@
|
373
|
-
assert(@
|
374
|
-
@
|
375
|
-
assert_equal("Record", @
|
376
|
-
@
|
377
|
-
assert_equal("", @
|
378
|
-
@
|
379
|
-
assert(@
|
380
|
-
#@
|
417
|
+
@b.navigate_to(@base_url + "/demo/map.htm")
|
418
|
+
@b.navigate_to("map.htm")
|
419
|
+
assert(@b.area("Record").exists?)
|
420
|
+
assert(@b.area("Playback").exists?)
|
421
|
+
assert(@b.area("Info").exists?)
|
422
|
+
assert(@b.area("Circular").exists?)
|
423
|
+
@b.area("Record").mouse_over()
|
424
|
+
assert_equal("Record", @b.div("output").text)
|
425
|
+
@b.button("Clear").mouse_over()
|
426
|
+
assert_equal("", @b.div("output").text)
|
427
|
+
@b.area("Record").click;
|
428
|
+
assert(@b.link("linkByContent").exists?)
|
429
|
+
#@b.navigate_to("map.htm")
|
381
430
|
end
|
382
431
|
|
383
432
|
def test_dragdrop()
|
384
|
-
@
|
385
|
-
@
|
386
|
-
assert @
|
387
|
-
assert @
|
388
|
-
assert @
|
389
|
-
assert @
|
433
|
+
@b.navigate_to("http://www.snook.ca/technical/mootoolsdragdrop/")
|
434
|
+
@b.div("Drag me").drag_and_drop_on(@b.xy(@b.div("Item 2"), 5, 5))
|
435
|
+
assert @b.div("dropped").exists?
|
436
|
+
assert @b.div("Item 1").exists?
|
437
|
+
assert @b.div("Item 3").exists?
|
438
|
+
assert @b.div("Item 4").exists?
|
390
439
|
end
|
391
440
|
|
392
441
|
def test_wait()
|
393
|
-
@
|
394
|
-
@
|
395
|
-
assert_equal("populated", @
|
442
|
+
@b.navigate_to(@base_url + "/demo/waitCondition1.htm")
|
443
|
+
@b.wait(15) {"populated" == @b.textbox("t1").value}
|
444
|
+
assert_equal("populated", @b.textbox("t1").value)
|
396
445
|
end
|
397
446
|
|
398
447
|
def test_google()
|
399
|
-
@
|
400
|
-
@
|
401
|
-
@
|
402
|
-
@
|
403
|
-
assert @
|
448
|
+
@b.navigate_to("http://www.google.com")
|
449
|
+
@b.textbox("q").value = "sahi forums"
|
450
|
+
@b.submit("Google Search").click
|
451
|
+
@b.link("Sign In").click
|
452
|
+
assert @b.textbox("Form/Email").visible?
|
404
453
|
end
|
405
454
|
|
406
455
|
def test_dblclick()
|
407
|
-
@
|
408
|
-
@
|
409
|
-
assert_equal("[DOUBLE_CLICK]", @
|
410
|
-
@
|
456
|
+
@b.navigate_to("#{@base_url}/demo/clicks.htm")
|
457
|
+
@b.div("dbl click me").dblclick
|
458
|
+
assert_equal("[DOUBLE_CLICK]", @b.textarea("t2").value)
|
459
|
+
@b.button("Clear").click
|
411
460
|
end
|
412
461
|
|
413
462
|
def test_right_click()
|
414
|
-
@
|
415
|
-
@
|
416
|
-
assert_equal("[RIGHT_CLICK]", @
|
417
|
-
@
|
463
|
+
@b.navigate_to("#{@base_url}/demo/clicks.htm")
|
464
|
+
@b.div("right click me").right_click
|
465
|
+
assert_equal("[RIGHT_CLICK]", @b.textarea("t2").value)
|
466
|
+
@b.button("Clear").click
|
418
467
|
end
|
419
468
|
|
420
469
|
def test_different_domains()
|
421
|
-
@
|
422
|
-
@
|
423
|
-
domain_tyto = @
|
424
|
-
domain_bing = @
|
470
|
+
@b.navigate_to("#{@base_url}/demo/")
|
471
|
+
@b.link("Different Domains External").click
|
472
|
+
domain_tyto = @b.domain("www.tytosoftware.com")
|
473
|
+
domain_bing = @b.domain("www.bing.com")
|
425
474
|
|
426
475
|
domain_tyto.link("Link Test").click
|
427
476
|
domain_bing.textbox("q").value = "fdsfsd"
|
@@ -429,79 +478,139 @@ class SahiDriverTest < Test::Unit::TestCase
|
|
429
478
|
domain_tyto.link("Back").click
|
430
479
|
domain_bing.div("bgDiv").click
|
431
480
|
|
432
|
-
@
|
481
|
+
@b.navigate_to("#{@base_url}/demo/");
|
433
482
|
end
|
434
483
|
|
435
484
|
def test_browser_types()
|
436
|
-
@
|
485
|
+
@b.navigate_to("#{@base_url}/demo/")
|
437
486
|
if (@browser_name == "firefox")
|
438
|
-
assert(!@
|
439
|
-
assert(@
|
487
|
+
assert(!@b.ie?())
|
488
|
+
assert(@b.firefox?())
|
440
489
|
elsif (@browser_name == "ie")
|
441
|
-
assert(@
|
442
|
-
assert(!@
|
490
|
+
assert(@b.ie?())
|
491
|
+
assert(!@b.firefox?())
|
443
492
|
end
|
444
493
|
end
|
445
494
|
|
446
495
|
def test_browser_js()
|
447
|
-
@
|
448
|
-
@
|
449
|
-
assert_equal("23", @
|
450
|
-
@
|
451
|
-
assert_equal("23", @
|
452
|
-
@
|
496
|
+
@b.browser_js = "function giveMyNumber(){return '23';}"
|
497
|
+
@b.navigate_to("#{@base_url}/demo/")
|
498
|
+
assert_equal("23", @b.fetch("giveMyNumber()"))
|
499
|
+
@b.link("Link Test").click()
|
500
|
+
assert_equal("23", @b.fetch("giveMyNumber()"))
|
501
|
+
@b.link("Back").click()
|
453
502
|
end
|
454
503
|
|
455
504
|
def test_count()
|
456
|
-
@
|
457
|
-
assert_equal(4, @
|
458
|
-
assert_equal(0, @
|
459
|
-
assert_equal(5, @
|
460
|
-
assert_equal(2, @
|
505
|
+
@b.navigate_to("#{@base_url}/demo/count.htm")
|
506
|
+
assert_equal(4, @b.link("group 0 link").count_similar())
|
507
|
+
assert_equal(0, @b.link("group non existent link").count_similar());
|
508
|
+
assert_equal(5, @b.link("/group 1/").count_similar());
|
509
|
+
assert_equal(2, @b.link("/group 1/").in(@b.div("div1")).count_similar());
|
461
510
|
end
|
462
511
|
|
463
512
|
def test_collect()
|
464
|
-
@
|
465
|
-
|
513
|
+
@b.navigate_to("#{@base_url}/demo/count.htm")
|
514
|
+
elsAttr = @b.collect(@b.link("/group 1/").in(@b.div("div1")), "sahiText");
|
515
|
+
assert_equal(2, elsAttr.size());
|
516
|
+
assert_equal("group 1 link3", elsAttr[0]);
|
517
|
+
assert_equal("group 1 link4", elsAttr[1]);
|
518
|
+
|
519
|
+
elsAttr2 = @b.collect(@b.link("/group 1/").in(@b.div("div1")));
|
520
|
+
assert_equal(2, elsAttr.size());
|
521
|
+
assert_equal("group 1 link3", elsAttr2[0].text);
|
522
|
+
assert_equal("group 1 link4", elsAttr2[1].text);
|
523
|
+
|
524
|
+
els = @b.link("/group 1/").collect_similar();
|
466
525
|
assert_equal(5, els.size());
|
467
526
|
assert_equal("group 1 link1", els[0].text);
|
468
527
|
assert_equal("group 1 link2", els[1].text);
|
469
528
|
|
470
|
-
@
|
471
|
-
els2 = @
|
529
|
+
@b.navigate_to("#{@base_url}/demo/count.htm")
|
530
|
+
els2 = @b.link("/group 1/").in(@b.div("div1")).collect_similar();
|
472
531
|
assert_equal(2, els2.size());
|
473
532
|
assert_equal("group 1 link3", els2[0].text);
|
474
533
|
assert_equal("group 1 link4", els2[1].text);
|
475
534
|
end
|
476
535
|
|
477
536
|
def test_strict_visible()
|
478
|
-
@
|
479
|
-
assert_equal("b", @
|
480
|
-
@
|
481
|
-
assert_equal("c", @
|
482
|
-
@
|
483
|
-
assert_equal("b", @
|
537
|
+
@b.navigate_to("#{@base_url}/demo/strict_visible.htm")
|
538
|
+
assert_equal("b", @b.textbox("q[1]").value)
|
539
|
+
@b.strict_visibility_check = true
|
540
|
+
assert_equal("c", @b.textbox("q[1]").value)
|
541
|
+
@b.strict_visibility_check = false
|
542
|
+
assert_equal("b", @b.textbox("q[1]").value)
|
484
543
|
end
|
485
544
|
|
486
545
|
def test_active_element()
|
487
|
-
@
|
488
|
-
@
|
489
|
-
assert_equal("user", @
|
490
|
-
@
|
491
|
-
assert_equal("password", @
|
546
|
+
@b.navigate_to("#{@base_url}/demo/training/login.htm")
|
547
|
+
@b.textbox("user").focus()
|
548
|
+
assert_equal("user", @b.activeElement().fetch("name"))
|
549
|
+
@b.password("password").focus()
|
550
|
+
assert_equal("password", @b.activeElement().fetch("name"))
|
492
551
|
end
|
493
552
|
|
494
553
|
def test_identify_by_multiple_attributes()
|
495
|
-
@
|
496
|
-
@
|
497
|
-
assert_equal("aaa", @
|
554
|
+
@b.navigate_to("#{@base_url}/demo/training/books.htm")
|
555
|
+
@b.textbox("q[2]").value = "aaa"
|
556
|
+
assert_equal("aaa", @b.textbox({"name"=>"q", "sahiIndex"=>2}).value)
|
498
557
|
end
|
499
558
|
|
500
559
|
def test_key_press()
|
501
|
-
@
|
502
|
-
@
|
503
|
-
assert_equal("a", @
|
504
|
-
@
|
505
|
-
assert_equal("ab", @
|
560
|
+
@b.navigate_to("#{@base_url}/demo/formTest.htm")
|
561
|
+
@b.textbox("t1").key_press("a")
|
562
|
+
assert_equal("a", @b.textbox("t1").value)
|
563
|
+
@b.textbox("t1").key_press([66,98]);
|
564
|
+
assert_equal("ab", @b.textbox("t1").value)
|
565
|
+
end
|
566
|
+
|
567
|
+
def test_execute_sahi()
|
568
|
+
@b.navigate_to(@base_url + "/demo/")
|
569
|
+
#@b.execute_step("_sahi._click(_sahi._link('Link Test'))")
|
570
|
+
@b.execute_sahi("_click(_link('Link Test'))")
|
571
|
+
assert_equal("Link Test", @b.heading2("Link Test").text)
|
572
|
+
end
|
573
|
+
|
574
|
+
def test_get_win_simple
|
575
|
+
@b.navigate_to(@base_url + "/demo/")
|
576
|
+
@b.wait(2)
|
577
|
+
windows = @b.get_windows()
|
578
|
+
assert_equal(1, windows.length)
|
579
|
+
assert_equal("0", windows[0]["wasOpened"])
|
580
|
+
assert_equal("Sahi Tests", windows[0]["windowTitle"])
|
581
|
+
end
|
582
|
+
|
583
|
+
def test_get_win_popup_with_title
|
584
|
+
@b.navigate_to(@base_url + "/demo/")
|
585
|
+
@b.link("Window Open Test With Title").click
|
586
|
+
@b.wait(2)
|
587
|
+
windows = @b.get_windows()
|
588
|
+
assert_equal(2, windows.length);
|
589
|
+
assert_equal("1", windows[1]["wasOpened"]);
|
590
|
+
assert_equal("With Title", windows[1]["windowTitle"]);
|
591
|
+
end
|
592
|
+
|
593
|
+
def test_get_win_popup_without_title
|
594
|
+
@b.navigate_to(@base_url + "/demo/")
|
595
|
+
@b.link("Window Open Test").click
|
596
|
+
@b.wait(2)
|
597
|
+
windows = @b.get_windows()
|
598
|
+
assert_equal(2, windows.length)
|
599
|
+
assert_equal("1", windows[1]["wasOpened"])
|
600
|
+
assert_equal("", windows[1]["windowTitle"])
|
601
|
+
end
|
602
|
+
|
603
|
+
def test_get_win_popup_with_param
|
604
|
+
@b.navigate_to(@base_url + "/demo/")
|
605
|
+
@b.link("Window Open Test").click
|
606
|
+
popup_popwin = @b.popup("popWin")
|
607
|
+
popup_popwin.close
|
608
|
+
@b.wait(3)
|
609
|
+
windows = @b.get_windows()
|
610
|
+
windows2 = @b.get_windows(0)
|
611
|
+
windows3 = @b.get_windows(2)
|
612
|
+
assert_equal(2, windows.length)
|
613
|
+
assert_equal(2, windows2.length)
|
614
|
+
assert_equal(1, windows3.length)
|
506
615
|
end
|
507
616
|
end
|