watir-classic 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +721 -0
- data/LICENSE +34 -0
- data/README.rdoc +78 -0
- data/VERSION +1 -0
- data/bin/watir-console +5 -0
- data/lib/watir-classic.rb +14 -0
- data/lib/watir-classic/IEDialog/Release/IEDialog.dll +0 -0
- data/lib/watir-classic/assertions.rb +44 -0
- data/lib/watir-classic/browser.rb +149 -0
- data/lib/watir-classic/browsers.rb +7 -0
- data/lib/watir-classic/close_all.rb +31 -0
- data/lib/watir-classic/container.rb +110 -0
- data/lib/watir-classic/contrib/enabled_popup.rb +21 -0
- data/lib/watir-classic/contrib/ie-new-process.rb +27 -0
- data/lib/watir-classic/contrib/page_checker.rb +29 -0
- data/lib/watir-classic/cookies.rb +80 -0
- data/lib/watir-classic/core.rb +43 -0
- data/lib/watir-classic/dialogs/file_field.rb +34 -0
- data/lib/watir-classic/dialogs/javascript.rb +43 -0
- data/lib/watir-classic/drag_and_drop_helper.rb +68 -0
- data/lib/watir-classic/element.rb +438 -0
- data/lib/watir-classic/element_collection.rb +109 -0
- data/lib/watir-classic/element_extensions.rb +69 -0
- data/lib/watir-classic/exceptions.rb +50 -0
- data/lib/watir-classic/form.rb +96 -0
- data/lib/watir-classic/frame.rb +47 -0
- data/lib/watir-classic/ie-class.rb +767 -0
- data/lib/watir-classic/ie-process.rb +47 -0
- data/lib/watir-classic/ie.rb +20 -0
- data/lib/watir-classic/image.rb +111 -0
- data/lib/watir-classic/input_elements.rb +480 -0
- data/lib/watir-classic/irb-history.rb +31 -0
- data/lib/watir-classic/link.rb +46 -0
- data/lib/watir-classic/locator.rb +243 -0
- data/lib/watir-classic/logger.rb +19 -0
- data/lib/watir-classic/matches.rb +23 -0
- data/lib/watir-classic/modal_dialog.rb +72 -0
- data/lib/watir-classic/module.rb +12 -0
- data/lib/watir-classic/non_control_elements.rb +114 -0
- data/lib/watir-classic/options.rb +56 -0
- data/lib/watir-classic/page-container.rb +114 -0
- data/lib/watir-classic/process.rb +20 -0
- data/lib/watir-classic/screen_capture.rb +115 -0
- data/lib/watir-classic/supported_elements.rb +172 -0
- data/lib/watir-classic/table.rb +224 -0
- data/lib/watir-classic/testcase.rb +97 -0
- data/lib/watir-classic/util.rb +35 -0
- data/lib/watir-classic/version.rb +4 -0
- data/lib/watir-classic/wait.rb +41 -0
- data/lib/watir-classic/wait_helper.rb +12 -0
- data/lib/watir-classic/waiter.rb +98 -0
- data/lib/watir-classic/win32.rb +40 -0
- data/lib/watir-classic/win32ole.rb +16 -0
- data/lib/watir-classic/win32ole/1.8.7/win32ole.so +0 -0
- data/lib/watir-classic/win32ole/1.9.3/win32ole.so +0 -0
- data/lib/watir-classic/window.rb +68 -0
- data/lib/watir-classic/xpath_locator.rb +52 -0
- data/rakefile.rb +54 -0
- data/unittests/all_tests.rb +10 -0
- data/unittests/buttons_xpath_test.rb +68 -0
- data/unittests/checkbox_test.rb +163 -0
- data/unittests/checkbox_xpath_test.rb +106 -0
- data/unittests/click_no_wait_test.rb +23 -0
- data/unittests/close_all_test.rb +17 -0
- data/unittests/core_tests.rb +17 -0
- data/unittests/css_selector_test.rb +44 -0
- data/unittests/css_test.rb +38 -0
- data/unittests/dialog_test.rb +64 -0
- data/unittests/div2_xpath_test.rb +21 -0
- data/unittests/div_test.rb +170 -0
- data/unittests/div_xpath_test.rb +95 -0
- data/unittests/document_standards.rb +63 -0
- data/unittests/element_collection_indexes_test.rb +57 -0
- data/unittests/element_collections_test.rb +100 -0
- data/unittests/element_test.rb +47 -0
- data/unittests/errorchecker_test.rb +31 -0
- data/unittests/filefield_test.rb +43 -0
- data/unittests/filefield_xpath_test.rb +35 -0
- data/unittests/form_test.rb +282 -0
- data/unittests/form_xpath_test.rb +254 -0
- data/unittests/frame_test.rb +165 -0
- data/unittests/google_form_test.rb +15 -0
- data/unittests/html/JavascriptClick.html +39 -0
- data/unittests/html/blankpage.html +11 -0
- data/unittests/html/buttons1.html +40 -0
- data/unittests/html/checkboxes1.html +89 -0
- data/unittests/html/click_no_wait.html +14 -0
- data/unittests/html/complex_table.html +35 -0
- data/unittests/html/cssTest.html +42 -0
- data/unittests/html/depot_store.html +59 -0
- data/unittests/html/div.html +92 -0
- data/unittests/html/div_xml.html +21 -0
- data/unittests/html/fileupload.html +44 -0
- data/unittests/html/formTest1.html +38 -0
- data/unittests/html/forms2.html +44 -0
- data/unittests/html/forms3.html +131 -0
- data/unittests/html/forms4.html +26 -0
- data/unittests/html/frame_buttons.html +4 -0
- data/unittests/html/frame_links.html +4 -0
- data/unittests/html/frame_multi.html +5 -0
- data/unittests/html/google_india.html +119 -0
- data/unittests/html/ie7_document_standards.html +9 -0
- data/unittests/html/ie8_document_standards.html +9 -0
- data/unittests/html/ie9_document_standards.html +9 -0
- data/unittests/html/iframe.html +3 -0
- data/unittests/html/iframeTest.html +17 -0
- data/unittests/html/iframeTest1.html +7 -0
- data/unittests/html/iframeTest2.html +5 -0
- data/unittests/html/images/1.gif +0 -0
- data/unittests/html/images/2.GIF +0 -0
- data/unittests/html/images/3.GIF +0 -0
- data/unittests/html/images/button.jpg +0 -0
- data/unittests/html/images/circle.jpg +0 -0
- data/unittests/html/images/map.GIF +0 -0
- data/unittests/html/images/map2.gif +0 -0
- data/unittests/html/images/minus.GIF +0 -0
- data/unittests/html/images/originaltriangle.jpg +0 -0
- data/unittests/html/images/plus.gif +0 -0
- data/unittests/html/images/square.jpg +0 -0
- data/unittests/html/images/triangle.jpg +0 -0
- data/unittests/html/images1.html +65 -0
- data/unittests/html/javascriptevents.html +33 -0
- data/unittests/html/link_pass.html +11 -0
- data/unittests/html/links1.html +37 -0
- data/unittests/html/links2.html +11 -0
- data/unittests/html/links_multi.html +12 -0
- data/unittests/html/list_matters.html +720 -0
- data/unittests/html/lists.html +18 -0
- data/unittests/html/map_test.html +30 -0
- data/unittests/html/modal_dialog.html +10 -0
- data/unittests/html/modal_dialog_launcher.html +12 -0
- data/unittests/html/multiple_specifiers.html +64 -0
- data/unittests/html/nestedFrames.html +6 -0
- data/unittests/html/new_browser.html +17 -0
- data/unittests/html/pass.html +13 -0
- data/unittests/html/popups1.html +59 -0
- data/unittests/html/pre.html +29 -0
- data/unittests/html/quirks_document_standards.html +8 -0
- data/unittests/html/radioButtons1.html +71 -0
- data/unittests/html/select_tealeaf.html +54 -0
- data/unittests/html/selectboxes1.html +52 -0
- data/unittests/html/simple_table.html +25 -0
- data/unittests/html/simple_table_buttons.html +104 -0
- data/unittests/html/simple_table_columns.html +75 -0
- data/unittests/html/table1.html +179 -0
- data/unittests/html/tableCell_using_xpath.html +19 -0
- data/unittests/html/table_and_tablerow_to_a.html +174 -0
- data/unittests/html/textarea.html +30 -0
- data/unittests/html/textfields1.html +100 -0
- data/unittests/html/textsearch.html +44 -0
- data/unittests/html/wallofcheckboxes.html +1003 -0
- data/unittests/html/xpath_nbsp.html +11 -0
- data/unittests/html/zeroindex.html +11 -0
- data/unittests/ie_exists_test.rb +16 -0
- data/unittests/ie_mock.rb +94 -0
- data/unittests/ie_test.rb +54 -0
- data/unittests/images_test.rb +156 -0
- data/unittests/images_xpath_test.rb +90 -0
- data/unittests/index_specifier_test.rb +31 -0
- data/unittests/js_events_test.rb +31 -0
- data/unittests/links_multi_test.rb +34 -0
- data/unittests/links_test.rb +131 -0
- data/unittests/links_xpath_test.rb +38 -0
- data/unittests/lists_test.rb +23 -0
- data/unittests/map_test.rb +98 -0
- data/unittests/minmax_test.rb +37 -0
- data/unittests/navigate_test.rb +38 -0
- data/unittests/nbsp_xpath_test.rb +16 -0
- data/unittests/no_wait_test.rb +28 -0
- data/unittests/non_core_tests.rb +12 -0
- data/unittests/other/all_tests_concurrent.rb +57 -0
- data/unittests/other/navigate_exception_test.rb +24 -0
- data/unittests/other/rexml_unit_test.rb +27 -0
- data/unittests/other/screen_capture_test.rb +53 -0
- data/unittests/other/testcase_method_order_test.rb +36 -0
- data/unittests/other/testcase_verify_test.rb +25 -0
- data/unittests/other/wait_until_test.rb +102 -0
- data/unittests/pagecontainstext_test.rb +69 -0
- data/unittests/parent_child_test.rb +27 -0
- data/unittests/perf_test.rb +20 -0
- data/unittests/pre_test.rb +49 -0
- data/unittests/radios_test.rb +181 -0
- data/unittests/radios_xpath_test.rb +100 -0
- data/unittests/security_setting_test.rb +24 -0
- data/unittests/selectbox_test.rb +144 -0
- data/unittests/selectbox_xpath_test.rb +102 -0
- data/unittests/setup.rb +69 -0
- data/unittests/speed_settings_test.rb +67 -0
- data/unittests/table_cell_using_xpath_test.rb +34 -0
- data/unittests/table_test.rb +296 -0
- data/unittests/table_xpath_test.rb +109 -0
- data/unittests/test_tests.rb +9 -0
- data/unittests/textarea_test.rb +92 -0
- data/unittests/textarea_xpath_test.rb +77 -0
- data/unittests/textfield_for_ch_char_test.rb +32 -0
- data/unittests/textfields_test.rb +184 -0
- data/unittests/textfields_xpath_test.rb +110 -0
- data/unittests/version_test.rb +15 -0
- data/unittests/win32ole_so_test.rb +35 -0
- data/unittests/window_tests.rb +10 -0
- data/unittests/windows/attach_to_existing_window_test.rb +52 -0
- data/unittests/windows/attach_to_new_window_test.rb +74 -0
- data/unittests/windows/close_window_test.rb +20 -0
- data/unittests/windows/frame_links_test.rb +23 -0
- data/unittests/windows/ie-each_test.rb +46 -0
- data/unittests/windows/modal_dialog_test.rb +95 -0
- data/unittests/windows/new_process_test.rb +24 -0
- data/unittests/windows/new_test.rb +58 -0
- data/unittests/windows/open_close_test.rb +19 -0
- data/unittests/windows/send_keys_test.rb +26 -0
- data/unittests/xpath_tests.rb +11 -0
- data/watir-rdoc.rb +7 -0
- metadata +370 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
|
2
|
+
require 'unittests/setup'
|
3
|
+
|
4
|
+
class TC_No_Wait_Commands < Test::Unit::TestCase
|
5
|
+
def test_fire_event_no_wait
|
6
|
+
goto_page "javascriptevents.html"
|
7
|
+
browser.text_field(:index, 0).fire_event_no_wait("onkeyup")
|
8
|
+
assert_nothing_raised{
|
9
|
+
Watir::Wait.until {browser.div(:id, 'event_name').text == 'onkeyup'}
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_set_no_wait_text_field
|
14
|
+
goto_page "textfields1.html"
|
15
|
+
browser.text_field(:name, "text1").set_no_wait("watir IE Controller")
|
16
|
+
assert_nothing_raised{
|
17
|
+
Watir::Wait.until {browser.text_field(:name, "text1").value == "watir IE Controller"}
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_select_no_wait_text_select_list
|
22
|
+
goto_page "selectboxes1.html"
|
23
|
+
browser.select_list(:name,'sel1').select_no_wait(/Option 1/)
|
24
|
+
assert_nothing_raised{
|
25
|
+
Watir::Wait.until {browser.select_list(:name , 'sel1').selected_options.first.text == 'Option 1'}
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
TOPDIR = File.join(File.dirname(__FILE__), '..')
|
2
|
+
$LOAD_PATH.unshift TOPDIR
|
3
|
+
|
4
|
+
require 'unittests/setup.rb'
|
5
|
+
|
6
|
+
Dir.chdir TOPDIR
|
7
|
+
$all_tests.each {|x| require x}
|
8
|
+
|
9
|
+
Watir::UnitTest.filter = proc do |test|
|
10
|
+
test.class.to_s !~ /xpath/i &&
|
11
|
+
test.class.tags.include?(:must_be_visible)
|
12
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# This is an UNFINISHED attempt to run the unit tests currently.
|
2
|
+
# The work on the harness is complete.
|
3
|
+
# The problem remaining is that the tests are not thread-safe.
|
4
|
+
# It's an open question whether getting this to work would actually save any execution time.
|
5
|
+
|
6
|
+
TOPDIR = File.join(File.dirname(__FILE__), '..')
|
7
|
+
$LOAD_PATH.unshift TOPDIR
|
8
|
+
Dir.chdir TOPDIR
|
9
|
+
#(Dir["unittests/*_test.rb"] - ["unittests/popups_test.rb"]).each {|x| require x}
|
10
|
+
|
11
|
+
require 'unittests/buttons_test'
|
12
|
+
require 'unittests/checkbox_test'
|
13
|
+
|
14
|
+
require 'test/unit/testsuite'
|
15
|
+
require 'thread'
|
16
|
+
class ConcurrentTestSuite < Test::Unit::TestSuite
|
17
|
+
|
18
|
+
# Runs the tests and/or suites contained in this TestSuite.
|
19
|
+
def run(result, &progress_block)
|
20
|
+
yield(STARTED, name)
|
21
|
+
threads = []
|
22
|
+
@tests.each do |test|
|
23
|
+
threads << Thread.new do
|
24
|
+
test.run(result, &progress_block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
threads.each {|t| t.join}
|
28
|
+
yield(FINISHED, name)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# create a suite
|
33
|
+
require 'test/unit/collector/objectspace'
|
34
|
+
|
35
|
+
require 'test/unit/collector'
|
36
|
+
include Test::Unit::Collector
|
37
|
+
|
38
|
+
|
39
|
+
@filters = []
|
40
|
+
suite = ConcurrentTestSuite.new('super suite')
|
41
|
+
sub_suites = []
|
42
|
+
::ObjectSpace.each_object(Class) do |klass|
|
43
|
+
if(Test::Unit::TestCase > klass)
|
44
|
+
puts sub_suites, klass.suite
|
45
|
+
add_suite(sub_suites, klass.suite)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
sort(sub_suites).each{|s| suite << s}
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
# select a runner
|
53
|
+
require 'test/unit/ui/console/testrunner'
|
54
|
+
Test::Unit::UI::Console::TestRunner.run(suite)
|
55
|
+
|
56
|
+
|
57
|
+
# then subclass Test::Unit::TestSuite and override the run method to be multithreaded
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# feature tests for navigation errors
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..') unless $SETUP_LOADED
|
4
|
+
require 'unittests/setup'
|
5
|
+
require 'watir-classic/contrib/page_checker'
|
6
|
+
# To add checkers, call the ie.add_checker method
|
7
|
+
#
|
8
|
+
# ie.
|
9
|
+
|
10
|
+
class TC_NavigateException < Test::Unit::TestCase
|
11
|
+
include Watir
|
12
|
+
|
13
|
+
def setup
|
14
|
+
browser.add_checker(PageCheckers::NAVIGATION_CHECKER)
|
15
|
+
end
|
16
|
+
def teardown
|
17
|
+
browser.disable_checker(PageCheckers::NAVIGATION_CHECKER)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_http_errors
|
21
|
+
assert_raises(NavigationException) { browser.goto('http://localhost:3001') } # Cannot find server or DNS Error
|
22
|
+
assert_raises(NavigationException) { browser.goto('http://www.fxruby.org/dfdf' ) } # HTTP 404 - File not found
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
class XPathTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
file = File.open( "xpath_bug.xml" )
|
7
|
+
@doc = Nokogiri::HTML::Document.read_io(file, nil, nil, 2145)
|
8
|
+
end
|
9
|
+
def fixture xpath
|
10
|
+
matches = []
|
11
|
+
|
12
|
+
@doc.xpath(xpath).each() do |node|
|
13
|
+
matches << node
|
14
|
+
assert_equal('Add', node.text)
|
15
|
+
assert_equal('ButtonText', node['class'])
|
16
|
+
end
|
17
|
+
|
18
|
+
assert_equal(1, matches.length)
|
19
|
+
end
|
20
|
+
def test_text
|
21
|
+
fixture "//div[text()='Add' and @class='ButtonText']"
|
22
|
+
end
|
23
|
+
def test_contains
|
24
|
+
fixture "//div[contains(.,'Add') and @class='ButtonText']"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# feature tests for screen capture
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
|
4
|
+
require 'unittests/setup'
|
5
|
+
require 'watir-classic/screen_capture'
|
6
|
+
|
7
|
+
class TC_Capture< Test::Unit::TestCase
|
8
|
+
tags :must_be_visible
|
9
|
+
include Watir
|
10
|
+
include Watir::ScreenCapture
|
11
|
+
|
12
|
+
def setup
|
13
|
+
delete_captured_files( [ 'jpeg1.jpg' , 'jpeg2.jpg' , 'bmp1.bmp', 'bmp2.bmp' ] )
|
14
|
+
browser.goto($htmlRoot + 'buttons1.html' )
|
15
|
+
@file_list = []
|
16
|
+
end
|
17
|
+
|
18
|
+
def teardown
|
19
|
+
delete_captured_files
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete_captured_files(files=nil )
|
23
|
+
files = @file_list unless files
|
24
|
+
files.each do |f|
|
25
|
+
File.delete( f) if FileTest.exists?( f)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_jpeg
|
30
|
+
file_name= 'jpeg1.jpg'
|
31
|
+
@file_list << file_name
|
32
|
+
screen_capture( file_name )
|
33
|
+
assert(FileTest.exist?( file_name) )
|
34
|
+
|
35
|
+
file_name= 'jpeg2.jpg'
|
36
|
+
@file_list << file_name
|
37
|
+
screen_capture( file_name , true ) # just the active window
|
38
|
+
assert(FileTest.exist?( file_name) )
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_bmp
|
42
|
+
file_name= 'bmp1.bmp'
|
43
|
+
@file_list << file_name
|
44
|
+
screen_capture( file_name , false, true )
|
45
|
+
assert(FileTest.exist?( file_name ) )
|
46
|
+
|
47
|
+
file_name= 'bmp2.bmp'
|
48
|
+
@file_list << file_name
|
49
|
+
screen_capture( file_name , true , true ) # just the active window
|
50
|
+
assert(FileTest.exist?( file_name) )
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
@@ -0,0 +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-classic/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
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# 3 tests, 10 assertions, 4 failures, 0 errors
|
2
|
+
|
3
|
+
require 'watir-classic/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
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# feature tests for wait_until
|
2
|
+
#
|
3
|
+
# Watir::Waiter is DEPRECATED! Use methods from Watir::Wait and Watir::ElementExtensions instead!
|
4
|
+
#
|
5
|
+
|
6
|
+
require 'watir-classic/testcase'
|
7
|
+
require 'watir-classic/waiter'
|
8
|
+
require 'watir-classic'
|
9
|
+
require 'spec' # gem install rspec
|
10
|
+
|
11
|
+
# used for unit testing
|
12
|
+
class MockTimeKeeper < Watir::TimeKeeper
|
13
|
+
def sleep seconds
|
14
|
+
@sleep_time += seconds
|
15
|
+
end
|
16
|
+
def now
|
17
|
+
Time.now + @sleep_time
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class WaitUntilInstanceTest < Watir::TestCase
|
22
|
+
|
23
|
+
def setup
|
24
|
+
@waiter = Watir::Waiter.new
|
25
|
+
@waiter.timeout = 10.0
|
26
|
+
@mock_checkee = Spec::Mocks::Mock.new "mock_checkee"
|
27
|
+
|
28
|
+
# remove this line to test with actual TimeKeeper intead of the Mock
|
29
|
+
# (slower, but more accurate)
|
30
|
+
@waiter.timer = MockTimeKeeper.new
|
31
|
+
end
|
32
|
+
|
33
|
+
def teardown
|
34
|
+
@mock_checkee.__verify if @test_passed
|
35
|
+
end
|
36
|
+
|
37
|
+
# Instance Method
|
38
|
+
|
39
|
+
def test_no_time_passes_if_true
|
40
|
+
@waiter.wait_until {true}
|
41
|
+
@waiter.timer.sleep_time.should_equal 0.0
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_three_tries_before_true
|
45
|
+
@mock_checkee.should_receive(:check).exactly(3).times.and_return [false, false, true]
|
46
|
+
@waiter.wait_until {@mock_checkee.check}
|
47
|
+
@waiter.timer.sleep_time.should_equal 1.0
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_timeout
|
51
|
+
@mock_checkee.should_receive(:check).any_number_of_times.and_return false
|
52
|
+
lambda{@waiter.wait_until {@mock_checkee.check}}.should_raise Watir::Exception::TimeOutException
|
53
|
+
@waiter.timer.sleep_time.should_be_close 10.25, 0.26
|
54
|
+
@waiter.timer.sleep_time.should_satisfy {|x| [10.0, 10.5].include? x}
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_polling_interval
|
58
|
+
@waiter.polling_interval = 0.1
|
59
|
+
@mock_checkee.should_receive(:check).any_number_of_times.and_return false
|
60
|
+
lambda{@waiter.wait_until {@mock_checkee.check}}.should_raise Watir::Exception::TimeOutException
|
61
|
+
@waiter.timer.sleep_time.should_be_close 10.05, 0.07
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_timeout_duration
|
65
|
+
@mock_checkee.should_receive(:check).any_number_of_times.and_return false
|
66
|
+
begin
|
67
|
+
@waiter.wait_until {@mock_checkee.check}
|
68
|
+
flunk
|
69
|
+
rescue Watir::Exception::TimeOutException => e
|
70
|
+
e.duration.should_be_close 10.25, 0.26
|
71
|
+
e.timeout.should_equal 10.0
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class WaitUntilClassTest < Watir::TestCase
|
77
|
+
|
78
|
+
def setup
|
79
|
+
@mock_checkee = Spec::Mocks::Mock.new "mock_checkee"
|
80
|
+
@mock_checkee.should_receive(:check).exactly(3).times.and_return [false, false, true]
|
81
|
+
end
|
82
|
+
|
83
|
+
def teardown
|
84
|
+
@mock_checkee.__verify if @test_passed
|
85
|
+
end
|
86
|
+
# Class method
|
87
|
+
|
88
|
+
def test_class_method_with_args
|
89
|
+
Watir::Waiter.wait_until(5, 0.1) {@mock_checkee.check}
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_class_method_with_defaults
|
93
|
+
Watir::Waiter.wait_until {@mock_checkee.check}
|
94
|
+
end
|
95
|
+
|
96
|
+
include Watir
|
97
|
+
def test_watir_classic_method
|
98
|
+
wait_until {@mock_checkee.check}
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# feature tests for IE::contains_text
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
|
4
|
+
require 'unittests/setup'
|
5
|
+
|
6
|
+
class TC_contains_text < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
goto_page "textsearch.html"
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_text_found
|
13
|
+
assert(browser.contains_text('slings and arrows of outrageous fortune'))
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_text_not_found
|
17
|
+
assert_false(browser.contains_text('So are they all, all honourable men'))
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_regexp_found
|
21
|
+
assert(browser.contains_text(/bodkin.*fardels/))
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_regexp_not_found
|
25
|
+
assert_false(browser.contains_text(/winding.*watch.*wit/))
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_match_regexp_found
|
29
|
+
$~ = browser.contains_text(/Messages ([0-9]+)/)
|
30
|
+
assert_equal('42', $1)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_bad_search_argument
|
34
|
+
assert_raises(ArgumentError) do
|
35
|
+
browser.contains_text
|
36
|
+
end
|
37
|
+
assert_raises(ArgumentError) do
|
38
|
+
browser.contains_text(nil)
|
39
|
+
end
|
40
|
+
assert_raises(ArgumentError) do
|
41
|
+
browser.contains_text(42)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
class TC_contains_text_in_new_ie < Test::Unit::TestCase
|
48
|
+
tags :fails_on_firefox
|
49
|
+
# Doesn't actually raise an error, but fails to close the window afterwards
|
50
|
+
# http://jira.openqa.org/browse/WTR-265
|
51
|
+
def setup
|
52
|
+
@new_browser = Watir::Browser.new
|
53
|
+
end
|
54
|
+
def test_nothing_raised
|
55
|
+
assert_nothing_raised {@new_browser.text.include? ''}
|
56
|
+
end
|
57
|
+
def teardown
|
58
|
+
@new_browser.close
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class TC_contains_text_in_frame < Test::Unit::TestCase
|
63
|
+
def setup
|
64
|
+
goto_page "frame_links.html"
|
65
|
+
end
|
66
|
+
def test_in_frame
|
67
|
+
assert browser.frame(:name => 'linkFrame').contains_text('The button is really a link')
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# feature tests for relative navigation/specification
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
|
4
|
+
require 'unittests/setup'
|
5
|
+
|
6
|
+
class TC_Relative < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
goto_page "depot_store.html"
|
10
|
+
@headline = browser.h3(:text, 'Pragmatic Version Control')
|
11
|
+
end
|
12
|
+
|
13
|
+
tag_method :test_parent, :fails_on_firefox
|
14
|
+
def test_parent
|
15
|
+
catalog_entry = @headline.parent
|
16
|
+
link = catalog_entry.link(:class, 'addtocart')
|
17
|
+
assert_equal 'http://localhost:3000/store/add_to_cart/12', link.href
|
18
|
+
assert_nothing_raised{link.click}
|
19
|
+
end
|
20
|
+
|
21
|
+
tag_method :test_parent_page_container, :fails_on_firefox
|
22
|
+
def test_parent_page_container
|
23
|
+
catalog_entry = @headline.parent
|
24
|
+
assert_not_nil catalog_entry.page_container
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|