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,40 @@
|
|
1
|
+
require 'dl/import'
|
2
|
+
require 'dl/struct'
|
3
|
+
require 'Win32API'
|
4
|
+
|
5
|
+
module Watir
|
6
|
+
module Win32
|
7
|
+
# this will find the IEDialog.dll file in its build location
|
8
|
+
@@iedialog_file = (File.expand_path(File.dirname(__FILE__) + '/..') + "/watir-classic/IEDialog/Release/IEDialog.dll").gsub('/', '\\')
|
9
|
+
|
10
|
+
GetUnknown = Win32API.new(@@iedialog_file, 'GetUnknown', ['l', 'p'], 'v')
|
11
|
+
User32 = DL.dlopen('user32')
|
12
|
+
if RUBY_VERSION =~ /^1\.8/
|
13
|
+
FindWindowEx = User32['FindWindowEx', 'LLLpp']
|
14
|
+
# method for this found in wet-winobj/wet/winobjects/WinUtils.rb
|
15
|
+
GetWindow = User32['GetWindow', 'ILL']
|
16
|
+
IsWindow = User32['IsWindow', 'II']
|
17
|
+
else
|
18
|
+
FindWindowEx = GetWindow = IsWindow = lambda do |*args|
|
19
|
+
raise NotImplementedError, "1.9's DL API not compatible with 1.8, see http://www.ruby-forum.com/topic/138277"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
## GetWindows Constants
|
24
|
+
GW_HWNDFIRST = 0
|
25
|
+
GW_HWNDLAST = 1
|
26
|
+
GW_HWNDNEXT = 2
|
27
|
+
GW_HWNDPREV = 3
|
28
|
+
GW_OWNER = 4
|
29
|
+
GW_CHILD = 5
|
30
|
+
GW_ENABLEDPOPUP = 6
|
31
|
+
GW_MAX = 6
|
32
|
+
|
33
|
+
|
34
|
+
# Does the window with the specified window handle (hwnd) exist?
|
35
|
+
def self.window_exists? hwnd
|
36
|
+
rtn, junk = IsWindow[hwnd]
|
37
|
+
rtn == 1
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# load the correct version of win32ole
|
2
|
+
|
3
|
+
# Use our modified win32ole library
|
4
|
+
|
5
|
+
if RUBY_VERSION =~ /^1\.8/
|
6
|
+
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'watir-classic', 'win32ole', '1.8.7'))
|
7
|
+
elsif RUBY_VERSION =~ /^1\.9/
|
8
|
+
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'watir-classic', 'win32ole', '1.9.3'))
|
9
|
+
else
|
10
|
+
# loading win32ole from stdlib
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
require 'win32ole'
|
15
|
+
|
16
|
+
WIN32OLE.codepage = WIN32OLE::CP_UTF8
|
Binary file
|
Binary file
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Watir
|
2
|
+
class Window
|
3
|
+
include ElementExtensions
|
4
|
+
|
5
|
+
class << self
|
6
|
+
attr_accessor :__main_ie
|
7
|
+
|
8
|
+
def wrap *meths
|
9
|
+
meths.each do |meth|
|
10
|
+
define_method meth do
|
11
|
+
result = nil
|
12
|
+
use {result = browser.send(meth)}
|
13
|
+
result
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(main_browser, locators, browser=nil, &blk)
|
20
|
+
valid_locators = [:title, :url, :hwnd, :index]
|
21
|
+
locators.each_pair do |k, v|
|
22
|
+
raise ArgumentError, "Valid locators are #{valid_locators.join(", ")}" unless valid_locators.include?(k)
|
23
|
+
end
|
24
|
+
@main_browser = main_browser
|
25
|
+
self.class.__main_ie = main_browser.ie
|
26
|
+
@locators = locators
|
27
|
+
@browser = browser
|
28
|
+
end
|
29
|
+
|
30
|
+
wrap :url, :title, :hwnd, :close
|
31
|
+
|
32
|
+
def browser
|
33
|
+
@browser ||= begin
|
34
|
+
IE.find(@locators.keys.first, @locators.values.first)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def use(&blk)
|
39
|
+
@main_browser.ie = browser.ie
|
40
|
+
if blk
|
41
|
+
begin
|
42
|
+
blk.call
|
43
|
+
ensure
|
44
|
+
@main_browser.ie = self.class.__main_ie
|
45
|
+
# try to find some existing IE when needed
|
46
|
+
@main_browser.ie = IE._find(:index, 0) unless @main_browser.exists?
|
47
|
+
end
|
48
|
+
end
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
def current?
|
53
|
+
@main_browser.hwnd == browser.hwnd && @main_browser.html == browser.html
|
54
|
+
end
|
55
|
+
|
56
|
+
def ==(other)
|
57
|
+
browser.hwnd == other.hwnd && browser.html == other.browser.html
|
58
|
+
end
|
59
|
+
|
60
|
+
alias_method :eql?, :==
|
61
|
+
|
62
|
+
def present?
|
63
|
+
@browser = nil
|
64
|
+
browser && browser.exists?
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Watir
|
2
|
+
module XpathLocator
|
3
|
+
|
4
|
+
def xmlparser_document_object
|
5
|
+
@xml_parser_doc ||= begin
|
6
|
+
require 'nokogiri'
|
7
|
+
Nokogiri.parse("<html>#{@container.html}</html>")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# execute css selector and return an array of elements
|
12
|
+
def elements_by_css(selector)
|
13
|
+
xmlparser_document_object # Needed to ensure Nokogiri has been loaded
|
14
|
+
xpath = Nokogiri::CSS.xpath_for(selector)[0]
|
15
|
+
elements_by_xpath(xpath)
|
16
|
+
end
|
17
|
+
|
18
|
+
# return the first element that matches the css selector
|
19
|
+
def element_by_css(selector)
|
20
|
+
elements_by_css(selector)[0]
|
21
|
+
end
|
22
|
+
|
23
|
+
# return the first element that matches the xpath
|
24
|
+
def element_by_xpath(xpath)
|
25
|
+
elements_by_xpath(xpath)[0]
|
26
|
+
end
|
27
|
+
|
28
|
+
# execute xpath selector and return an array of elements
|
29
|
+
def elements_by_xpath(xpath)
|
30
|
+
doc = xmlparser_document_object
|
31
|
+
current_tag = @container.is_a?(IE) ? "body" : @container.tag_name
|
32
|
+
|
33
|
+
doc.xpath(xpath).reduce([]) do |elements, element|
|
34
|
+
absolute_xpath_parts = element.path.split("/")
|
35
|
+
first_tag_position = absolute_xpath_parts.index(current_tag) || absolute_xpath_parts.index("html") + 1
|
36
|
+
element_xpath_parts = absolute_xpath_parts[first_tag_position..-1]
|
37
|
+
elements << element_xpath_parts.reduce(@container.page_container) do |container, tag|
|
38
|
+
tag_name, index = tag.split(/[\[\]]/)
|
39
|
+
index = index ? index.to_i - 1 : 0
|
40
|
+
specifiers = {:tag_name => [tag_name]}
|
41
|
+
direct_children(container, container.send(:elements, specifiers))[index]
|
42
|
+
end.ole_object
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def direct_children container, elements
|
47
|
+
return elements if container.is_a?(IE)
|
48
|
+
elements.select {|el| el.parent == container}
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
data/rakefile.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rake/packagetask'
|
5
|
+
require 'rake/testtask'
|
6
|
+
require 'rake/rdoctask'
|
7
|
+
require 'rake/gempackagetask'
|
8
|
+
|
9
|
+
require './watir-rdoc'
|
10
|
+
|
11
|
+
$VERBOSE = nil
|
12
|
+
desc 'Generate Watir API Documentation'
|
13
|
+
Rake::RDocTask.new('rdoc') do |rdoc|
|
14
|
+
rdoc.rdoc_dir = 'rdoc'
|
15
|
+
rdoc.options += $WATIR_RDOC_OPTIONS
|
16
|
+
rdoc.rdoc_files.include('lib/watir-classic/ie.rb')
|
17
|
+
$WATIR_EXTRA_RDOC_FILES.each do |file|
|
18
|
+
rdoc.rdoc_files.include(file)
|
19
|
+
end
|
20
|
+
rdoc.rdoc_files.include('lib/watir-classic/contrib/*.rb')
|
21
|
+
rdoc.rdoc_files.include('lib/watir-classic/dialogs/*.rb')
|
22
|
+
rdoc.rdoc_files.include('lib/watir-classic/*.rb')
|
23
|
+
rdoc.rdoc_files.exclude('lib/watir-classic/camel_case.rb')
|
24
|
+
end
|
25
|
+
|
26
|
+
Rake::TestTask.new do |t|
|
27
|
+
t.test_files = FileList['unittests/core_tests.rb']
|
28
|
+
t.verbose = true
|
29
|
+
end
|
30
|
+
|
31
|
+
CLEAN << 'pkg' << 'rdoc'
|
32
|
+
|
33
|
+
|
34
|
+
desc 'Attach to an active IE window'
|
35
|
+
task :attach do
|
36
|
+
sh "irb.bat -r attach.rb"
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :package
|
40
|
+
|
41
|
+
if defined? Rake::GemPackageTask
|
42
|
+
|
43
|
+
gemspec = eval(File.read('watir-classic.gemspec'))
|
44
|
+
|
45
|
+
Rake::GemPackageTask.new(gemspec) do |p|
|
46
|
+
p.gem_spec = gemspec
|
47
|
+
p.need_tar = false
|
48
|
+
p.need_zip = false
|
49
|
+
end
|
50
|
+
|
51
|
+
else
|
52
|
+
puts 'Warning: without Rubygems packaging tasks are not available'
|
53
|
+
end
|
54
|
+
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# feature tests for Buttons
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
|
4
|
+
require 'unittests/setup'
|
5
|
+
|
6
|
+
class TC_Buttons_XPath < Test::Unit::TestCase
|
7
|
+
include Watir::Exception
|
8
|
+
|
9
|
+
def setup
|
10
|
+
goto_page "buttons1.html"
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_properties
|
14
|
+
assert_raises(UnknownObjectException) { browser.button(:xpath, "//input[@name='noName']/").id }
|
15
|
+
assert_raises(UnknownObjectException) { browser.button(:xpath, "//input[@name='noName']/").name }
|
16
|
+
assert_raises(UnknownObjectException) { browser.button(:xpath, "//input[@name='noName']/").disabled }
|
17
|
+
assert_raises(UnknownObjectException) { browser.button(:xpath, "//input[@name='noName']/").type }
|
18
|
+
assert_raises(UnknownObjectException) { browser.button(:xpath, "//input[@name='noName']/").value }
|
19
|
+
|
20
|
+
assert_equal("b1" , browser.button(:xpath, "//input[@id='b2']/").name )
|
21
|
+
assert_equal("b2" , browser.button(:xpath, "//input[@id='b2']/").id )
|
22
|
+
assert_equal("button" , browser.button(:xpath, "//input[@id='b2']/").type )
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_button_using_default
|
26
|
+
# since most of the time, a button will be accessed based on its caption, there is a default way of accessing it....
|
27
|
+
assert_raises(UnknownObjectException) { browser.button(:xpath, "//input[@value='Missing Caption']/").click }
|
28
|
+
|
29
|
+
browser.button(:xpath, "//input[@value='Click Me']/").click
|
30
|
+
assert(browser.text.include?("PASS") )
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_Button_click_only
|
34
|
+
browser.button(:xpath, "//input[@value='Click Me']/").click
|
35
|
+
assert(browser.text.include?("PASS") )
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_button_click
|
39
|
+
assert_raises(UnknownObjectException) { browser.button(:xpath, "//input[@value='Missing Caption']/").click }
|
40
|
+
assert_raises(UnknownObjectException) { browser.button(:xpath, "//input[@id='MissingId']/").click }
|
41
|
+
|
42
|
+
assert_raises(ObjectDisabledException , "ObjectDisabledException was supposed to be thrown" ) { browser.button(:xpath, "//input[@value='Disabled Button']/").click }
|
43
|
+
|
44
|
+
browser.button(:xpath, "//input[@value='Click Me']/").click
|
45
|
+
assert(browser.text.include?("PASS") )
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_Button_Exists
|
49
|
+
assert(browser.button(:xpath, "//input[@value='Click Me']/").exists?)
|
50
|
+
assert(browser.button(:xpath, "//input[@value='Submit']/").exists?)
|
51
|
+
assert(browser.button(:xpath, "//input[@name='b1']/").exists?)
|
52
|
+
assert(browser.button(:xpath, "//input[@id='b2']/").exists?)
|
53
|
+
|
54
|
+
assert_false(browser.button(:xpath, "//input[@value='Missing Caption']/").exists?)
|
55
|
+
assert_false(browser.button(:xpath, "//input[@name='missingname']/").exists?)
|
56
|
+
assert_false(browser.button(:xpath, "//input[@id='missingid']/").exists?)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_Button_Enabled
|
60
|
+
assert(browser.button(:xpath, "//input[@value='Click Me']/").enabled?)
|
61
|
+
assert_false(browser.button(:xpath, "//input[@value='Disabled Button']/").enabled?)
|
62
|
+
assert_false(browser.button(:xpath, "//input[@name='b4']/").enabled?)
|
63
|
+
assert_false(browser.button(:xpath, "//input[@id='b5']/").enabled?)
|
64
|
+
|
65
|
+
assert_raises(UnknownObjectException) { browser.button(:xpath, "//input[@name='noName']/").enabled? }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
@@ -0,0 +1,163 @@
|
|
1
|
+
# feature tests for Check Boxes
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
|
4
|
+
require 'unittests/setup'
|
5
|
+
|
6
|
+
class TC_CheckBox < Test::Unit::TestCase
|
7
|
+
include Watir::Exception
|
8
|
+
|
9
|
+
def setup
|
10
|
+
goto_page "checkboxes1.html"
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_checkbox_exceptions
|
14
|
+
assert_raises(UnknownObjectException) { browser.checkbox(:name, "noName").id }
|
15
|
+
assert_raises(UnknownObjectException) { browser.checkbox(:name, "noName").name }
|
16
|
+
assert_raises(UnknownObjectException) { browser.checkbox(:name, "noName").disabled? }
|
17
|
+
assert_raises(UnknownObjectException) { browser.checkbox(:name, "noName").type }
|
18
|
+
assert_raises(UnknownObjectException) { browser.checkbox(:name, "noName").value }
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_checkbox_properties_with_index
|
22
|
+
assert_equal("box1", browser.checkbox(:index, 0).name )
|
23
|
+
assert_equal("", browser.checkbox(:index, 0).id )
|
24
|
+
assert_equal("checkbox", browser.checkbox(:index, 0).type )
|
25
|
+
assert_equal("on", browser.checkbox(:index, 0).value )
|
26
|
+
assert_equal(false, browser.checkbox(:index, 0).disabled? )
|
27
|
+
end
|
28
|
+
def test_checkbox_properties
|
29
|
+
assert_equal("check_box_style", browser.checkbox(:name, "box1").class_name)
|
30
|
+
assert_equal("", browser.checkbox(:name, "box2").class_name)
|
31
|
+
|
32
|
+
assert_equal("1", browser.checkbox(:name, "box4").value )
|
33
|
+
assert_equal("3", browser.checkbox(:name => "box4", :value => 3).value )
|
34
|
+
assert(browser.checkbox(:name, "box6").exists?)
|
35
|
+
assert_equal("checkbox", browser.checkbox(:name => "box4", :value => 3).type )
|
36
|
+
assert_equal("checkbox", browser.checkbox(:name => "box6", :value => 'Milk').type )
|
37
|
+
assert_equal(false, browser.checkbox(:name => "box4", :value => 3).disabled? )
|
38
|
+
assert_equal("", browser.checkbox(:name => "box4", :value => 3).id )
|
39
|
+
|
40
|
+
assert_equal("box4-value5", browser.checkbox(:name => "box4", :value => 5).title)
|
41
|
+
assert_equal("", browser.checkbox(:name => "box4", :value => 4).title)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_onClick
|
45
|
+
assert_false(browser.button(:value, "foo").enabled?)
|
46
|
+
browser.checkbox(:name, "box5").set
|
47
|
+
assert(browser.button(:value, "foo").enabled?)
|
48
|
+
|
49
|
+
browser.checkbox(:name, "box5").clear
|
50
|
+
assert_false(browser.button(:value, "foo").enabled?)
|
51
|
+
|
52
|
+
browser.checkbox(:name, "box5").clear
|
53
|
+
assert_false(browser.button(:value, "foo").enabled?)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_CheckBox_Exists
|
57
|
+
assert(browser.checkbox(:name, "box1").exists?)
|
58
|
+
assert_false(browser.checkbox(:name, "missing").exists?)
|
59
|
+
|
60
|
+
assert(browser.checkbox(:name => "box4", :value => 1).exists?)
|
61
|
+
assert_false(browser.checkbox(:name => "box4", :value => 22).exists?)
|
62
|
+
|
63
|
+
assert(browser.checkbox(:name => "box4", :value => /[0-9]/).exists?)
|
64
|
+
assert_false(browser.checkbox(:name => "box4", :value => /\d\d\d/).exists?)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_checkbox_Enabled
|
68
|
+
assert_raises(UnknownObjectException) { browser.checkbox(:name, "noName").enabled? }
|
69
|
+
assert_raises(UnknownObjectException) { browser.checkbox(:id, "noName").enabled? }
|
70
|
+
assert_raises(UnknownObjectException) { browser.checkbox(:name => "box4", :value => 6).enabled? }
|
71
|
+
|
72
|
+
assert(browser.checkbox(:name, "box1").enabled?)
|
73
|
+
assert_false(browser.checkbox(:name, "box2").enabled?)
|
74
|
+
|
75
|
+
assert(browser.checkbox(:name => "box4", :value => 4).enabled?)
|
76
|
+
assert_false(browser.checkbox(:name =>"box4", :value => 5 ).enabled?)
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_checkbox_isSet
|
80
|
+
assert_raises(UnknownObjectException ) { browser.checkbox(:name, "noName").set? }
|
81
|
+
|
82
|
+
assert_false(browser.checkbox(:name, "box1").set?)
|
83
|
+
assert_false(browser.checkbox(:name, "box2").set?)
|
84
|
+
assert(browser.checkbox(:name, "box3").set?)
|
85
|
+
|
86
|
+
assert_false(browser.checkbox(:name => "box4", :value => 2 ).set?)
|
87
|
+
assert(browser.checkbox(:name => "box4", :value => 1 ).set?)
|
88
|
+
|
89
|
+
assert_false(browser.checkbox(:name => 'box6', :value => 'Milk').set?)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_checkbox_clear
|
93
|
+
assert_raises(UnknownObjectException) { browser.checkbox(:name, "noName").clear }
|
94
|
+
browser.checkbox(:name, "box1").clear
|
95
|
+
assert_false(browser.checkbox(:name, "box1").set?)
|
96
|
+
|
97
|
+
assert_raises(ObjectDisabledException) { browser.checkbox(:name, "box2").clear }
|
98
|
+
assert_false(browser.checkbox(:name, "box2").set?)
|
99
|
+
|
100
|
+
browser.checkbox(:name, "box3").clear
|
101
|
+
assert_false(browser.checkbox(:name, "box3").set?)
|
102
|
+
|
103
|
+
browser.checkbox(:name => "box4", :value => 1).clear
|
104
|
+
assert_false(browser.checkbox(:name => "box4", :value => 1).set?)
|
105
|
+
|
106
|
+
browser.checkbox(:name => "box6", :value => 'Tea').clear
|
107
|
+
assert_false(browser.checkbox(:name => "box6", :value => 'Tea').set?)
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_checkbox_set
|
111
|
+
assert_raises(UnknownObjectException) { browser.checkbox(:name, "noName").set }
|
112
|
+
browser.checkbox(:name, "box1").set
|
113
|
+
assert(browser.checkbox(:name, "box1").set?)
|
114
|
+
|
115
|
+
assert_raises(ObjectDisabledException) { browser.checkbox(:name, "box2").set }
|
116
|
+
|
117
|
+
browser.checkbox(:name, "box3").set
|
118
|
+
assert(browser.checkbox(:name, "box3").set?)
|
119
|
+
|
120
|
+
# checkboxes that have the same name but different values
|
121
|
+
browser.checkbox(:name => "box4", :value => 3).set
|
122
|
+
assert(browser.checkbox(:name => "box4", :value => 3).set?)
|
123
|
+
|
124
|
+
# test set using the optinal true/false
|
125
|
+
# assumes the checkbox is already checked
|
126
|
+
browser.checkbox(:name, "box1").set( false )
|
127
|
+
assert_false(browser.checkbox(:name, "box1").set?)
|
128
|
+
|
129
|
+
browser.checkbox(:name, "box1").set( true )
|
130
|
+
assert(browser.checkbox(:name, "box1").set?)
|
131
|
+
|
132
|
+
browser.checkbox(:name => "box6", :value => 'Tea').set( false )
|
133
|
+
assert_false(browser.checkbox(:name => "box6", :value => 'Tea').set?)
|
134
|
+
|
135
|
+
browser.checkbox(:name => "box6", :value => 'Tea').set( true )
|
136
|
+
assert(browser.checkbox(:name => "box6", :value => 'Tea').set?)
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_checkboxes_access
|
140
|
+
assert_equal("box1" , browser.checkboxes[0].name )
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_checkbox_iterator
|
144
|
+
assert_equal(13, browser.checkboxes.length)
|
145
|
+
index = 0
|
146
|
+
browser.checkboxes.each do |c|
|
147
|
+
# puts "#{index}: #{c.name}"
|
148
|
+
assert_equal( browser.checkbox(:index, index).name , c.name )
|
149
|
+
assert_equal( browser.checkbox(:index, index).id, c.id )
|
150
|
+
assert_equal( browser.checkbox(:index, index).value, c.value )
|
151
|
+
index += 1
|
152
|
+
end
|
153
|
+
assert_equal(index, browser.checkboxes.length)
|
154
|
+
end
|
155
|
+
|
156
|
+
# bug 217
|
157
|
+
tag_method :test_checkbox_access_by_ole_object, :fails_on_firefox
|
158
|
+
def test_checkbox_access_by_ole_object
|
159
|
+
ole = browser.checkboxes[1].locate
|
160
|
+
browser.checkbox(:ole_object, ole).flash
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|