watir 1.6.2 → 1.6.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +326 -188
- data/bin/watir-console +7 -8
- data/lib/changes.rb +3 -3
- data/lib/license.rb +38 -38
- data/lib/readme.rb +140 -140
- data/lib/watir/WindowHelper.rb +49 -49
- data/lib/watir/camel_case.rb +66 -45
- data/lib/watir/clickJSDialog.rb +19 -19
- data/lib/watir/close_all.rb +37 -37
- data/lib/watir/collections.rb +344 -312
- data/lib/watir/container.rb +815 -753
- data/lib/watir/contrib/enabled_popup.rb +20 -20
- data/lib/watir/contrib/ie-new-process.rb +27 -27
- data/lib/watir/contrib/page_checker.rb +29 -29
- data/lib/watir/cookiemanager.rb +55 -55
- data/lib/watir/core_ext.rb +18 -0
- data/lib/watir/datahandler.rb +107 -107
- data/lib/watir/dialog.rb +46 -46
- data/lib/watir/element.rb +343 -312
- data/lib/watir/element_collections.rb +97 -81
- data/lib/watir/form.rb +170 -170
- data/lib/watir/frame.rb +59 -59
- data/lib/watir/ie-class.rb +1009 -1003
- data/lib/watir/ie-process.rb +39 -39
- data/lib/watir/ie.rb +133 -132
- data/lib/watir/image.rb +130 -130
- data/lib/watir/input_elements.rb +572 -539
- data/lib/watir/irb-history.rb +30 -30
- data/lib/watir/link.rb +64 -64
- data/lib/watir/locator.rb +176 -161
- data/lib/watir/logger.rb +19 -19
- data/lib/watir/modal_dialog.rb +122 -122
- data/lib/watir/non_control_elements.rb +145 -127
- data/lib/watir/page-container.rb +107 -105
- data/lib/watir/popup.rb +29 -29
- data/lib/watir/process.rb +19 -19
- data/lib/watir/screen_capture.rb +115 -115
- data/lib/watir/setFileDialog.rb +16 -16
- data/lib/watir/table.rb +362 -362
- data/lib/watir/utils.rb +19 -19
- data/lib/watir/version.rb +5 -5
- data/lib/watir/watir_simple.rb +475 -475
- data/lib/watir/win32.rb +35 -28
- data/lib/watir/win32ole.rb +14 -6
- data/lib/watir/winClicker.rb +496 -479
- data/unittests/all_tests.rb +10 -10
- data/unittests/buttons_xpath_test.rb +69 -69
- data/unittests/checkbox_test.rb +179 -176
- data/unittests/checkbox_xpath_test.rb +107 -107
- data/unittests/core_tests.rb +17 -16
- data/unittests/css_test.rb +35 -35
- data/unittests/defer_test.rb +46 -46
- data/unittests/dialog_test.rb +77 -77
- data/unittests/div2_xpath_test.rb +21 -21
- data/unittests/div_test.rb +188 -183
- data/unittests/div_xpath_test.rb +96 -96
- data/unittests/errorchecker_test.rb +22 -22
- data/unittests/filefield_test.rb +39 -40
- data/unittests/filefield_xpath_test.rb +33 -33
- data/unittests/form_test.rb +280 -293
- data/unittests/form_xpath_test.rb +252 -253
- data/unittests/frame_test.rb +155 -157
- data/unittests/google_form_test.rb +15 -15
- data/unittests/html/JavascriptClick.html +39 -39
- data/unittests/html/blankpage.html +11 -11
- data/unittests/html/buttons1.html +40 -40
- data/unittests/html/checkboxes1.html +89 -89
- data/unittests/html/complex_table.html +36 -36
- data/unittests/html/cssTest.html +42 -42
- data/unittests/html/depot_store.html +51 -51
- data/unittests/html/div.html +93 -93
- data/unittests/html/div_xml.html +20 -20
- data/unittests/html/fileupload.html +45 -45
- data/unittests/html/formTest1.html +38 -38
- data/unittests/html/forms2.html +44 -44
- data/unittests/html/forms3.html +131 -131
- data/unittests/html/forms4.html +27 -27
- data/unittests/html/frame_buttons.html +3 -3
- data/unittests/html/frame_links.html +3 -3
- data/unittests/html/frame_multi.html +4 -4
- data/unittests/html/google_india.html +107 -107
- data/unittests/html/iframeTest.html +12 -12
- data/unittests/html/iframeTest1.html +6 -6
- data/unittests/html/iframeTest2.html +5 -5
- data/unittests/html/images1.html +66 -66
- data/unittests/html/javascriptevents.html +35 -35
- data/unittests/html/link_pass.html +10 -10
- data/unittests/html/links1.html +38 -38
- data/unittests/html/links2.html +10 -10
- data/unittests/html/links_multi.html +14 -14
- data/unittests/html/list_matters.html +720 -720
- data/unittests/html/lists.html +17 -17
- data/unittests/html/map_test.html +31 -31
- data/unittests/html/modal_dialog.html +10 -10
- data/unittests/html/modal_dialog_launcher.html +11 -11
- data/unittests/html/nestedFrames.html +6 -6
- data/unittests/html/new_browser.html +16 -16
- data/unittests/html/pass.html +12 -12
- data/unittests/html/popups1.html +59 -59
- data/unittests/html/pre.html +27 -27
- data/unittests/html/radioButtons1.html +71 -71
- data/unittests/html/select_tealeaf.html +54 -54
- data/unittests/html/selectboxes1.html +52 -55
- data/unittests/html/simple_table.html +26 -26
- data/unittests/html/simple_table_buttons.html +104 -104
- data/unittests/html/simple_table_columns.html +76 -76
- data/unittests/html/table1.html +181 -181
- data/unittests/html/tableCell_using_xpath.html +19 -19
- data/unittests/html/textarea.html +30 -30
- data/unittests/html/textfields1.html +88 -88
- data/unittests/html/textsearch.html +44 -44
- data/unittests/html/wallofcheckboxes.html +1003 -1003
- data/unittests/html/xpath_nbsp.html +12 -12
- data/unittests/ie_exists_test.rb +33 -33
- data/unittests/ie_mock.rb +94 -94
- data/unittests/ie_test.rb +51 -50
- data/unittests/images_test.rb +157 -157
- data/unittests/images_xpath_test.rb +91 -91
- data/unittests/links_multi_test.rb +48 -48
- data/unittests/links_test.rb +175 -177
- data/unittests/links_xpath_test.rb +39 -39
- data/unittests/map_test.rb +98 -98
- data/unittests/minmax_test.rb +31 -31
- data/unittests/navigate_test.rb +39 -39
- data/unittests/nbsp_xpath_test.rb +16 -16
- data/unittests/non_core_tests.rb +12 -12
- data/unittests/other/WindowLogonExample.rb +27 -27
- data/unittests/other/WindowLogonExtra.rb +6 -6
- data/unittests/other/all_tests_concurrent.rb +57 -57
- data/unittests/{windows → other}/jscriptExtraAlert.rb +6 -6
- data/unittests/{windows → other}/jscriptExtraConfirmCancel.rb +6 -6
- data/unittests/{windows → other}/jscriptExtraConfirmOk.rb +6 -6
- data/unittests/{windows → other}/jscriptPushButton.rb +6 -6
- data/unittests/{windows → other}/jscript_test.rb +63 -63
- data/unittests/other/navigate_exception_test.rb +24 -24
- data/unittests/other/rexml_unit_test.rb +27 -24
- data/unittests/other/screen_capture_test.rb +54 -54
- data/unittests/other/testcase_method_order_test.rb +35 -35
- data/unittests/other/testcase_verify_test.rb +24 -24
- data/unittests/other/wait_until_test.rb +99 -99
- data/unittests/pagecontainstext_test.rb +69 -69
- data/unittests/parent_child_test.rb +43 -43
- data/unittests/perf_test.rb +20 -20
- data/unittests/popups_test.rb +43 -43
- data/unittests/pre_test.rb +53 -53
- data/unittests/radios_test.rb +212 -212
- data/unittests/radios_xpath_test.rb +101 -101
- data/unittests/security_setting_test.rb +23 -23
- data/unittests/selectbox_test.rb +148 -139
- data/unittests/selectbox_xpath_test.rb +113 -113
- data/unittests/setup.rb +77 -75
- data/unittests/speed_settings_test.rb +67 -65
- data/unittests/table_cell_using_xpath_test.rb +35 -35
- data/unittests/table_test.rb +376 -362
- data/unittests/table_xpath_test.rb +110 -110
- data/unittests/test_tests.rb +9 -9
- data/unittests/textarea_test.rb +92 -92
- data/unittests/textarea_xpath_test.rb +78 -78
- data/unittests/textfield_for_ch_char_test.rb +31 -29
- data/unittests/textfields_test.rb +218 -218
- data/unittests/textfields_xpath_test.rb +111 -111
- data/unittests/window_tests.rb +10 -7
- data/unittests/windows/attach_to_existing_window_test.rb +53 -52
- data/unittests/windows/attach_to_new_window_test.rb +83 -82
- data/unittests/windows/close_window_test.rb +20 -20
- data/unittests/windows/frame_links_test.rb +25 -25
- data/unittests/windows/ie-each_test.rb +47 -47
- data/unittests/windows/iedialog_test.rb +54 -54
- data/unittests/windows/js_events_test.rb +55 -55
- data/unittests/windows/modal_dialog_test.rb +128 -126
- data/unittests/windows/new_test.rb +57 -55
- data/unittests/windows/open_close_test.rb +18 -18
- data/unittests/windows/send_keys_test.rb +33 -32
- data/unittests/xpath_tests.rb +10 -10
- metadata +20 -20
- data/lib/watir/contrib/visible.rb +0 -47
- data/unittests/iostring.rb +0 -30
- data/unittests/iostring_test.rb +0 -48
@@ -1,54 +1,54 @@
|
|
1
|
-
# feature tests for screen capture
|
2
|
-
# revision: $Revision:1338 $
|
3
|
-
|
4
|
-
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
|
5
|
-
require 'unittests/setup'
|
6
|
-
require 'watir/screen_capture'
|
7
|
-
|
8
|
-
class TC_Capture< Test::Unit::TestCase
|
9
|
-
tags :must_be_visible
|
10
|
-
include Watir
|
11
|
-
include Watir::ScreenCapture
|
12
|
-
|
13
|
-
def setup
|
14
|
-
delete_captured_files( [ 'jpeg1.jpg' , 'jpeg2.jpg' , 'bmp1.bmp', 'bmp2.bmp' ] )
|
15
|
-
browser.goto($htmlRoot + 'buttons1.html' )
|
16
|
-
@file_list = []
|
17
|
-
end
|
18
|
-
|
19
|
-
def teardown
|
20
|
-
delete_captured_files
|
21
|
-
end
|
22
|
-
|
23
|
-
def delete_captured_files(files=nil )
|
24
|
-
files = @file_list unless files
|
25
|
-
files.each do |f|
|
26
|
-
File.delete( f) if FileTest.exists?( f)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_jpeg
|
31
|
-
file_name= 'jpeg1.jpg'
|
32
|
-
@file_list << file_name
|
33
|
-
screen_capture( file_name )
|
34
|
-
assert(FileTest.exist?( file_name) )
|
35
|
-
|
36
|
-
file_name= 'jpeg2.jpg'
|
37
|
-
@file_list << file_name
|
38
|
-
screen_capture( file_name , true ) # just the active window
|
39
|
-
assert(FileTest.exist?( file_name) )
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_bmp
|
43
|
-
file_name= 'bmp1.bmp'
|
44
|
-
@file_list << file_name
|
45
|
-
screen_capture( file_name , false, true )
|
46
|
-
assert(FileTest.exist?( file_name ) )
|
47
|
-
|
48
|
-
file_name= 'bmp2.bmp'
|
49
|
-
@file_list << file_name
|
50
|
-
screen_capture( file_name , true , true ) # just the active window
|
51
|
-
assert(FileTest.exist?( file_name) )
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
1
|
+
# feature tests for screen capture
|
2
|
+
# revision: $Revision:1338 $
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
|
5
|
+
require 'unittests/setup'
|
6
|
+
require 'watir/screen_capture'
|
7
|
+
|
8
|
+
class TC_Capture< Test::Unit::TestCase
|
9
|
+
tags :must_be_visible
|
10
|
+
include Watir
|
11
|
+
include Watir::ScreenCapture
|
12
|
+
|
13
|
+
def setup
|
14
|
+
delete_captured_files( [ 'jpeg1.jpg' , 'jpeg2.jpg' , 'bmp1.bmp', 'bmp2.bmp' ] )
|
15
|
+
browser.goto($htmlRoot + 'buttons1.html' )
|
16
|
+
@file_list = []
|
17
|
+
end
|
18
|
+
|
19
|
+
def teardown
|
20
|
+
delete_captured_files
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete_captured_files(files=nil )
|
24
|
+
files = @file_list unless files
|
25
|
+
files.each do |f|
|
26
|
+
File.delete( f) if FileTest.exists?( f)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_jpeg
|
31
|
+
file_name= 'jpeg1.jpg'
|
32
|
+
@file_list << file_name
|
33
|
+
screen_capture( file_name )
|
34
|
+
assert(FileTest.exist?( file_name) )
|
35
|
+
|
36
|
+
file_name= 'jpeg2.jpg'
|
37
|
+
@file_list << file_name
|
38
|
+
screen_capture( file_name , true ) # just the active window
|
39
|
+
assert(FileTest.exist?( file_name) )
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_bmp
|
43
|
+
file_name= 'bmp1.bmp'
|
44
|
+
@file_list << file_name
|
45
|
+
screen_capture( file_name , false, true )
|
46
|
+
assert(FileTest.exist?( file_name ) )
|
47
|
+
|
48
|
+
file_name= 'bmp2.bmp'
|
49
|
+
@file_list << file_name
|
50
|
+
screen_capture( file_name , true , true ) # just the active window
|
51
|
+
assert(FileTest.exist?( file_name) )
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
@@ -1,36 +1,36 @@
|
|
1
|
-
# the default behavior of Test::Unit::TestCase should be to execute test
|
2
|
-
# methods in alphabetical order.
|
3
|
-
# When executed, should print "A.B.C.D.E.F.G.H.I.J.K.L.F"
|
4
|
-
# The final F is actually an expected failure:
|
5
|
-
# 1) Failure:
|
6
|
-
# default_test(TC4_No_Test_Methods)
|
7
|
-
|
8
|
-
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..') unless $SETUP_LOADED
|
9
|
-
|
10
|
-
require 'watir/testcase'
|
11
|
-
|
12
|
-
class TC1_Alphabetical_Default < Watir::TestCase
|
13
|
-
execute :alphabetically
|
14
|
-
def test_b; print 'B'; end
|
15
|
-
def test_a; print 'A'; end
|
16
|
-
def test_d; print 'D'; end
|
17
|
-
def test_c; print 'C'; end
|
18
|
-
end
|
19
|
-
|
20
|
-
class TC2_Sequential < Watir::TestCase
|
21
|
-
def test_b; print 'E'; end
|
22
|
-
def test_a; print 'F'; end
|
23
|
-
def test_d; print 'G'; end
|
24
|
-
def test_c; print 'H'; end
|
25
|
-
end
|
26
|
-
|
27
|
-
class TC3_Alphabetical_Specified < Watir::TestCase
|
28
|
-
execute :alphabetically
|
29
|
-
def test_b; print 'J'; end
|
30
|
-
def test_a; print 'I'; end
|
31
|
-
def test_d; print 'L'; end
|
32
|
-
def test_c; print 'K'; end
|
33
|
-
end
|
34
|
-
|
35
|
-
class TC4_No_Test_Methods < Watir::TestCase
|
1
|
+
# the default behavior of Test::Unit::TestCase should be to execute test
|
2
|
+
# methods in alphabetical order.
|
3
|
+
# When executed, should print "A.B.C.D.E.F.G.H.I.J.K.L.F"
|
4
|
+
# The final F is actually an expected failure:
|
5
|
+
# 1) Failure:
|
6
|
+
# default_test(TC4_No_Test_Methods)
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..') unless $SETUP_LOADED
|
9
|
+
|
10
|
+
require 'watir/testcase'
|
11
|
+
|
12
|
+
class TC1_Alphabetical_Default < Watir::TestCase
|
13
|
+
execute :alphabetically
|
14
|
+
def test_b; print 'B'; end
|
15
|
+
def test_a; print 'A'; end
|
16
|
+
def test_d; print 'D'; end
|
17
|
+
def test_c; print 'C'; end
|
18
|
+
end
|
19
|
+
|
20
|
+
class TC2_Sequential < Watir::TestCase
|
21
|
+
def test_b; print 'E'; end
|
22
|
+
def test_a; print 'F'; end
|
23
|
+
def test_d; print 'G'; end
|
24
|
+
def test_c; print 'H'; end
|
25
|
+
end
|
26
|
+
|
27
|
+
class TC3_Alphabetical_Specified < Watir::TestCase
|
28
|
+
execute :alphabetically
|
29
|
+
def test_b; print 'J'; end
|
30
|
+
def test_a; print 'I'; end
|
31
|
+
def test_d; print 'L'; end
|
32
|
+
def test_c; print 'K'; end
|
33
|
+
end
|
34
|
+
|
35
|
+
class TC4_No_Test_Methods < Watir::TestCase
|
36
36
|
end
|
@@ -1,25 +1,25 @@
|
|
1
|
-
# 3 tests, 10 assertions, 4 failures, 0 errors
|
2
|
-
|
3
|
-
require 'watir/testcase'
|
4
|
-
|
5
|
-
class VerifyTests < Watir::TestCase
|
6
|
-
|
7
|
-
def test_verify
|
8
|
-
verify true
|
9
|
-
assert true
|
10
|
-
verify false
|
11
|
-
assert true
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_verify_equal
|
15
|
-
verify_equal 1, 1
|
16
|
-
verify_equal 1, 2
|
17
|
-
verify_equal 3, 4
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_verify_match
|
21
|
-
verify_match /\d*/, '123'
|
22
|
-
verify_match 'foo', 'foobar'
|
23
|
-
verify_match '...', 'A'
|
24
|
-
end
|
1
|
+
# 3 tests, 10 assertions, 4 failures, 0 errors
|
2
|
+
|
3
|
+
require 'watir/testcase'
|
4
|
+
|
5
|
+
class VerifyTests < Watir::TestCase
|
6
|
+
|
7
|
+
def test_verify
|
8
|
+
verify true
|
9
|
+
assert true
|
10
|
+
verify false
|
11
|
+
assert true
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_verify_equal
|
15
|
+
verify_equal 1, 1
|
16
|
+
verify_equal 1, 2
|
17
|
+
verify_equal 3, 4
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_verify_match
|
21
|
+
verify_match /\d*/, '123'
|
22
|
+
verify_match 'foo', 'foobar'
|
23
|
+
verify_match '...', 'A'
|
24
|
+
end
|
25
25
|
end
|
@@ -1,99 +1,99 @@
|
|
1
|
-
# feature tests for wait_until
|
2
|
-
|
3
|
-
require 'watir/testcase'
|
4
|
-
require 'watir/waiter'
|
5
|
-
require 'watir'
|
6
|
-
require 'spec' # gem install rspec
|
7
|
-
|
8
|
-
# used for unit testing
|
9
|
-
class MockTimeKeeper < Watir::TimeKeeper
|
10
|
-
def sleep seconds
|
11
|
-
@sleep_time += seconds
|
12
|
-
end
|
13
|
-
def now
|
14
|
-
Time.now + @sleep_time
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
class WaitUntilInstanceTest < Watir::TestCase
|
19
|
-
|
20
|
-
def setup
|
21
|
-
@waiter = Watir::Waiter.new
|
22
|
-
@waiter.timeout = 10.0
|
23
|
-
@mock_checkee = Spec::Mocks::Mock.new "mock_checkee"
|
24
|
-
|
25
|
-
# remove this line to test with actual TimeKeeper intead of the Mock
|
26
|
-
# (slower, but more accurate)
|
27
|
-
@waiter.timer = MockTimeKeeper.new
|
28
|
-
end
|
29
|
-
|
30
|
-
def teardown
|
31
|
-
@mock_checkee.__verify if @test_passed
|
32
|
-
end
|
33
|
-
|
34
|
-
# Instance Method
|
35
|
-
|
36
|
-
def test_no_time_passes_if_true
|
37
|
-
@waiter.wait_until {true}
|
38
|
-
@waiter.timer.sleep_time.should_equal 0.0
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_three_tries_before_true
|
42
|
-
@mock_checkee.should_receive(:check).exactly(3).times.and_return [false, false, true]
|
43
|
-
@waiter.wait_until {@mock_checkee.check}
|
44
|
-
@waiter.timer.sleep_time.should_equal 1.0
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_timeout
|
48
|
-
@mock_checkee.should_receive(:check).any_number_of_times.and_return false
|
49
|
-
lambda{@waiter.wait_until {@mock_checkee.check}}.should_raise Watir::Exception::TimeOutException
|
50
|
-
@waiter.timer.sleep_time.should_be_close 10.25, 0.26
|
51
|
-
@waiter.timer.sleep_time.should_satisfy {|x| [10.0, 10.5].include? x}
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_polling_interval
|
55
|
-
@waiter.polling_interval = 0.1
|
56
|
-
@mock_checkee.should_receive(:check).any_number_of_times.and_return false
|
57
|
-
lambda{@waiter.wait_until {@mock_checkee.check}}.should_raise Watir::Exception::TimeOutException
|
58
|
-
@waiter.timer.sleep_time.should_be_close 10.05, 0.07
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_timeout_duration
|
62
|
-
@mock_checkee.should_receive(:check).any_number_of_times.and_return false
|
63
|
-
begin
|
64
|
-
@waiter.wait_until {@mock_checkee.check}
|
65
|
-
flunk
|
66
|
-
rescue Watir::Exception::TimeOutException => e
|
67
|
-
e.duration.should_be_close 10.25, 0.26
|
68
|
-
e.timeout.should_equal 10.0
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
class WaitUntilClassTest < Watir::TestCase
|
74
|
-
|
75
|
-
def setup
|
76
|
-
@mock_checkee = Spec::Mocks::Mock.new "mock_checkee"
|
77
|
-
@mock_checkee.should_receive(:check).exactly(3).times.and_return [false, false, true]
|
78
|
-
end
|
79
|
-
|
80
|
-
def teardown
|
81
|
-
@mock_checkee.__verify if @test_passed
|
82
|
-
end
|
83
|
-
# Class method
|
84
|
-
|
85
|
-
def test_class_method_with_args
|
86
|
-
Watir::Waiter.wait_until(5, 0.1) {@mock_checkee.check}
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_class_method_with_defaults
|
90
|
-
Watir::Waiter.wait_until {@mock_checkee.check}
|
91
|
-
end
|
92
|
-
|
93
|
-
include Watir
|
94
|
-
def test_watir_method
|
95
|
-
wait_until {@mock_checkee.check}
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
|
1
|
+
# feature tests for wait_until
|
2
|
+
|
3
|
+
require 'watir/testcase'
|
4
|
+
require 'watir/waiter'
|
5
|
+
require 'watir'
|
6
|
+
require 'spec' # gem install rspec
|
7
|
+
|
8
|
+
# used for unit testing
|
9
|
+
class MockTimeKeeper < Watir::TimeKeeper
|
10
|
+
def sleep seconds
|
11
|
+
@sleep_time += seconds
|
12
|
+
end
|
13
|
+
def now
|
14
|
+
Time.now + @sleep_time
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class WaitUntilInstanceTest < Watir::TestCase
|
19
|
+
|
20
|
+
def setup
|
21
|
+
@waiter = Watir::Waiter.new
|
22
|
+
@waiter.timeout = 10.0
|
23
|
+
@mock_checkee = Spec::Mocks::Mock.new "mock_checkee"
|
24
|
+
|
25
|
+
# remove this line to test with actual TimeKeeper intead of the Mock
|
26
|
+
# (slower, but more accurate)
|
27
|
+
@waiter.timer = MockTimeKeeper.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def teardown
|
31
|
+
@mock_checkee.__verify if @test_passed
|
32
|
+
end
|
33
|
+
|
34
|
+
# Instance Method
|
35
|
+
|
36
|
+
def test_no_time_passes_if_true
|
37
|
+
@waiter.wait_until {true}
|
38
|
+
@waiter.timer.sleep_time.should_equal 0.0
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_three_tries_before_true
|
42
|
+
@mock_checkee.should_receive(:check).exactly(3).times.and_return [false, false, true]
|
43
|
+
@waiter.wait_until {@mock_checkee.check}
|
44
|
+
@waiter.timer.sleep_time.should_equal 1.0
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_timeout
|
48
|
+
@mock_checkee.should_receive(:check).any_number_of_times.and_return false
|
49
|
+
lambda{@waiter.wait_until {@mock_checkee.check}}.should_raise Watir::Exception::TimeOutException
|
50
|
+
@waiter.timer.sleep_time.should_be_close 10.25, 0.26
|
51
|
+
@waiter.timer.sleep_time.should_satisfy {|x| [10.0, 10.5].include? x}
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_polling_interval
|
55
|
+
@waiter.polling_interval = 0.1
|
56
|
+
@mock_checkee.should_receive(:check).any_number_of_times.and_return false
|
57
|
+
lambda{@waiter.wait_until {@mock_checkee.check}}.should_raise Watir::Exception::TimeOutException
|
58
|
+
@waiter.timer.sleep_time.should_be_close 10.05, 0.07
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_timeout_duration
|
62
|
+
@mock_checkee.should_receive(:check).any_number_of_times.and_return false
|
63
|
+
begin
|
64
|
+
@waiter.wait_until {@mock_checkee.check}
|
65
|
+
flunk
|
66
|
+
rescue Watir::Exception::TimeOutException => e
|
67
|
+
e.duration.should_be_close 10.25, 0.26
|
68
|
+
e.timeout.should_equal 10.0
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class WaitUntilClassTest < Watir::TestCase
|
74
|
+
|
75
|
+
def setup
|
76
|
+
@mock_checkee = Spec::Mocks::Mock.new "mock_checkee"
|
77
|
+
@mock_checkee.should_receive(:check).exactly(3).times.and_return [false, false, true]
|
78
|
+
end
|
79
|
+
|
80
|
+
def teardown
|
81
|
+
@mock_checkee.__verify if @test_passed
|
82
|
+
end
|
83
|
+
# Class method
|
84
|
+
|
85
|
+
def test_class_method_with_args
|
86
|
+
Watir::Waiter.wait_until(5, 0.1) {@mock_checkee.check}
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_class_method_with_defaults
|
90
|
+
Watir::Waiter.wait_until {@mock_checkee.check}
|
91
|
+
end
|
92
|
+
|
93
|
+
include Watir
|
94
|
+
def test_watir_method
|
95
|
+
wait_until {@mock_checkee.check}
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
@@ -1,70 +1,70 @@
|
|
1
|
-
# feature tests for IE::contains_text
|
2
|
-
# revision: $Revision
|
3
|
-
|
4
|
-
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
|
5
|
-
require 'unittests/setup'
|
6
|
-
|
7
|
-
class TC_contains_text < Test::Unit::TestCase
|
8
|
-
|
9
|
-
def setup
|
10
|
-
goto_page "textsearch.html"
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_text_found
|
14
|
-
assert(browser.contains_text('slings and arrows of outrageous fortune'))
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_text_not_found
|
18
|
-
assert_false(browser.contains_text('So are they all, all honourable men'))
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_regexp_found
|
22
|
-
assert(browser.contains_text(/bodkin.*fardels/))
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_regexp_not_found
|
26
|
-
assert_false(browser.contains_text(/winding.*watch.*wit/))
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_match_regexp_found
|
30
|
-
$~ = browser.contains_text(/Messages ([0-9]+)/)
|
31
|
-
assert_equal('42', $1)
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_bad_search_argument
|
35
|
-
assert_raises(ArgumentError) do
|
36
|
-
browser.contains_text
|
37
|
-
end
|
38
|
-
assert_raises(ArgumentError) do
|
39
|
-
browser.contains_text(nil)
|
40
|
-
end
|
41
|
-
assert_raises(ArgumentError) do
|
42
|
-
browser.contains_text(42)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
class TC_contains_text_in_new_ie < Test::Unit::TestCase
|
49
|
-
tags :fails_on_firefox
|
50
|
-
# Doesn't actually raise an error, but fails to close the window afterwards
|
51
|
-
# http://jira.openqa.org/browse/WTR-265
|
52
|
-
def setup
|
53
|
-
@new_browser = Watir::Browser.new
|
54
|
-
end
|
55
|
-
def test_nothing_raised
|
56
|
-
assert_nothing_raised {@new_browser.text.include? ''}
|
57
|
-
end
|
58
|
-
def teardown
|
59
|
-
@new_browser.close
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
class TC_contains_text_in_frame < Test::Unit::TestCase
|
64
|
-
def setup
|
65
|
-
goto_page "frame_links.html"
|
66
|
-
end
|
67
|
-
def test_in_frame
|
68
|
-
assert browser.frame('linkFrame').contains_text('The button is really a link')
|
69
|
-
end
|
1
|
+
# feature tests for IE::contains_text
|
2
|
+
# revision: $Revision$
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
|
5
|
+
require 'unittests/setup'
|
6
|
+
|
7
|
+
class TC_contains_text < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
goto_page "textsearch.html"
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_text_found
|
14
|
+
assert(browser.contains_text('slings and arrows of outrageous fortune'))
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_text_not_found
|
18
|
+
assert_false(browser.contains_text('So are they all, all honourable men'))
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_regexp_found
|
22
|
+
assert(browser.contains_text(/bodkin.*fardels/))
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_regexp_not_found
|
26
|
+
assert_false(browser.contains_text(/winding.*watch.*wit/))
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_match_regexp_found
|
30
|
+
$~ = browser.contains_text(/Messages ([0-9]+)/)
|
31
|
+
assert_equal('42', $1)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_bad_search_argument
|
35
|
+
assert_raises(ArgumentError) do
|
36
|
+
browser.contains_text
|
37
|
+
end
|
38
|
+
assert_raises(ArgumentError) do
|
39
|
+
browser.contains_text(nil)
|
40
|
+
end
|
41
|
+
assert_raises(ArgumentError) do
|
42
|
+
browser.contains_text(42)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
class TC_contains_text_in_new_ie < Test::Unit::TestCase
|
49
|
+
tags :fails_on_firefox
|
50
|
+
# Doesn't actually raise an error, but fails to close the window afterwards
|
51
|
+
# http://jira.openqa.org/browse/WTR-265
|
52
|
+
def setup
|
53
|
+
@new_browser = Watir::Browser.new
|
54
|
+
end
|
55
|
+
def test_nothing_raised
|
56
|
+
assert_nothing_raised {@new_browser.text.include? ''}
|
57
|
+
end
|
58
|
+
def teardown
|
59
|
+
@new_browser.close
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class TC_contains_text_in_frame < Test::Unit::TestCase
|
64
|
+
def setup
|
65
|
+
goto_page "frame_links.html"
|
66
|
+
end
|
67
|
+
def test_in_frame
|
68
|
+
assert browser.frame('linkFrame').contains_text('The button is really a link')
|
69
|
+
end
|
70
70
|
end
|