operawatir 0.4.3.pre1-jruby → 0.5-jruby
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitmodules +1 -1
- data/CHANGES +230 -0
- data/Gemfile +4 -0
- data/Rakefile +3 -2
- data/VERSION +1 -1
- data/bin/desktopwatir +1 -1
- data/bin/operawatir +16 -4
- data/lib/operadriver/guava-r09.jar +0 -0
- data/lib/operadriver/operadriver-v0.7.2.jar +0 -0
- data/lib/operadriver/selenium-nodeps-20100909.jar +0 -0
- data/lib/operawatir.rb +10 -3
- data/lib/operawatir/actions.rb +111 -0
- data/lib/operawatir/browser.rb +24 -20
- data/lib/operawatir/clickable_item.rb +68 -0
- data/lib/operawatir/compat.rb +4 -4
- data/lib/operawatir/compat/collection.rb +1 -1
- data/lib/operawatir/compat/element.rb +1 -1
- data/lib/operawatir/compat/window.rb +4 -3
- data/lib/operawatir/desktop_browser.rb +299 -95
- data/lib/operawatir/desktop_common.rb +88 -23
- data/lib/operawatir/desktop_container.rb +103 -34
- data/lib/operawatir/desktop_enums.rb +4 -4
- data/lib/operawatir/desktop_exceptions.rb +2 -2
- data/lib/operawatir/desktop_helper.rb +31 -8
- data/lib/operawatir/element.rb +6 -2
- data/lib/operawatir/exceptions.rb +4 -4
- data/lib/operawatir/helper.rb +6 -6
- data/lib/operawatir/keys.rb +4 -4
- data/lib/operawatir/preferences.rb +126 -155
- data/lib/operawatir/quickwidgets.rb +3 -3
- data/lib/operawatir/quickwidgets/quick_addressfield.rb +12 -5
- data/lib/operawatir/quickwidgets/quick_button.rb +39 -53
- data/lib/operawatir/quickwidgets/quick_checkbox.rb +6 -6
- data/lib/operawatir/quickwidgets/quick_dialogtab.rb +5 -5
- data/lib/operawatir/quickwidgets/quick_dropdown.rb +28 -4
- data/lib/operawatir/quickwidgets/quick_dropdownitem.rb +46 -0
- data/lib/operawatir/quickwidgets/quick_editfield.rb +16 -13
- data/lib/operawatir/quickwidgets/quick_label.rb +1 -1
- data/lib/operawatir/quickwidgets/quick_menu.rb +155 -0
- data/lib/operawatir/quickwidgets/quick_menuitem.rb +387 -0
- data/lib/operawatir/quickwidgets/quick_searchfield.rb +7 -4
- data/lib/operawatir/quickwidgets/quick_tab.rb +23 -12
- data/lib/operawatir/quickwidgets/quick_thumbnail.rb +4 -4
- data/lib/operawatir/quickwidgets/quick_toolbar.rb +1 -1
- data/lib/operawatir/quickwidgets/quick_treeitem.rb +45 -29
- data/lib/operawatir/quickwidgets/quick_treeview.rb +2 -2
- data/lib/operawatir/quickwidgets/quick_widget.rb +267 -77
- data/lib/operawatir/quickwidgets/quick_window.rb +64 -38
- data/lib/operawatir/screenshot.rb +1 -1
- data/lib/operawatir/utils.rb +31 -0
- data/lib/operawatir/window.rb +1 -1
- data/operawatir.gemspec +38 -132
- data/spec/operawatir/core/actions_spec.rb +202 -0
- data/spec/operawatir/core/browser_spec.rb +8 -8
- data/spec/operawatir/core/element_spec.rb +11 -2
- data/spec/operawatir/core/keys_spec.rb +50 -2
- data/spec/operawatir/core/preferences_spec.rb +44 -128
- data/spec/operawatir/core/spatnav_spec.rb +16 -16
- data/spec/operawatir/core/utils_spec.rb +47 -0
- data/spec/operawatir/core/window_spec.rb +1 -1
- data/spec/operawatir/desktop/desktopbrowser_spec.rb +191 -22
- data/spec/operawatir/desktop/quickbutton_spec.rb +197 -164
- data/spec/operawatir/desktop/quickcheckbox_spec.rb +12 -12
- data/spec/operawatir/desktop/quickdialogtab_spec.rb +11 -11
- data/spec/operawatir/desktop/quickdropdown_spec.rb +25 -25
- data/spec/operawatir/desktop/quickeditfield_spec.rb +31 -31
- data/spec/operawatir/desktop/quickmenu_spec.rb +57 -0
- data/spec/operawatir/desktop/quickmenuitem_spec.rb +168 -0
- data/spec/operawatir/desktop/quicktab_spec.rb +26 -15
- data/spec/operawatir/desktop/quickthumbnail_spec.rb +18 -4
- data/spec/operawatir/desktop/quicktreeitem_spec.rb +72 -72
- data/spec/operawatir/desktop/quicktreeview_spec.rb +13 -13
- data/spec/operawatir/desktop/quickwidget_spec.rb +51 -13
- data/spec/operawatir/desktop/quickwindow_spec.rb +4 -0
- data/spec/operawatir/desktop/shared/shared.rb +25 -9
- data/spec/operawatir/fixtures/draggableLists.html +67 -0
- data/spec/operawatir/fixtures/formSelectionPage.html +46 -0
- data/spec/operawatir/fixtures/js/jquery-1.4.4.min.js +167 -0
- data/spec/operawatir/fixtures/js/jquery-ui-1.8.10.custom.min.js +782 -0
- data/spec/operawatir/fixtures/keys.html +40 -0
- data/spec/operawatir/fixtures/label_submit.html +5 -0
- data/spec/operawatir/fixtures/mouse.html +59 -0
- data/spec/operawatir/fixtures/simple.html +10 -0
- data/spec/operawatir/matchers.rb +20 -19
- data/spec/operawatir/watirspec_desktophelper.rb +51 -3
- data/spec/operawatir/watirspec_helper.rb +0 -2
- metadata +91 -220
- data/lib/operadriver/client-combined-nodeps.jar +0 -0
- data/lib/operadriver/webdriver-opera.jar +0 -0
- data/spec/watir3/browser_spec.rb +0 -190
- data/spec/watir3/clipboard_spec.rb +0 -64
- data/spec/watir3/collection_spec.rb +0 -387
- data/spec/watir3/element_spec.rb +0 -474
- data/spec/watir3/guards.rb +0 -39
- data/spec/watir3/keys_spec.rb +0 -204
- data/spec/watir3/server.rb +0 -91
- data/spec/watir3/watirspec_helper.rb +0 -62
- data/spec/watir3/window_spec.rb +0 -295
data/spec/watir3/guards.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
module WatirSpec
|
2
|
-
class Guard
|
3
|
-
|
4
|
-
attr_accessor :type, :browsers, :data
|
5
|
-
|
6
|
-
def initialize(type, browsers, data={})
|
7
|
-
self.type, self.browsers, self.data = type, browsers, data
|
8
|
-
WatirSpec.guards << self
|
9
|
-
end
|
10
|
-
|
11
|
-
def guarded?(browser)
|
12
|
-
WatirSpec.guarded? || browsers.include?(browser.name)
|
13
|
-
end
|
14
|
-
|
15
|
-
module Helpers
|
16
|
-
def deviates_on(*browsers)
|
17
|
-
guard = WatirSpec::Guard.new :deviation, browsers, :file => caller.first
|
18
|
-
yield unless guard.guarded?(OperaWatir::Helper.browser)
|
19
|
-
end
|
20
|
-
|
21
|
-
def not_compliant_on(*browsers)
|
22
|
-
guard = WatirSpec::Guard.new :non_compliance, browsers, :file => caller.first
|
23
|
-
yield unless guard.guarded?(OperaWatir::Helper.browser)
|
24
|
-
end
|
25
|
-
|
26
|
-
def compliant_on(*browsers)
|
27
|
-
guard = WatirSpec::Guard.new :compliance, browsers, :file => caller.first
|
28
|
-
yield unless guard.guarded?(OperaWatir::Helper.browser)
|
29
|
-
end
|
30
|
-
|
31
|
-
def bug(url, *browsers)
|
32
|
-
guard = WatirSpec::Guard.new :bug, browsers, :file => caller.first, :url => url
|
33
|
-
yield unless guard.guarded?(OperaWatir::Helper.browser)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
data/spec/watir3/keys_spec.rb
DELETED
@@ -1,204 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require File.expand_path('../watirspec_helper', __FILE__)
|
3
|
-
|
4
|
-
# keyboard input
|
5
|
-
# ---------------
|
6
|
-
describe 'Keys' do
|
7
|
-
after :each do
|
8
|
-
browser.keys.release
|
9
|
-
end
|
10
|
-
|
11
|
-
describe '#send' do
|
12
|
-
before :each do
|
13
|
-
browser.url = fixture('two_input_fields.html')
|
14
|
-
@one = window.find_by_name('one')
|
15
|
-
@two = window.find_by_name('two')
|
16
|
-
@one.click
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'types a single character' do
|
20
|
-
browser.keys.send 'A'
|
21
|
-
@one.value.should == 'A'
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'types a mixed-case string' do
|
25
|
-
browser.keys.send 'ABC abc'
|
26
|
-
@one.value.should == 'ABC abc'
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'types a string containing multi-byte characters' do
|
30
|
-
browser.keys.send 'ルビー 水'
|
31
|
-
@one.value.should == 'ルビー 水'
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'types many single characters in sequence' do
|
35
|
-
browser.keys.send 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
|
36
|
-
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
|
37
|
-
'W', 'X', 'Y', 'Z'
|
38
|
-
@one.value.should == 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'moves the caret using arrow keys' do
|
42
|
-
browser.keys.send 'AC', :left, 'B'
|
43
|
-
@one.value.should == 'ABC'
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'switches to a different input element with tab' do
|
47
|
-
browser.keys.send 'AB', :tab, 'C'
|
48
|
-
@one.value.should == 'AB'
|
49
|
-
@two.value.should == 'C'
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'uses modifier keys' do
|
53
|
-
browser.keys.send [:shift, 'a'], 'bc'
|
54
|
-
@one.value.should == 'Abc'
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'uses multiple modifier keys to manipulate selection' do
|
58
|
-
browser.keys.send 'ABC 123'
|
59
|
-
|
60
|
-
# Selection using keys works differently on OS X
|
61
|
-
if Config::CONFIG['host_os'] =~ /darwin|mac os/
|
62
|
-
browser.keys.send [:shift, :alt, :left], :backspace
|
63
|
-
else
|
64
|
-
browser.keys.send [:shift, :control, :left], :backspace
|
65
|
-
end
|
66
|
-
|
67
|
-
@one.value.should == 'ABC '
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'presses an invalid key' do
|
71
|
-
browser.keys.send(:hoobaflooba).should raise_error InvalidKeyException
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe '#down' do
|
76
|
-
it 'types a mixed-case string by holding shift' do
|
77
|
-
browser.url = fixture('two_input_fields.html')
|
78
|
-
window.find_by_name('one').click
|
79
|
-
browser.keys.send 'a'
|
80
|
-
browser.keys.down :shift
|
81
|
-
browser.keys.send 'b'
|
82
|
-
window.find_by_name('one').value.should == 'aB'
|
83
|
-
browser.keys.up :shift
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'holds down a non-modifier key for one second' do
|
87
|
-
browser.url = fixture('two_input_fields.html')
|
88
|
-
window.find_by_name('one').click
|
89
|
-
browser.keys.down 'a'
|
90
|
-
sleep 1
|
91
|
-
browser.keys.up 'a'
|
92
|
-
window.find_by_name('one').value.should include 'aa' # Two or more characters are expected.
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'triggers onkeydown' do
|
96
|
-
browser.url = fixture('keys.html')
|
97
|
-
browser.keys.down :shift
|
98
|
-
window.find_by_id('log').text.should include 'down, 16'
|
99
|
-
browser.keys.up :shift
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'does not trigger onkeyup' do
|
103
|
-
browser.url = fixture('keys.html')
|
104
|
-
browser.keys.down :shift
|
105
|
-
window.find_by_id('log').text.should_not include 'up, 16'
|
106
|
-
browser.keys.up :shift
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'presses two buttons at the same time' do
|
110
|
-
browser.url = fixture('keys.html')
|
111
|
-
browser.keys.down :shift, :control
|
112
|
-
window.find_by_id('log').text.should include 'down, 16'
|
113
|
-
window.find_by_id('log').text.should include 'down, 17'
|
114
|
-
browser.keys.up :shift
|
115
|
-
browser.keys.up :control
|
116
|
-
end
|
117
|
-
|
118
|
-
it 'presses an invalid key' do
|
119
|
-
browser.keys.down(:hoobaflooba).should raise_error InvalidKeyException
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'passes an array instead of a string' do
|
123
|
-
browser.keys.down([:shift, :control]).should raise_error NativeException
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
describe '#up' do
|
128
|
-
it 'types a mixed-case string by holding shift' do
|
129
|
-
browser.url = fixture('two_input_fields.html')
|
130
|
-
window.find_by_name('one').click
|
131
|
-
browser.keys.down :shift
|
132
|
-
browser.keys.send 'a'
|
133
|
-
browser.keys.send 'b' # Testing that we do not release prematurely
|
134
|
-
browser.keys.up :shift
|
135
|
-
browser.keys.send 'c'
|
136
|
-
window.find_by_name('one').value.should == 'ABc'
|
137
|
-
end
|
138
|
-
|
139
|
-
it 'holds down a non-modifier key for one second (but no longer)' do
|
140
|
-
browser.url = fixture('two_input_fields.html')
|
141
|
-
window.find_by_name('one').click
|
142
|
-
browser.keys.down 'a'
|
143
|
-
sleep 1
|
144
|
-
browser.keys.up 'a'
|
145
|
-
result_string = window.find_by_name('one').value
|
146
|
-
sleep 1
|
147
|
-
window.find_by_name('one').value.should == result_string
|
148
|
-
result_string = nil
|
149
|
-
end
|
150
|
-
|
151
|
-
it 'triggers onkeyup' do
|
152
|
-
browser.url = fixture('keys.html')
|
153
|
-
browser.keys.down :shift
|
154
|
-
browser.keys.up :shift
|
155
|
-
window.find_by_id('log').text.should include 'up, 16'
|
156
|
-
end
|
157
|
-
|
158
|
-
it 'presses two buttons, but releases only one' do
|
159
|
-
browser.url = fixture('keys.html')
|
160
|
-
browser.keys.down :shift, :control
|
161
|
-
browser.keys.up :shift
|
162
|
-
window.find_by_id('log').text.should include 'up, 16'
|
163
|
-
window.find_by_id('log').text.should_not include 'up, 17'
|
164
|
-
browser.keys.up :control
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'releases two buttons' do
|
168
|
-
browser.url = fixture('keys.html')
|
169
|
-
browser.keys.down :shift, :control
|
170
|
-
browser.keys.up :shift, :control
|
171
|
-
window.find_by_id('log').text.should include 'up, 16'
|
172
|
-
window.find_by_id('log').text.should include 'up, 17'
|
173
|
-
end
|
174
|
-
|
175
|
-
it 'presses an invalid key' do
|
176
|
-
browser.keys.down(:hoobaflooba).should raise_error InvalidKeyException
|
177
|
-
end
|
178
|
-
|
179
|
-
it 'passes an array instead of a string' do
|
180
|
-
browser.keys.up([:shift, :control]).should raise_error NativeException
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
describe '#release' do
|
185
|
-
it 'releases one button' do
|
186
|
-
browser.url = fixture('two_input_fields.html')
|
187
|
-
window.find_by_name('one').click
|
188
|
-
browser.keys.down :shift
|
189
|
-
browser.keys.send 'a'
|
190
|
-
browser.keys.release
|
191
|
-
browser.keys.send 'b'
|
192
|
-
window.find_by_name('one').value.should == 'Ab'
|
193
|
-
end
|
194
|
-
|
195
|
-
it 'releases two buttons' do
|
196
|
-
browser.url = fixture('keys.html')
|
197
|
-
browser.keys.down :shift, :control
|
198
|
-
browser.keys.release
|
199
|
-
window.find_by_id('log').text.should include 'up, 16'
|
200
|
-
window.find_by_id('log').text.should include 'up, 17'
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
end
|
data/spec/watir3/server.rb
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'sinatra/base'
|
3
|
-
|
4
|
-
class WatirSpec::Server < ::Sinatra::Base
|
5
|
-
|
6
|
-
set :app_file, __FILE__
|
7
|
-
set :root, File.dirname(__FILE__)
|
8
|
-
set :public, lambda { File.join(root, 'fixtures')}
|
9
|
-
set :static, true
|
10
|
-
set :run, false
|
11
|
-
set :environment, :production
|
12
|
-
set :bind, 'localhost'
|
13
|
-
set :port, 2000
|
14
|
-
set :server, %w[thin mongrel webrick]
|
15
|
-
|
16
|
-
get '/' do
|
17
|
-
self.class.name
|
18
|
-
end
|
19
|
-
|
20
|
-
get '/big' do
|
21
|
-
Class.new do
|
22
|
-
def each(&blk)
|
23
|
-
yield "<html><head><title>Big Content</title></head><body>"
|
24
|
-
string = "hello "*205
|
25
|
-
300.times { yield string }
|
26
|
-
yield "</body></html>"
|
27
|
-
end
|
28
|
-
end.new
|
29
|
-
end
|
30
|
-
|
31
|
-
post '/post_to_me' do
|
32
|
-
"You posted the following content:\n#{ env['rack.input'].read }"
|
33
|
-
end
|
34
|
-
|
35
|
-
get '/plain_text' do
|
36
|
-
content_type 'text/plain'
|
37
|
-
'This is text/plain'
|
38
|
-
end
|
39
|
-
|
40
|
-
get '/ajax' do
|
41
|
-
sleep 10
|
42
|
-
"A slooow ajax response"
|
43
|
-
end
|
44
|
-
|
45
|
-
get '/charset_mismatch' do
|
46
|
-
content_type 'text/html; charset=UTF-8'
|
47
|
-
%{
|
48
|
-
<html>
|
49
|
-
<head>
|
50
|
-
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />
|
51
|
-
</head>
|
52
|
-
<body>
|
53
|
-
<h1>ø</h1>
|
54
|
-
</body>
|
55
|
-
</html>
|
56
|
-
}
|
57
|
-
end
|
58
|
-
|
59
|
-
get '/octet_stream' do
|
60
|
-
content_type 'application/octet-stream'
|
61
|
-
'This is application/octet-stream'
|
62
|
-
end
|
63
|
-
|
64
|
-
get '/set_cookie' do
|
65
|
-
content_type 'text/plain'
|
66
|
-
headers 'Set-Cookie' => "monster=/"
|
67
|
-
|
68
|
-
"C is for cookie, it's good enough for me"
|
69
|
-
end
|
70
|
-
|
71
|
-
get '/header_echo' do
|
72
|
-
content_type 'text/plain'
|
73
|
-
env.inspect
|
74
|
-
end
|
75
|
-
|
76
|
-
get '/authentication' do
|
77
|
-
auth = Rack::Auth::Basic::Request.new(env)
|
78
|
-
|
79
|
-
unless auth.provided? && auth.credentials == %w[foo bar]
|
80
|
-
headers 'WWW-Authenticate' => %(Basic realm="localhost")
|
81
|
-
halt 401, 'Authorization Required'
|
82
|
-
end
|
83
|
-
|
84
|
-
"ok"
|
85
|
-
end
|
86
|
-
|
87
|
-
get '/encodable_<stuff>' do
|
88
|
-
'page with characters in URI that need encoding'
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$LOAD_PATH.unshift File.dirname(__FILE__)
|
3
|
-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
4
|
-
require 'rspec'
|
5
|
-
|
6
|
-
require 'guards'
|
7
|
-
require 'server'
|
8
|
-
|
9
|
-
require 'operawatir/helper'
|
10
|
-
|
11
|
-
OperaWatir.api = 2
|
12
|
-
|
13
|
-
RSpec.configure do |config|
|
14
|
-
config.mock_with :rr
|
15
|
-
end
|
16
|
-
|
17
|
-
module WatirSpec
|
18
|
-
extend self
|
19
|
-
|
20
|
-
attr_accessor :args, :guarded
|
21
|
-
|
22
|
-
def host
|
23
|
-
"http://#{Server.bind}:#{Server.port}"
|
24
|
-
end
|
25
|
-
alias_method :files, :host
|
26
|
-
|
27
|
-
def guards
|
28
|
-
@guards ||= []
|
29
|
-
end
|
30
|
-
|
31
|
-
def guarded?
|
32
|
-
!!@guarded
|
33
|
-
end
|
34
|
-
|
35
|
-
module Helpers
|
36
|
-
def browser
|
37
|
-
OperaWatir::Helper.browser
|
38
|
-
end
|
39
|
-
|
40
|
-
def window
|
41
|
-
browser.active_window
|
42
|
-
end
|
43
|
-
|
44
|
-
def fixture(*paths)
|
45
|
-
[WatirSpec.host, *paths].join('/')
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
include OperaWatir::Exceptions
|
52
|
-
|
53
|
-
include WatirSpec::Guard::Helpers
|
54
|
-
|
55
|
-
RSpec.configure do |config|
|
56
|
-
config.include WatirSpec::Helpers
|
57
|
-
|
58
|
-
config.before(:suite) do
|
59
|
-
Thread.new { WatirSpec::Server.run! }
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
data/spec/watir3/window_spec.rb
DELETED
@@ -1,295 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require File.expand_path('../watirspec_helper', __FILE__)
|
3
|
-
|
4
|
-
describe 'Window' do
|
5
|
-
|
6
|
-
before :each do
|
7
|
-
browser.url = fixture('non_control_elements.html')
|
8
|
-
end
|
9
|
-
|
10
|
-
# element access
|
11
|
-
# --------------
|
12
|
-
|
13
|
-
describe '#find_by_id' do
|
14
|
-
it 'returns an element with the given ID' do
|
15
|
-
elements = window.find_by_id('header')
|
16
|
-
|
17
|
-
elements.should_not be_empty
|
18
|
-
elements.length.should == 1
|
19
|
-
elements.first.attr(:id).should == 'header'
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'finds multiple elements with the same id' do
|
23
|
-
elements = window.find_by_id('lead')
|
24
|
-
elements.length.should == 4
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#find_by_tag' do
|
29
|
-
it 'is not empty if the tag exists' do
|
30
|
-
window.find_by_tag(:div).should_not be_empty
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'returns a collection of elements of the given tag' do
|
34
|
-
uls = window.find_by_tag(:ul)
|
35
|
-
uls.length.should == 2
|
36
|
-
uls.find_by_tag(:li).all? do |element|
|
37
|
-
element.parent.tag_name.match(/ul/i)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# TODO I'm not convinced that we should be able to filter in finders
|
42
|
-
it 'contains only elements restricted by the selector' do
|
43
|
-
window.find_by_tag(:div, :title => 'Lorem ipsum').all? do |element|
|
44
|
-
element.attr(:title) == 'Lorem ipsum' && element.tag_name.match(/div/i)
|
45
|
-
end.should be_true
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'empty if the elements do not exist' do
|
49
|
-
window.find_by_tag(:hoobaflooba).should be_empty
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
# css
|
55
|
-
# we don't want a complete CSS selector test suite here, so just some common
|
56
|
-
# selectors
|
57
|
-
describe '#find_by_css' do
|
58
|
-
it 'is not empty if an element matches the css selector' do
|
59
|
-
window.find_by_css('#outer_container > div').should_not be_empty
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'contains all elements selected by the selector' do
|
63
|
-
window.find_by_css('#outer_container > div').all? do |element|
|
64
|
-
element.parent.attr(:id).should == 'outer_container'
|
65
|
-
end.should be_true
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'is empty if the selector does not match' do
|
69
|
-
window.find_by_css('#hoobaflooba').should be_empty
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
# class
|
74
|
-
describe '#find_by_class' do
|
75
|
-
it 'is not empty if an element matches the class' do
|
76
|
-
window.find_by_class('lead').should_not be_empty
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'returns a collection of elements with the given class' do
|
80
|
-
window.find_by_class('lead').attrs(:class).should == ['lead','lead','lead','lead']
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'finds elements with multiple classes' do
|
84
|
-
window.find_by_class('one').all? do |element|
|
85
|
-
element.attr(:class).should match /one/
|
86
|
-
end.should be_true
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'is empty if the class does not match' do
|
90
|
-
window.find_by_class('hoobaflooba').should be_empty
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
# xpath
|
95
|
-
describe '#find_by_xpath' do
|
96
|
-
before :all do
|
97
|
-
@headers = window.find_by_xpath('//h1')
|
98
|
-
end
|
99
|
-
|
100
|
-
it 'is not empty if elements matches the class' do
|
101
|
-
@headers.should_not be_empty
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'contains all elements with the given query' do
|
105
|
-
@headers.all? do |element|
|
106
|
-
element.tag_name.should match /h1/i
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'is empty if the query does not match' do
|
111
|
-
window.find_by_xpath('//hoobaflooba').should be_empty
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
# properties
|
116
|
-
# ----------
|
117
|
-
|
118
|
-
describe '#title' do
|
119
|
-
it 'is the title of the window' do
|
120
|
-
window.title.should == 'Non-control elements'
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'changes when the title tag changes' do
|
124
|
-
window.execute_script('document.title = "changed"')
|
125
|
-
window.title.should == 'changed'
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
describe '#html' do
|
130
|
-
it 'is the source of the page' do
|
131
|
-
window.html.should match /<title>Non-control elements<\/title>/i
|
132
|
-
end
|
133
|
-
|
134
|
-
# TODO I'm not sure Watir allows DOM manipulation
|
135
|
-
it 'is the original source' do
|
136
|
-
# window.find_by_tag(:title).first.text = 'changed'
|
137
|
-
window.html.should match /<title>Non-control elements<\/title>/i
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
# page management
|
142
|
-
# ---------------
|
143
|
-
|
144
|
-
describe '#url' do
|
145
|
-
it 'is the url of this window' do
|
146
|
-
window.url.should == fixture('non_control_elements.html')
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
describe '#url=' do
|
151
|
-
it 'navigates to the given url' do
|
152
|
-
window.url = fixture('forms_with_input_elements.html')
|
153
|
-
window.find_by_tag(:title).first.text.should == 'Forms with input elements'
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
describe '#back' do
|
158
|
-
# should it raise an exception if it fails instead?
|
159
|
-
it 'is possible to go back' do
|
160
|
-
window.url = fixture('forms_with_input_elements.html')
|
161
|
-
window.back.should be_true
|
162
|
-
end
|
163
|
-
|
164
|
-
it 'is false if there is no page to go back to' do
|
165
|
-
# FIXME: We need to open a new window first
|
166
|
-
window.back.should be_false
|
167
|
-
end
|
168
|
-
|
169
|
-
it 'goes back one page in history' do
|
170
|
-
window.url = fixture('forms_with_input_elements.html')
|
171
|
-
window.back
|
172
|
-
window.url.should == fixture('non_control_elements.html')
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
describe '#forward' do
|
177
|
-
it 'is possible to go forward' do
|
178
|
-
window.url = fixture('forms_with_input_elements.html')
|
179
|
-
window.back
|
180
|
-
window.forward.should be_true
|
181
|
-
end
|
182
|
-
|
183
|
-
it 'there is no page to go forward to' do
|
184
|
-
window.forward.should be_false
|
185
|
-
end
|
186
|
-
|
187
|
-
it 'goes forward one page in history' do
|
188
|
-
window.url = fixture('forms_with_input_elements.html')
|
189
|
-
window.back
|
190
|
-
window.forward
|
191
|
-
window.url.should == fixture('forms_with_input_elements.html')
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
describe '#refresh' do
|
196
|
-
it 'refreshes the current page' do
|
197
|
-
window.url = fixture('forms_with_input_elements.html')
|
198
|
-
field = window.find_by_id('new_user_first_name').first
|
199
|
-
field.value = 'foobar'
|
200
|
-
field.value.should == 'foobar'
|
201
|
-
|
202
|
-
window.refresh
|
203
|
-
field.value.should be_empty
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
# actions
|
208
|
-
# -------
|
209
|
-
|
210
|
-
# click(x,y)
|
211
|
-
|
212
|
-
describe '#execute_script' do
|
213
|
-
it 'executes Javascript in the page' do
|
214
|
-
window.execute_script('document.title = "test"')
|
215
|
-
window.title.should == 'test'
|
216
|
-
end
|
217
|
-
|
218
|
-
it 'returns an element when the Javascript does' do
|
219
|
-
window.execute_script('document.createElement("div")').tag_name.should match /div/i
|
220
|
-
end
|
221
|
-
|
222
|
-
it 'returns a number when the Javascript does' do
|
223
|
-
window.execute_script('Math.abs(-5)').should == 5
|
224
|
-
end
|
225
|
-
|
226
|
-
it 'returns a boolean when the Javascript does' do
|
227
|
-
window.execute_script('(function(){return true;})()').should be_true
|
228
|
-
end
|
229
|
-
|
230
|
-
it 'returns an array when the Javascript does' do
|
231
|
-
result = window.execute_script('["this", "is", "a", "test"]') # WTR-227
|
232
|
-
result.length.should == 4
|
233
|
-
result[3].should == 'test'
|
234
|
-
end
|
235
|
-
|
236
|
-
it 'returns a string when the result is not one of these types' do
|
237
|
-
window.execute_script('({one:"two"}).toString()').should == '[object Object]'
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
|
-
# window management
|
242
|
-
# -----------------
|
243
|
-
|
244
|
-
describe '#maximize' do
|
245
|
-
before :each do
|
246
|
-
# Make sure we aren't already maximized
|
247
|
-
window.restore
|
248
|
-
end
|
249
|
-
|
250
|
-
it 'maximizes the window' do
|
251
|
-
body = window.find_by_tag(:body).first
|
252
|
-
width = body.width
|
253
|
-
window.maximize
|
254
|
-
body.width.should be > width
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
describe '#restore' do
|
259
|
-
it 'restores (unmaximizes) the window' do
|
260
|
-
body = window.find_by_tag(:body).first
|
261
|
-
# Make sure we aren't already restored
|
262
|
-
window.maximize
|
263
|
-
width = body.width
|
264
|
-
window.restore
|
265
|
-
body.width.should be < width
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
describe '#exists?' do
|
270
|
-
it 'is true if the window exists' do
|
271
|
-
window.exists?.should be_true
|
272
|
-
end
|
273
|
-
|
274
|
-
it 'is false if the window does not exist' do
|
275
|
-
window.close
|
276
|
-
window.exists?.should be_false
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
describe '#close' do
|
281
|
-
it 'destroys the window' do
|
282
|
-
window.close
|
283
|
-
window.exists?.should be_false
|
284
|
-
window.find_by_tag(:title).should raise_error
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
describe '#new' do
|
289
|
-
it 'creates a new window' do
|
290
|
-
new_window = browser.url(fixture('non_control_elements.html'))
|
291
|
-
new_window.exists?.should be_true
|
292
|
-
new_window.url.should == fixture('non_control_elements.html')
|
293
|
-
end
|
294
|
-
end
|
295
|
-
end
|