sahi 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/sahi.rb +166 -44
- data/test/sahi_test.rb +116 -27
- metadata +33 -73
data/lib/sahi.rb
CHANGED
@@ -1,16 +1,12 @@
|
|
1
1
|
require 'net/http'
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
require 'Platform'
|
2
|
+
require 'time'
|
3
|
+
require 'json'
|
5
4
|
|
6
5
|
module Sahi
|
7
6
|
# The Browser class controls different browsers via Sahi's proxy.
|
8
7
|
#
|
9
|
-
# Thank you Sai Venkat for helping kickstart the ruby driver.
|
10
|
-
#
|
11
8
|
# Author:: Narayan Raman (mailto:narayan@sahi.co.in)
|
12
9
|
# Copyright:: Copyright (c) 2006 V Narayan Raman
|
13
|
-
# License:: Apache License, Version 2.0
|
14
10
|
#
|
15
11
|
# Download Sahi from http://sahi.co.in/ .
|
16
12
|
# Java 1.5 or greater is needed to run Sahi.
|
@@ -23,48 +19,61 @@ module Sahi
|
|
23
19
|
#
|
24
20
|
# cd sahi/userdata/bin;
|
25
21
|
# start_sahi.sh;
|
26
|
-
#
|
27
|
-
# Point the browser proxy settings to localhost 9999.
|
28
22
|
#
|
29
23
|
|
30
24
|
class Browser
|
31
|
-
attr_accessor :proxy_host, :proxy_port, :print_steps, :sahisid, :popup_name
|
25
|
+
attr_accessor :proxy_host, :proxy_port, :print_steps, :sahisid, :popup_name, :domain_name
|
32
26
|
|
33
|
-
# Takes
|
27
|
+
# Takes browser_type as specified in sahi/userdata/config/browser_types.xml (name of browserType) - RECOMMENDED
|
28
|
+
#
|
29
|
+
# OR
|
30
|
+
#
|
31
|
+
# Takes browser_path, browser_options and browser_executable - NOT RECOMMENDED
|
34
32
|
# Various browser options needed to initialize the Browser object are:
|
35
33
|
#
|
36
34
|
# Internet Explorer 6&7:
|
37
35
|
# browser_path = "C:\\Program Files\\Internet Explorer\\iexplore.exe"
|
38
36
|
# browser_options = ""
|
37
|
+
# browser_executable = "iexplore.exe"
|
39
38
|
#
|
40
39
|
# Internet Explorer 8:
|
41
40
|
# browser_path = "C:\\Program Files\\Internet Explorer\\iexplore.exe"
|
42
41
|
# browser_options = "-nomerge"
|
42
|
+
# browser_executable = "iexplore.exe"
|
43
43
|
#
|
44
44
|
# Firefox:
|
45
|
-
# userdata_dir = "D:/sahi/sf/sahi_993/userdata" # path to Sahi's userdata directory.
|
46
45
|
# browser_path = "C:\\Program Files\\Mozilla Firefox\\firefox.exe"
|
47
|
-
# browser_options = "-profile
|
46
|
+
# browser_options = "-profile $userDir/browser/ff/profiles/sahi0 -no-remote"
|
47
|
+
# browser_executable = "firefox.exe"
|
48
48
|
#
|
49
49
|
# Chrome:
|
50
50
|
# userdata_dir = "D:/sahi/sf/sahi_993/userdata" # path to Sahi's userdata directory.
|
51
51
|
# browser_path = "C:\\Documents and Settings\\YOU_THE_USER\\Local Settings\\Application Data\\Google\\Chrome\\Application\\chrome.exe"
|
52
52
|
# browser_options = "--user-data-dir=# {userdata_dir}\browser\chrome\profiles\sahi$threadNo"
|
53
|
+
# browser_executable = "chrome.exe"
|
53
54
|
#
|
54
55
|
# Safari:
|
55
56
|
# browser_path = "C:\\Program Files\\Safari\Safari.exe"
|
56
57
|
# browser_options = ""
|
58
|
+
# browser_executable = "safari.exe"
|
57
59
|
#
|
58
60
|
# Opera:
|
59
61
|
# browser_path = "C:\\Program Files\\Opera\\opera.exe"
|
60
62
|
# browser_options = ""
|
63
|
+
# browser_executable = "opera.exe"
|
61
64
|
|
62
|
-
def initialize(
|
65
|
+
def initialize(*args)
|
63
66
|
@proxy_host = "localhost"
|
64
67
|
@proxy_port = 9999
|
65
|
-
|
66
|
-
|
68
|
+
if args.size == 3
|
69
|
+
@browser_path = args[0]
|
70
|
+
@browser_options = ars[1]
|
71
|
+
@browser_executable = args[2]
|
72
|
+
elsif args.size == 1
|
73
|
+
@browser_type = args[0]
|
74
|
+
end
|
67
75
|
@popup_name = nil
|
76
|
+
@domain_name = nil
|
68
77
|
@sahisid = nil
|
69
78
|
@print_steps = false
|
70
79
|
end
|
@@ -80,18 +89,12 @@ module Sahi
|
|
80
89
|
#opens the browser
|
81
90
|
def open()
|
82
91
|
check_proxy()
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
if Platform::OS == :win32
|
88
|
-
require "win32/process"
|
89
|
-
@pid = Process.create(:app_name => cmd,
|
90
|
-
:process_inherit => true,
|
91
|
-
:thread_inherit => true,
|
92
|
-
:inherit => true).process_id
|
92
|
+
@sahisid = Time.now.to_f
|
93
|
+
start_url = "http://sahi.example.com/_s_/dyn/Driver_initialized"
|
94
|
+
if (@browser_type != null)
|
95
|
+
exec_command("launchPreconfiguredBrowser", {"browserType" => @browser_type, "startUrl" => start_url})
|
93
96
|
else
|
94
|
-
@
|
97
|
+
exec_command("launchAndPlayback", {"browser" => @browser, "browserOptions" => @browser_options, "browserExecutable" => @browser_executable, "startUrl" => start_url})
|
95
98
|
end
|
96
99
|
|
97
100
|
i = 0
|
@@ -124,6 +127,10 @@ module Sahi
|
|
124
127
|
if popup?()
|
125
128
|
step = "_sahi._popup(#{Utils.quoted(@popup_name)})." + step
|
126
129
|
end
|
130
|
+
if domain?()
|
131
|
+
step = "_sahi._domain(#{Utils.quoted(@domain_name)})." + step
|
132
|
+
end
|
133
|
+
#puts step
|
127
134
|
exec_command("setStep", {"step" => step})
|
128
135
|
i = 0
|
129
136
|
while (i < 500)
|
@@ -134,9 +141,9 @@ module Sahi
|
|
134
141
|
|
135
142
|
error = check_done.index("error:") == 0
|
136
143
|
return if done
|
137
|
-
|
144
|
+
if (error)
|
138
145
|
raise check_done
|
139
|
-
|
146
|
+
end
|
140
147
|
end
|
141
148
|
end
|
142
149
|
|
@@ -146,11 +153,21 @@ module Sahi
|
|
146
153
|
|
147
154
|
# evaluates a javascript expression on the browser and fetches its value
|
148
155
|
def fetch(expression)
|
149
|
-
key = "___lastValue___" +
|
156
|
+
key = "___lastValue___" + Time.now.getutc.to_s;
|
150
157
|
execute_step("_sahi.setServerVarPlain('"+key+"', " + expression + ")")
|
151
158
|
return check_nil(exec_command("getVariable", {"key" => key}))
|
152
159
|
end
|
153
160
|
|
161
|
+
# evaluates a javascript expression on the browser and returns true if value is true or "true"
|
162
|
+
def fetch_boolean(expression)
|
163
|
+
return fetch(expression) == "true"
|
164
|
+
end
|
165
|
+
|
166
|
+
|
167
|
+
def browser_js=(js)
|
168
|
+
exec_command("setBrowserJS", {"browserJS"=>js})
|
169
|
+
end
|
170
|
+
|
154
171
|
def check_nil(s)
|
155
172
|
return (s == "null") ? nil : s
|
156
173
|
end
|
@@ -160,23 +177,53 @@ module Sahi
|
|
160
177
|
if popup?()
|
161
178
|
execute_step("_sahi._closeWindow()");
|
162
179
|
else
|
163
|
-
|
180
|
+
exec_command("kill");
|
181
|
+
#Process.kill(9, @pid) if @pid
|
164
182
|
end
|
165
183
|
end
|
166
184
|
|
167
185
|
# sets the speed of execution. The speed is specified in milli seconds
|
168
|
-
def
|
186
|
+
def speed=(ms)
|
169
187
|
exec_command("setSpeed", {"speed"=>ms})
|
170
188
|
end
|
171
189
|
|
190
|
+
# sets strict visibility check. If true, Sahi APIs ignores elements which are not visible
|
191
|
+
def strict_visibility_check=(check)
|
192
|
+
execute_step("_sahi._setStrictVisibilityCheck(#{check})")
|
193
|
+
end
|
194
|
+
|
195
|
+
|
172
196
|
# represents a popup window. The name is either the window name or its title.
|
173
197
|
def popup(name)
|
174
|
-
|
198
|
+
if (@browser_type != null)
|
199
|
+
win = Browser.new(@browser_type)
|
200
|
+
else
|
201
|
+
win = Browser.new(@browser_path, @browser_options, @browser_executable)
|
202
|
+
end
|
203
|
+
|
175
204
|
win.proxy_host = @proxy_host
|
176
205
|
win.proxy_port = @proxy_port
|
177
206
|
win.sahisid = @sahisid
|
178
207
|
win.print_steps = @print_steps
|
179
208
|
win.popup_name = name
|
209
|
+
win.domain_name = @domain_name
|
210
|
+
return win
|
211
|
+
end
|
212
|
+
|
213
|
+
# represents a domain section of window.
|
214
|
+
def domain(name)
|
215
|
+
if (@browser_type != null)
|
216
|
+
win = Browser.new(@browser_type)
|
217
|
+
else
|
218
|
+
win = Browser.new(@browser_path, @browser_options, @browser_executable)
|
219
|
+
end
|
220
|
+
|
221
|
+
win.proxy_host = @proxy_host
|
222
|
+
win.proxy_port = @proxy_port
|
223
|
+
win.sahisid = @sahisid
|
224
|
+
win.print_steps = @print_steps
|
225
|
+
win.popup_name = @popup_name
|
226
|
+
win.domain_name = name
|
180
227
|
return win
|
181
228
|
end
|
182
229
|
|
@@ -184,6 +231,10 @@ module Sahi
|
|
184
231
|
return @popup_name != nil
|
185
232
|
end
|
186
233
|
|
234
|
+
def domain?()
|
235
|
+
return @domain_name != nil
|
236
|
+
end
|
237
|
+
|
187
238
|
# returns the message last alerted on the browser
|
188
239
|
def last_alert()
|
189
240
|
return fetch("_sahi._lastAlert()")
|
@@ -243,18 +294,43 @@ module Sahi
|
|
243
294
|
def add_url_mock(url_pattern, clazz=nil)
|
244
295
|
clazz = "MockResponder_simple" if !clazz
|
245
296
|
execute_step("_sahi._addMock(#{Utils.quoted(url_pattern)}, #{Utils.quoted(clazz)})")
|
246
|
-
|
297
|
+
end
|
247
298
|
|
248
299
|
# reverse effect of add_url_mock
|
249
|
-
|
300
|
+
def remove_url_mock(url_pattern)
|
250
301
|
execute_step("_sahi._removeMock(#{Utils.quoted(url_pattern)})")
|
251
|
-
|
302
|
+
end
|
252
303
|
|
253
304
|
# return window title
|
254
305
|
def title()
|
255
306
|
return fetch("_sahi._title()")
|
256
307
|
end
|
257
308
|
|
309
|
+
# returns true if browser is Internet Explorer
|
310
|
+
def ie?()
|
311
|
+
return fetch_boolean("_sahi._isIE()")
|
312
|
+
end
|
313
|
+
|
314
|
+
# returns true if browser is Firefox
|
315
|
+
def firefox?()
|
316
|
+
return fetch_boolean("_sahi._isFF()")
|
317
|
+
end
|
318
|
+
|
319
|
+
# returns true if browser is Google Chrome
|
320
|
+
def chrome?()
|
321
|
+
return fetch_boolean("_sahi._isChrome()")
|
322
|
+
end
|
323
|
+
|
324
|
+
# returns true if browser is Safari
|
325
|
+
def safari?()
|
326
|
+
return fetch_boolean("_sahi._isSafari()")
|
327
|
+
end
|
328
|
+
|
329
|
+
# returns true if browser is Opera
|
330
|
+
def opera?()
|
331
|
+
return fetch_boolean("_sahi._isOpera()")
|
332
|
+
end
|
333
|
+
|
258
334
|
# waits for specified time (in seconds).
|
259
335
|
# if a block is passed, it will wait till the block evaluates to true or till the specified timeout, which ever is earlier.
|
260
336
|
def wait(timeout)
|
@@ -296,10 +372,12 @@ module Sahi
|
|
296
372
|
# uncheck - for checkboxes
|
297
373
|
|
298
374
|
class ElementStub
|
299
|
-
@@actions = {"click"=>"click",
|
375
|
+
@@actions = {"click"=>"click",
|
300
376
|
"focus"=>"focus", "remove_focus"=>"removeFocus",
|
301
377
|
"check"=>"check", "uncheck"=>"uncheck",
|
302
|
-
|
378
|
+
"dblclick"=>"doubleClick", "right_click"=>"rightClick",
|
379
|
+
"key_down"=>"keyDown", "key_up"=>"keyUp",
|
380
|
+
"mouse_over"=>"mouseOver", "mouse_down"=>"mouseDown", "mouse_up"=>"mouseUp"}
|
303
381
|
def initialize (browser, type, identifiers)
|
304
382
|
@type = type
|
305
383
|
@browser = browser
|
@@ -318,6 +396,10 @@ module Sahi
|
|
318
396
|
@browser.execute_step(step)
|
319
397
|
end
|
320
398
|
|
399
|
+
def key_press(codes, combo=nil)
|
400
|
+
@browser.execute_step("_sahi._keyPress(#{self.to_s()}, #{codes.to_json}, #{combo.to_json})")
|
401
|
+
end
|
402
|
+
|
321
403
|
# drag element and drop on another element
|
322
404
|
def drag_and_drop_on(el2)
|
323
405
|
@browser.execute_step("_sahi._dragDrop(#{self.to_s()}, #{el2.to_s()})")
|
@@ -325,7 +407,7 @@ module Sahi
|
|
325
407
|
|
326
408
|
# choose option in a select box
|
327
409
|
def choose(val)
|
328
|
-
@browser.execute_step("_sahi._setSelected(#{self.to_s()}, #{
|
410
|
+
@browser.execute_step("_sahi._setSelected(#{self.to_s()}, #{val.to_json})")
|
329
411
|
end
|
330
412
|
|
331
413
|
# sets the value for textboxes or textareas. Also triggers necessary events.
|
@@ -335,14 +417,27 @@ module Sahi
|
|
335
417
|
|
336
418
|
# returns value of textbox or textareas and other relevant input elements
|
337
419
|
def value()
|
338
|
-
return @browser.fetch("#{self.to_s()}
|
420
|
+
return @browser.fetch("_sahi._getValue(#{self.to_s()})")
|
339
421
|
end
|
340
422
|
|
341
423
|
# fetches value of specified attribute
|
342
424
|
def fetch(attr=nil)
|
343
|
-
|
344
|
-
|
425
|
+
if attr
|
426
|
+
if attr.include? "."
|
427
|
+
return @browser.fetch("#{self.to_s()}.#{attr}")
|
428
|
+
else
|
429
|
+
return @browser.fetch("_sahi.getAttribute(#{self.to_s()}, #{Utils.quoted(attr)})")
|
430
|
+
end
|
431
|
+
else
|
432
|
+
return @browser.fetch("#{self.to_s()}")
|
433
|
+
end
|
434
|
+
end
|
345
435
|
|
436
|
+
# returns boolean value of attribute. returns true only if fetch returns "true"
|
437
|
+
def fetch_boolean(attr=nil)
|
438
|
+
return @browser.fetch_boolean(attr)
|
439
|
+
end
|
440
|
+
|
346
441
|
# Emulates setting filepath in a file input box.
|
347
442
|
def file=(val)
|
348
443
|
@browser.execute_step("_sahi._setFile(#{self.to_s()}, #{Utils.quoted(val)})")
|
@@ -378,6 +473,16 @@ module Sahi
|
|
378
473
|
@identifiers << ElementStub.new(@browser, "in", [el2])
|
379
474
|
return self
|
380
475
|
end
|
476
|
+
|
477
|
+
# returns a stub with a POSITIONAL "under" relation to another element.
|
478
|
+
# Eg.
|
479
|
+
# browser.cell(0).under(browser.cell("Header")) will denote the cell visually under "Header"
|
480
|
+
# browser.cell(0).near(browser.cell("Book")).under(browser.cell("Cost")) may be used to denote the Cost of Book in a grid
|
481
|
+
|
482
|
+
def under(el2)
|
483
|
+
@identifiers << ElementStub.new(@browser, "under", [el2])
|
484
|
+
return self
|
485
|
+
end
|
381
486
|
|
382
487
|
|
383
488
|
# 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
|
@@ -429,13 +534,30 @@ module Sahi
|
|
429
534
|
def contains_html?(html)
|
430
535
|
return @browser.fetch("_sahi._containsHTML(#{self.to_s()}, #{Utils.quoted(html)})")
|
431
536
|
end
|
432
|
-
|
537
|
+
|
538
|
+
# returns count of elements similar to this element
|
539
|
+
def count_similar()
|
540
|
+
return Integer(@browser.fetch("_sahi._count(\"_#{@type}\", #{concat_identifiers(@identifiers).join(", ")})"))
|
541
|
+
end
|
542
|
+
|
543
|
+
# returns array elements similar to this element
|
544
|
+
def collect_similar()
|
545
|
+
count = self.count_similar()
|
546
|
+
els = Array.new(count)
|
547
|
+
for i in (0..count-1)
|
548
|
+
copy = Array.new(@identifiers)
|
549
|
+
copy[0] = "#{copy[0]}[#{i}]"
|
550
|
+
els[i] = ElementStub.new(@browser, @type, copy);
|
551
|
+
end
|
552
|
+
return els
|
553
|
+
end
|
554
|
+
|
433
555
|
def to_s
|
434
|
-
return "_sahi._#{@type
|
556
|
+
return "_sahi._#{@type}(#{concat_identifiers(@identifiers).join(", ") })"
|
435
557
|
end
|
436
558
|
|
437
559
|
def concat_identifiers(ids)
|
438
|
-
return ids.collect {|id| id.kind_of?(String) ? Utils.quoted(id) : id.to_s()}
|
560
|
+
return ids.collect {|id| id.kind_of?(String) ? Utils.quoted(id) : (id.is_a?(ElementStub) ? id.to_s() : id.to_json())}
|
439
561
|
end
|
440
562
|
#private :concat_identifiers, :exists1?, :visible1?
|
441
563
|
end
|
data/test/sahi_test.rb
CHANGED
@@ -5,38 +5,34 @@ class SahiDriverTest < Test::Unit::TestCase
|
|
5
5
|
def setup
|
6
6
|
@browser = init_browser()
|
7
7
|
@browser.open
|
8
|
-
@base_url = "http://
|
8
|
+
@base_url = "http://localhost."
|
9
9
|
end
|
10
10
|
|
11
11
|
def teardown
|
12
12
|
if @browser
|
13
|
-
@browser.set_speed
|
13
|
+
@browser.set_speed = 100
|
14
14
|
@browser.close
|
15
15
|
sleep(1)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
def init_browser()
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
#browser_path = "C:\\Program Files\\Internet Explorer\\iexplore.exe"
|
24
|
-
#browser_options = "-nomerge"
|
25
|
-
|
26
|
-
return Sahi::Browser.new(browser_path, browser_options)
|
20
|
+
# Look at sahi/userdata/config/browser_types.xml to configure browsers.
|
21
|
+
@browser_name = "chrome"
|
22
|
+
return Sahi::Browser.new(@browser_name)
|
27
23
|
end
|
28
24
|
|
29
25
|
|
30
26
|
def test1
|
31
27
|
@browser.navigate_to(@base_url + "/demo/formTest.htm")
|
32
|
-
@browser.textbox("t1").value = "aaa"
|
28
|
+
@browser.textbox("t1").value = "aaa"
|
33
29
|
@browser.link("Back").click
|
34
|
-
@browser.link("Table Test").click
|
30
|
+
@browser.link("Table Test").click
|
35
31
|
assert_equal("Cell with id", @browser.cell("CellWithId").text)
|
36
32
|
end
|
37
33
|
|
38
|
-
def
|
39
|
-
@browser.
|
34
|
+
def xtest_ZK
|
35
|
+
@browser.speed = 200
|
40
36
|
@browser.navigate_to("http://www.zkoss.org/zkdemo/userguide/")
|
41
37
|
@browser.div("Hello World").click
|
42
38
|
@browser.span("Pure Java").click
|
@@ -52,7 +48,7 @@ class SahiDriverTest < Test::Unit::TestCase
|
|
52
48
|
@browser.span("The coolest technology").click
|
53
49
|
@browser.italic("z-combobox-btn[2]").click
|
54
50
|
@browser.image("CogwheelEye-32x32.gif").click
|
55
|
-
assert(@browser.textbox("z-combobox-inp[2]").exists?)
|
51
|
+
assert(@browser.textbox("z-combobox-inp[2]").exists?)
|
56
52
|
end
|
57
53
|
|
58
54
|
|
@@ -113,6 +109,8 @@ class SahiDriverTest < Test::Unit::TestCase
|
|
113
109
|
assert_equal("o1", @browser.select("s1Id[1]").selected_text())
|
114
110
|
@browser.select("s1Id[1]").choose("o2")
|
115
111
|
assert_equal("o2", @browser.select("s1Id[1]").selected_text())
|
112
|
+
@browser.select(3).choose(["o1", "o3"])
|
113
|
+
assert_equal("o1,o3", @browser.select(3).selected_text())
|
116
114
|
end
|
117
115
|
|
118
116
|
def test_set_file()
|
@@ -184,7 +182,7 @@ class SahiDriverTest < Test::Unit::TestCase
|
|
184
182
|
@browser.image("imgWithLinkNoClick").click;
|
185
183
|
assert(@browser.textbox("t1").exists?)
|
186
184
|
assert_equal("myFn called", @browser.textbox("t1").value)
|
187
|
-
@browser.link("Back").click;
|
185
|
+
@browser.link("Back").click;
|
188
186
|
end
|
189
187
|
|
190
188
|
|
@@ -227,14 +225,21 @@ class SahiDriverTest < Test::Unit::TestCase
|
|
227
225
|
@browser.navigate_to(@base_url + "/demo/tableTest.htm")
|
228
226
|
assert_equal("111", @browser.textarea("ta").near(@browser.cell("a1")).value)
|
229
227
|
assert_equal("222", @browser.textarea("ta").near(@browser.cell("a2")).value)
|
228
|
+
assert_equal("3", @browser.table(0).fetch("rows.length"))
|
230
229
|
@browser.link("Go back").in(@browser.cell("a1").parent_node()).click;
|
231
230
|
assert(@browser.link("Link Test").exists?)
|
232
231
|
end
|
233
232
|
|
233
|
+
def test_under()
|
234
|
+
@browser.navigate_to(@base_url + "/demo/tableTest.htm")
|
235
|
+
assert_equal("x1-2", @browser.cell(0).near(@browser.cell("x1-0")).under(@browser.tableHeader("header 3")).text());
|
236
|
+
assert_equal("x1-3", @browser.cell(0).near(@browser.cell("x1-0")).under(@browser.tableHeader("header 4")).text());
|
237
|
+
end
|
238
|
+
|
234
239
|
def test_exists()
|
235
240
|
@browser.navigate_to(@base_url + "/demo/index.htm")
|
236
241
|
assert(@browser.link("Link Test").exists?)
|
237
|
-
assert(!@browser.link("Link Test NonExistent").exists?)
|
242
|
+
assert(!@browser.link("Link Test NonExistent").exists?)
|
238
243
|
end
|
239
244
|
|
240
245
|
def alert1(message)
|
@@ -277,7 +282,7 @@ class SahiDriverTest < Test::Unit::TestCase
|
|
277
282
|
@browser.expect_confirm("Some question?", true)
|
278
283
|
@browser.button("Click For Confirm").click;
|
279
284
|
assert_equal("oked", @browser.textbox("t1").value)
|
280
|
-
assert_equal("Some question?", @browser.last_confirm())
|
285
|
+
assert_equal("Some question?", @browser.last_confirm())
|
281
286
|
@browser.clear_last_confirm()
|
282
287
|
assert_nil(@browser.last_confirm())
|
283
288
|
end
|
@@ -292,7 +297,7 @@ class SahiDriverTest < Test::Unit::TestCase
|
|
292
297
|
@browser.waitFor(2000)
|
293
298
|
assert_equal("Some prompt?", @browser.last_prompt())
|
294
299
|
@browser.clear_last_prompt()
|
295
|
-
assert_nil(@browser.last_prompt())
|
300
|
+
assert_nil(@browser.last_prompt())
|
296
301
|
end
|
297
302
|
|
298
303
|
|
@@ -318,7 +323,7 @@ class SahiDriverTest < Test::Unit::TestCase
|
|
318
323
|
assert(@browser.spandiv("using visibility").visible?)
|
319
324
|
|
320
325
|
assert(!@browser.byId("nestedBlockInNone").visible?)
|
321
|
-
assert(!@browser.byId("absoluteNestedBlockInNone").visible?)
|
326
|
+
assert(!@browser.byId("absoluteNestedBlockInNone").visible?)
|
322
327
|
end
|
323
328
|
|
324
329
|
def test_check()
|
@@ -346,7 +351,7 @@ class SahiDriverTest < Test::Unit::TestCase
|
|
346
351
|
@browser.textbox("t2").remove_focus()
|
347
352
|
assert_equal("not focused", @browser.textbox("t1").value)
|
348
353
|
@browser.textbox("t2").focus()
|
349
|
-
assert_equal("focused", @browser.textbox("t1").value)
|
354
|
+
assert_equal("focused", @browser.textbox("t1").value)
|
350
355
|
end
|
351
356
|
|
352
357
|
def test_title()
|
@@ -372,12 +377,12 @@ class SahiDriverTest < Test::Unit::TestCase
|
|
372
377
|
assert_equal("", @browser.div("output").text)
|
373
378
|
@browser.area("Record").click;
|
374
379
|
assert(@browser.link("linkByContent").exists?)
|
375
|
-
#@browser.navigate_to("map.htm")
|
380
|
+
#@browser.navigate_to("map.htm")
|
376
381
|
end
|
377
382
|
|
378
383
|
def test_dragdrop()
|
379
384
|
@browser.navigate_to("http://www.snook.ca/technical/mootoolsdragdrop/")
|
380
|
-
@browser.div("Drag me").drag_and_drop_on(@browser.div("Item 2"))
|
385
|
+
@browser.div("Drag me").drag_and_drop_on(@browser.xy(@browser.div("Item 2"), 5, 5))
|
381
386
|
assert @browser.div("dropped").exists?
|
382
387
|
assert @browser.div("Item 1").exists?
|
383
388
|
assert @browser.div("Item 3").exists?
|
@@ -394,9 +399,8 @@ class SahiDriverTest < Test::Unit::TestCase
|
|
394
399
|
@browser.navigate_to("http://www.google.com")
|
395
400
|
@browser.textbox("q").value = "sahi forums"
|
396
401
|
@browser.submit("Google Search").click
|
397
|
-
@browser.link("
|
398
|
-
@browser.
|
399
|
-
assert @browser.textbox("req_username").visible?
|
402
|
+
@browser.link("Sign In").click
|
403
|
+
assert @browser.textbox("Form/Email").visible?
|
400
404
|
end
|
401
405
|
|
402
406
|
def test_dblclick()
|
@@ -413,6 +417,91 @@ class SahiDriverTest < Test::Unit::TestCase
|
|
413
417
|
@browser.button("Clear").click
|
414
418
|
end
|
415
419
|
|
420
|
+
def test_different_domains()
|
421
|
+
@browser.navigate_to("#{@base_url}/demo/")
|
422
|
+
@browser.link("Different Domains External").click
|
423
|
+
domain_tyto = @browser.domain("www.tytosoftware.com")
|
424
|
+
domain_bing = @browser.domain("www.bing.com")
|
425
|
+
|
426
|
+
domain_tyto.link("Link Test").click
|
427
|
+
domain_bing.textbox("q").value = "fdsfsd"
|
428
|
+
|
429
|
+
domain_tyto.link("Back").click
|
430
|
+
domain_bing.div("bgDiv").click
|
431
|
+
|
432
|
+
@browser.navigate_to("#{@base_url}/demo/");
|
433
|
+
end
|
434
|
+
|
435
|
+
def test_browser_types()
|
436
|
+
@browser.navigate_to("#{@base_url}/demo/")
|
437
|
+
if (@browser_name == "firefox")
|
438
|
+
assert(!@browser.ie?())
|
439
|
+
assert(@browser.firefox?())
|
440
|
+
elsif (@browser_name == "ie")
|
441
|
+
assert(@browser.ie?())
|
442
|
+
assert(!@browser.firefox?())
|
443
|
+
end
|
444
|
+
end
|
445
|
+
|
446
|
+
def test_browser_js()
|
447
|
+
@browser.browser_js = "function giveMyNumber(){return '23';}"
|
448
|
+
@browser.navigate_to("#{@base_url}/demo/")
|
449
|
+
assert_equal("23", @browser.fetch("giveMyNumber()"))
|
450
|
+
@browser.link("Link Test").click()
|
451
|
+
assert_equal("23", @browser.fetch("giveMyNumber()"))
|
452
|
+
@browser.link("Back").click()
|
453
|
+
end
|
416
454
|
|
417
|
-
|
418
|
-
|
455
|
+
def test_count()
|
456
|
+
@browser.navigate_to("#{@base_url}/demo/count.htm")
|
457
|
+
assert_equal(4, @browser.link("group 0 link").count_similar())
|
458
|
+
assert_equal(0, @browser.link("group non existent link").count_similar());
|
459
|
+
assert_equal(5, @browser.link("/group 1/").count_similar());
|
460
|
+
assert_equal(2, @browser.link("/group 1/").in(@browser.div("div1")).count_similar());
|
461
|
+
end
|
462
|
+
|
463
|
+
def test_collect()
|
464
|
+
@browser.navigate_to("#{@base_url}/demo/count.htm")
|
465
|
+
els = @browser.link("/group 1/").collect_similar();
|
466
|
+
assert_equal(5, els.size());
|
467
|
+
assert_equal("group 1 link1", els[0].text);
|
468
|
+
assert_equal("group 1 link2", els[1].text);
|
469
|
+
|
470
|
+
@browser.navigate_to("#{@base_url}/demo/count.htm")
|
471
|
+
els2 = @browser.link("/group 1/").in(@browser.div("div1")).collect_similar();
|
472
|
+
assert_equal(2, els2.size());
|
473
|
+
assert_equal("group 1 link3", els2[0].text);
|
474
|
+
assert_equal("group 1 link4", els2[1].text);
|
475
|
+
end
|
476
|
+
|
477
|
+
def test_strict_visible()
|
478
|
+
@browser.navigate_to("#{@base_url}/demo/strict_visible.htm")
|
479
|
+
assert_equal("b", @browser.textbox("q[1]").value)
|
480
|
+
@browser.strict_visibility_check = true
|
481
|
+
assert_equal("c", @browser.textbox("q[1]").value)
|
482
|
+
@browser.strict_visibility_check = false
|
483
|
+
assert_equal("b", @browser.textbox("q[1]").value)
|
484
|
+
end
|
485
|
+
|
486
|
+
def test_active_element()
|
487
|
+
@browser.navigate_to("#{@base_url}/demo/training/login.htm")
|
488
|
+
@browser.textbox("user").focus()
|
489
|
+
assert_equal("user", @browser.activeElement().fetch("name"))
|
490
|
+
@browser.password("password").focus()
|
491
|
+
assert_equal("password", @browser.activeElement().fetch("name"))
|
492
|
+
end
|
493
|
+
|
494
|
+
def test_identify_by_multiple_attributes()
|
495
|
+
@browser.navigate_to("#{@base_url}/demo/training/books.htm")
|
496
|
+
@browser.textbox("q[2]").value = "aaa"
|
497
|
+
assert_equal("aaa", @browser.textbox({"name"=>"q", "sahiIndex"=>2}).value)
|
498
|
+
end
|
499
|
+
|
500
|
+
def test_key_press()
|
501
|
+
@browser.navigate_to("#{@base_url}/demo/formTest.htm")
|
502
|
+
@browser.textbox("t1").key_press("a")
|
503
|
+
assert_equal("a", @browser.textbox("t1").value)
|
504
|
+
@browser.textbox("t1").key_press([66,98]);
|
505
|
+
assert_equal("ab", @browser.textbox("t1").value)
|
506
|
+
end
|
507
|
+
end
|
metadata
CHANGED
@@ -1,94 +1,54 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: sahi
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
version: 1.0.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
12
|
-
-
|
7
|
+
authors:
|
8
|
+
- Tyto Software
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
name: Platform
|
22
|
-
prerelease: false
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - ">="
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 0
|
29
|
-
- 3
|
30
|
-
- 9
|
31
|
-
version: 0.3.9
|
32
|
-
type: :runtime
|
33
|
-
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: guid
|
36
|
-
prerelease: false
|
37
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - ">="
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
segments:
|
42
|
-
- 0
|
43
|
-
- 1
|
44
|
-
- 1
|
45
|
-
version: 0.1.1
|
46
|
-
type: :runtime
|
47
|
-
version_requirements: *id002
|
48
|
-
description: |-
|
49
|
-
Ruby driver for Sahi (http://sahi.co.in/). Sahi is a web automation tool.
|
50
|
-
Sahi runs as a proxy, and the browser needs to be configured to use Sahi's proxy.
|
51
|
-
The browser can then be driven via the Sahi Ruby driver.
|
12
|
+
date: 2013-08-06 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! "Ruby driver for Sahi (http://sahi.co.in/). Sahi is a web automation
|
15
|
+
tool. \nSahi runs as a proxy, and the browser needs to be configured to use Sahi's
|
16
|
+
proxy. \nThe browser can then be driven via the Sahi Ruby driver."
|
52
17
|
email: support@sahi.co.in
|
53
18
|
executables: []
|
54
|
-
|
55
19
|
extensions: []
|
56
|
-
|
57
|
-
extra_rdoc_files:
|
20
|
+
extra_rdoc_files:
|
58
21
|
- README.txt
|
59
|
-
files:
|
22
|
+
files:
|
60
23
|
- lib/sahi.rb
|
61
24
|
- README.txt
|
62
|
-
|
25
|
+
- test/elementstub_test.rb
|
26
|
+
- test/sahi_test.rb
|
63
27
|
homepage: http://sahi.co.in/w/ruby/
|
64
28
|
licenses: []
|
65
|
-
|
66
|
-
|
29
|
+
post_install_message: Welcome to easy web automation using Sahi. You need to have
|
30
|
+
Sahi proxy running before using this driver.
|
67
31
|
rdoc_options: []
|
68
|
-
|
69
|
-
require_paths:
|
32
|
+
require_paths:
|
70
33
|
- lib
|
71
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
requirements:
|
80
|
-
- -
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
|
83
|
-
- 0
|
84
|
-
version: "0"
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
85
46
|
requirements: []
|
86
|
-
|
87
47
|
rubyforge_project:
|
88
|
-
rubygems_version: 1.
|
48
|
+
rubygems_version: 1.7.2
|
89
49
|
signing_key:
|
90
50
|
specification_version: 3
|
91
|
-
summary: Ruby driver for Sahi
|
92
|
-
test_files:
|
51
|
+
summary: Ruby driver for Sahi Pro
|
52
|
+
test_files:
|
93
53
|
- test/elementstub_test.rb
|
94
54
|
- test/sahi_test.rb
|