watir 1.6.5 → 1.6.6.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +461 -326
- data/VERSION +1 -0
- data/bin/watir-console +6 -6
- 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 -66
- data/lib/watir/clickJSDialog.rb +19 -19
- data/lib/watir/close_all.rb +37 -37
- data/lib/watir/collections.rb +392 -344
- data/lib/watir/container.rb +857 -815
- 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.rb +28 -0
- data/lib/watir/core_ext.rb +17 -17
- data/lib/watir/datahandler.rb +107 -107
- data/lib/watir/dialog.rb +46 -46
- data/lib/watir/element.rb +351 -343
- data/lib/watir/element_collections.rb +97 -97
- data/lib/watir/form.rb +170 -170
- data/lib/watir/frame.rb +59 -59
- data/lib/watir/html_element.rb +22 -0
- data/lib/watir/ie-class.rb +1006 -1009
- data/lib/watir/ie-process.rb +39 -39
- data/lib/watir/ie.rb +70 -133
- data/lib/watir/image.rb +130 -130
- data/lib/watir/input_elements.rb +614 -572
- data/lib/watir/irb-history.rb +30 -30
- data/lib/watir/link.rb +64 -64
- data/lib/watir/locator.rb +200 -176
- data/lib/watir/logger.rb +19 -19
- data/lib/watir/modal_dialog.rb +122 -122
- data/lib/watir/module.rb +37 -0
- data/lib/watir/non_control_elements.rb +145 -145
- data/lib/watir/page-container.rb +116 -107
- 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 +395 -362
- data/lib/watir/watir_simple.rb +475 -475
- data/lib/watir/win32.rb +35 -35
- data/lib/watir/win32ole.rb +14 -14
- data/lib/watir/winClicker.rb +496 -496
- data/rakefile.rb +70 -0
- data/unittests/all_tests.rb +10 -10
- data/unittests/buttons_xpath_test.rb +69 -69
- data/unittests/checkbox_test.rb +179 -179
- data/unittests/checkbox_xpath_test.rb +107 -107
- data/unittests/click_no_wait_test.rb +21 -0
- data/unittests/core_tests.rb +17 -17
- data/unittests/css_test.rb +42 -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 -188
- data/unittests/div_xpath_test.rb +96 -96
- data/unittests/element_test.rb +49 -0
- data/unittests/errorchecker_test.rb +32 -22
- data/unittests/filefield_test.rb +39 -39
- data/unittests/filefield_xpath_test.rb +33 -33
- data/unittests/form_test.rb +280 -280
- data/unittests/form_xpath_test.rb +252 -252
- data/unittests/frame_test.rb +155 -155
- 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/click_no_wait.html +14 -0
- data/unittests/html/complex_table.html +36 -36
- data/unittests/html/cssTest.html +42 -42
- data/unittests/html/depot_store.html +59 -59
- 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 +119 -119
- 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 -52
- 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/table_and_tablerow_to_a.html +174 -0
- 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 -51
- 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 -175
- data/unittests/links_xpath_test.rb +39 -39
- data/unittests/lists_test.rb +32 -32
- 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/other/jscriptExtraAlert.rb +6 -6
- data/unittests/other/jscriptExtraConfirmCancel.rb +6 -6
- data/unittests/other/jscriptExtraConfirmOk.rb +6 -6
- data/unittests/other/jscriptPushButton.rb +6 -6
- data/unittests/other/jscript_test.rb +63 -63
- data/unittests/other/navigate_exception_test.rb +24 -24
- data/unittests/other/rexml_unit_test.rb +27 -27
- 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 -148
- data/unittests/selectbox_xpath_test.rb +113 -113
- data/unittests/setup.rb +87 -77
- data/unittests/speed_settings_test.rb +67 -67
- data/unittests/table_and_tablerow_to_a_test.rb +117 -0
- data/unittests/table_cell_using_xpath_test.rb +35 -35
- data/unittests/table_test.rb +376 -376
- 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 -31
- data/unittests/textfields_test.rb +218 -218
- data/unittests/textfields_xpath_test.rb +111 -111
- data/unittests/window_tests.rb +10 -10
- data/unittests/windows/attach_to_existing_window_test.rb +53 -53
- data/unittests/windows/attach_to_new_window_test.rb +83 -83
- 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 +42 -55
- data/unittests/windows/modal_dialog_test.rb +128 -128
- data/unittests/windows/new_test.rb +57 -57
- data/unittests/windows/open_close_test.rb +18 -18
- data/unittests/windows/send_keys_test.rb +33 -33
- data/unittests/xpath_tests.rb +10 -10
- metadata +85 -31
- data/lib/watir/utils.rb +0 -20
- data/lib/watir/version.rb +0 -5
@@ -1,21 +1,21 @@
|
|
1
|
-
# http://www.vbcity.com/forums/topic.asp?tid=108859
|
2
|
-
require 'watir/ie'
|
3
|
-
module Watir
|
4
|
-
module PageContainer
|
5
|
-
include Win32
|
6
|
-
def enabled_popup(timeout=4)
|
7
|
-
# Use handle of our parent window to see if we have any currently
|
8
|
-
# enabled popup.
|
9
|
-
hwnd_modal = 0
|
10
|
-
Waiter.wait_until(timeout) do
|
11
|
-
hwnd_modal, arr = GetWindow.call(hwnd, GW_ENABLEDPOPUP)
|
12
|
-
hwnd_modal > 0
|
13
|
-
end
|
14
|
-
# use hwnd() method to find the IE or Container hwnd (overriden by IE)
|
15
|
-
if hwnd_modal == hwnd() || 0 == hwnd_modal
|
16
|
-
hwnd_modal = nil
|
17
|
-
end
|
18
|
-
hwnd_modal
|
19
|
-
end
|
20
|
-
end
|
1
|
+
# http://www.vbcity.com/forums/topic.asp?tid=108859
|
2
|
+
require 'watir/ie'
|
3
|
+
module Watir
|
4
|
+
module PageContainer
|
5
|
+
include Win32
|
6
|
+
def enabled_popup(timeout=4)
|
7
|
+
# Use handle of our parent window to see if we have any currently
|
8
|
+
# enabled popup.
|
9
|
+
hwnd_modal = 0
|
10
|
+
Waiter.wait_until(timeout) do
|
11
|
+
hwnd_modal, arr = GetWindow.call(hwnd, GW_ENABLEDPOPUP)
|
12
|
+
hwnd_modal > 0
|
13
|
+
end
|
14
|
+
# use hwnd() method to find the IE or Container hwnd (overriden by IE)
|
15
|
+
if hwnd_modal == hwnd() || 0 == hwnd_modal
|
16
|
+
hwnd_modal = nil
|
17
|
+
end
|
18
|
+
hwnd_modal
|
19
|
+
end
|
20
|
+
end
|
21
21
|
end
|
@@ -1,27 +1,27 @@
|
|
1
|
-
# based on http://svn.instiki.org/instiki/trunk/test/watir/e2e.rb
|
2
|
-
# and http://rubyforge.org/pipermail/wtr-general/2005-November/004108.html
|
3
|
-
|
4
|
-
require 'watir/ie-process'
|
5
|
-
|
6
|
-
class IEProcess < Watir::IE::Process
|
7
|
-
def stop
|
8
|
-
right_to_terminate_process = 1
|
9
|
-
handle = Win32API.new('kernel32.dll', 'OpenProcess', 'lil', 'l').
|
10
|
-
call(right_to_terminate_process, 0, @process_id)
|
11
|
-
Win32API.new('kernel32.dll', 'TerminateProcess', 'll', 'l').call(handle, 0)
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
module Watir
|
17
|
-
class IE
|
18
|
-
def process_id
|
19
|
-
@process_id ||= IEProcess.process_id_from_hwnd @ie.hwnd
|
20
|
-
end
|
21
|
-
attr_writer :process_id
|
22
|
-
def kill
|
23
|
-
iep = IEProcess.new process_id
|
24
|
-
iep.stop
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
1
|
+
# based on http://svn.instiki.org/instiki/trunk/test/watir/e2e.rb
|
2
|
+
# and http://rubyforge.org/pipermail/wtr-general/2005-November/004108.html
|
3
|
+
|
4
|
+
require 'watir/ie-process'
|
5
|
+
|
6
|
+
class IEProcess < Watir::IE::Process
|
7
|
+
def stop
|
8
|
+
right_to_terminate_process = 1
|
9
|
+
handle = Win32API.new('kernel32.dll', 'OpenProcess', 'lil', 'l').
|
10
|
+
call(right_to_terminate_process, 0, @process_id)
|
11
|
+
Win32API.new('kernel32.dll', 'TerminateProcess', 'll', 'l').call(handle, 0)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
module Watir
|
17
|
+
class IE
|
18
|
+
def process_id
|
19
|
+
@process_id ||= IEProcess.process_id_from_hwnd @ie.hwnd
|
20
|
+
end
|
21
|
+
attr_writer :process_id
|
22
|
+
def kill
|
23
|
+
iep = IEProcess.new process_id
|
24
|
+
iep.stop
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,29 +1,29 @@
|
|
1
|
-
# This module includes checkers which are run on every page load
|
2
|
-
#
|
3
|
-
# In order to use this module, add a require to one of your test scripts:
|
4
|
-
# require 'watir/contrib/page_checker'
|
5
|
-
# To add checkers, call the ie.add_checker method
|
6
|
-
#
|
7
|
-
# ie.add_checker(PageCheckers::NAVIGATION_CHECKER)
|
8
|
-
#
|
9
|
-
# Checkers are Ruby proc objects which are called within Watir::IE and passed
|
10
|
-
# the current instance of ie.
|
11
|
-
|
12
|
-
module PageCheckers
|
13
|
-
|
14
|
-
# This checker iterates through the current document including any frames
|
15
|
-
# and checks for http errors, 404, 500 etc
|
16
|
-
NAVIGATION_CHECKER = lambda do |ie|
|
17
|
-
if ie.document.frames.length > 1
|
18
|
-
1.upto ie.document.frames.length do |i|
|
19
|
-
begin
|
20
|
-
ie.frame(:index, i).check_for_http_error
|
21
|
-
rescue Watir::Exception::UnknownFrameException
|
22
|
-
# frame can be already destroyed
|
23
|
-
end
|
24
|
-
end
|
25
|
-
else
|
26
|
-
ie.check_for_http_error
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
1
|
+
# This module includes checkers which are run on every page load
|
2
|
+
#
|
3
|
+
# In order to use this module, add a require to one of your test scripts:
|
4
|
+
# require 'watir/contrib/page_checker'
|
5
|
+
# To add checkers, call the ie.add_checker method
|
6
|
+
#
|
7
|
+
# ie.add_checker(PageCheckers::NAVIGATION_CHECKER)
|
8
|
+
#
|
9
|
+
# Checkers are Ruby proc objects which are called within Watir::IE and passed
|
10
|
+
# the current instance of ie.
|
11
|
+
|
12
|
+
module PageCheckers
|
13
|
+
|
14
|
+
# This checker iterates through the current document including any frames
|
15
|
+
# and checks for http errors, 404, 500 etc
|
16
|
+
NAVIGATION_CHECKER = lambda do |ie|
|
17
|
+
if ie.document.frames.length > 1
|
18
|
+
1.upto ie.document.frames.length do |i|
|
19
|
+
begin
|
20
|
+
ie.frame(:index, i).check_for_http_error
|
21
|
+
rescue Watir::Exception::UnknownFrameException
|
22
|
+
# frame can be already destroyed
|
23
|
+
end
|
24
|
+
end
|
25
|
+
else
|
26
|
+
ie.check_for_http_error
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/watir/cookiemanager.rb
CHANGED
@@ -1,56 +1,56 @@
|
|
1
|
-
# should be moved to watir/contrib
|
2
|
-
# use of modules here is ugly
|
3
|
-
|
4
|
-
require 'find'
|
5
|
-
module Watir
|
6
|
-
module CookieManager
|
7
|
-
|
8
|
-
class Dir
|
9
|
-
def Dir.visit(dir = '.', files_first = false, &block)
|
10
|
-
if files_first
|
11
|
-
paths = []
|
12
|
-
Find.find(dir) { |path| paths << path }
|
13
|
-
paths.reverse_each {|path| yield path}
|
14
|
-
else
|
15
|
-
Find.find(dir, &block)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
# simulates unix rm -rf command
|
19
|
-
def Dir.rm_rf(dir)
|
20
|
-
Dir.visit(dir, true) do |path|
|
21
|
-
if FileTest.directory?(path)
|
22
|
-
begin
|
23
|
-
Dir.unlink(path)
|
24
|
-
rescue # Security Exception for Content.IE
|
25
|
-
end
|
26
|
-
else
|
27
|
-
begin
|
28
|
-
File.unlink(path)
|
29
|
-
rescue #Security exception index.dat etc.
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
class WatirHelper
|
37
|
-
#taken from shlObj.h used in win32 SHGetSpecialFolderLocation
|
38
|
-
#define CSIDL_INTERNET_CACHE 0x0020
|
39
|
-
#define CSIDL_COOKIES 0x0021
|
40
|
-
#define CSIDL_HISTORY 0x0022
|
41
|
-
COOKIES = 0x0021
|
42
|
-
INTERNET_CACHE = 0x0020
|
43
|
-
|
44
|
-
def WatirHelper.getSpecialFolderLocation(specFolderName)
|
45
|
-
shell = WIN32OLE.new('Shell.Application')
|
46
|
-
folder = shell.Namespace(specFolderName)
|
47
|
-
folderItem = folder.Self
|
48
|
-
folderPath = folderItem.Path
|
49
|
-
end
|
50
|
-
def WatirHelper.deleteSpecialFolderContents(specFolderName)
|
51
|
-
Dir.rm_rf(self.getSpecialFolderLocation(specFolderName))
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
end
|
1
|
+
# should be moved to watir/contrib
|
2
|
+
# use of modules here is ugly
|
3
|
+
|
4
|
+
require 'find'
|
5
|
+
module Watir
|
6
|
+
module CookieManager
|
7
|
+
|
8
|
+
class Dir
|
9
|
+
def Dir.visit(dir = '.', files_first = false, &block)
|
10
|
+
if files_first
|
11
|
+
paths = []
|
12
|
+
Find.find(dir) { |path| paths << path }
|
13
|
+
paths.reverse_each {|path| yield path}
|
14
|
+
else
|
15
|
+
Find.find(dir, &block)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
# simulates unix rm -rf command
|
19
|
+
def Dir.rm_rf(dir)
|
20
|
+
Dir.visit(dir, true) do |path|
|
21
|
+
if FileTest.directory?(path)
|
22
|
+
begin
|
23
|
+
Dir.unlink(path)
|
24
|
+
rescue # Security Exception for Content.IE
|
25
|
+
end
|
26
|
+
else
|
27
|
+
begin
|
28
|
+
File.unlink(path)
|
29
|
+
rescue #Security exception index.dat etc.
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class WatirHelper
|
37
|
+
#taken from shlObj.h used in win32 SHGetSpecialFolderLocation
|
38
|
+
#define CSIDL_INTERNET_CACHE 0x0020
|
39
|
+
#define CSIDL_COOKIES 0x0021
|
40
|
+
#define CSIDL_HISTORY 0x0022
|
41
|
+
COOKIES = 0x0021
|
42
|
+
INTERNET_CACHE = 0x0020
|
43
|
+
|
44
|
+
def WatirHelper.getSpecialFolderLocation(specFolderName)
|
45
|
+
shell = WIN32OLE.new('Shell.Application')
|
46
|
+
folder = shell.Namespace(specFolderName)
|
47
|
+
folderItem = folder.Self
|
48
|
+
folderPath = folderItem.Path
|
49
|
+
end
|
50
|
+
def WatirHelper.deleteSpecialFolderContents(specFolderName)
|
51
|
+
Dir.rm_rf(self.getSpecialFolderLocation(specFolderName))
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
56
|
end
|
data/lib/watir/core.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# these require statements are needed for Watir
|
2
|
+
# to work with minimum functionality
|
3
|
+
#
|
4
|
+
# this is needed for #click_no_wait to perform faster
|
5
|
+
require 'watir/win32ole'
|
6
|
+
|
7
|
+
require 'logger'
|
8
|
+
require 'watir/exceptions'
|
9
|
+
require 'watir/matches'
|
10
|
+
|
11
|
+
require 'watir/core_ext'
|
12
|
+
require 'watir/logger'
|
13
|
+
require 'watir/container'
|
14
|
+
require 'watir/locator'
|
15
|
+
require 'watir/page-container'
|
16
|
+
require 'watir/ie-class'
|
17
|
+
require 'watir/element'
|
18
|
+
require 'watir/element_collections'
|
19
|
+
require 'watir/form'
|
20
|
+
require 'watir/non_control_elements'
|
21
|
+
require 'watir/input_elements'
|
22
|
+
require 'watir/table'
|
23
|
+
require 'watir/image'
|
24
|
+
require 'watir/link'
|
25
|
+
require 'watir/html_element'
|
26
|
+
|
27
|
+
require 'watir/waiter'
|
28
|
+
require 'watir/module'
|
data/lib/watir/core_ext.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
class String
|
2
|
-
|
3
|
-
#
|
4
|
-
# "Watir::Span" => "Span"
|
5
|
-
#
|
6
|
-
|
7
|
-
def demodulize
|
8
|
-
gsub(/^.*::/, '')
|
9
|
-
end
|
10
|
-
|
11
|
-
#
|
12
|
-
# "FooBar" => "foo_bar"
|
13
|
-
#
|
14
|
-
|
15
|
-
def underscore
|
16
|
-
gsub(/\B[A-Z][^A-Z]/, '_\&').downcase.gsub(' ', '_')
|
17
|
-
end
|
1
|
+
class String
|
2
|
+
|
3
|
+
#
|
4
|
+
# "Watir::Span" => "Span"
|
5
|
+
#
|
6
|
+
|
7
|
+
def demodulize
|
8
|
+
gsub(/^.*::/, '')
|
9
|
+
end
|
10
|
+
|
11
|
+
#
|
12
|
+
# "FooBar" => "foo_bar"
|
13
|
+
#
|
14
|
+
|
15
|
+
def underscore
|
16
|
+
gsub(/\B[A-Z][^A-Z]/, '_\&').downcase.gsub(' ', '_')
|
17
|
+
end
|
18
18
|
end
|
data/lib/watir/datahandler.rb
CHANGED
@@ -1,107 +1,107 @@
|
|
1
|
-
require 'watir/win32ole'
|
2
|
-
|
3
|
-
class String
|
4
|
-
|
5
|
-
def pred
|
6
|
-
self[0..-2] << (self[-1]-1).chr
|
7
|
-
end
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
class DataHandler
|
12
|
-
|
13
|
-
# This allows you to put data in a csv file or an xls file and access it in your scripts for
|
14
|
-
# a data driven approach.
|
15
|
-
#
|
16
|
-
# You can supply a file with extension csv or xls and it will just work
|
17
|
-
#
|
18
|
-
# e.g.
|
19
|
-
# require 'datahandler'
|
20
|
-
# d = DataHandler.new("data.csv")
|
21
|
-
# loginId = d.data[0].LoginId --> line 1 of the csv file and column LoginId
|
22
|
-
# pin = d.data[0].Pin --> line 1 of the cvs file and column Pin
|
23
|
-
#
|
24
|
-
# b = Datahandler.new("data.xls")
|
25
|
-
# loginId = b.data[0].LoginId --> line 1 of workbook 1 of the xls file with column LoginId
|
26
|
-
#
|
27
|
-
# Remember that line 1 of the data is referenced by using 0 - and this excludes the header line.
|
28
|
-
#
|
29
|
-
def initialize(datafile)
|
30
|
-
|
31
|
-
# if the data files are in the same dir as the one you execute from this works
|
32
|
-
directory = `dir`
|
33
|
-
directory.match(/Directory of(.+)$/)
|
34
|
-
working_directory = $1.to_s.gsub(/\\/,"/").gsub(/^\s/,"")
|
35
|
-
file = "#{working_directory.chomp}\\#{datafile}"
|
36
|
-
|
37
|
-
# otherwise it will take the location you specify
|
38
|
-
if File.exists?(file)
|
39
|
-
@datafile = file
|
40
|
-
else
|
41
|
-
@datafile = datafile
|
42
|
-
end
|
43
|
-
|
44
|
-
@excel = WIN32OLE::new('excel.Application')
|
45
|
-
@workbook = @excel.Workbooks.Open(@datafile)
|
46
|
-
@worksheet = @workbook.Worksheets(1)
|
47
|
-
@excel['Visible'] = false
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
def csv_data
|
52
|
-
csv_data = File.readlines(@datafile)
|
53
|
-
header = csv_data[0].split(",")
|
54
|
-
header.each{|z| z.chomp!}
|
55
|
-
data = Struct.new("Data", *header)
|
56
|
-
csv_data.shift
|
57
|
-
data_array = []
|
58
|
-
csv_data.each do |line|
|
59
|
-
line.each{|z| line.chomp!}
|
60
|
-
data_array << data.new(*line.split(","))
|
61
|
-
end
|
62
|
-
return data_array
|
63
|
-
end
|
64
|
-
|
65
|
-
def number_columns
|
66
|
-
column = last_column = "a"
|
67
|
-
while @worksheet.Range("a1:#{column}1")['Value']
|
68
|
-
if !@worksheet.Range("#{column}1")['Value']
|
69
|
-
last_column = column.pred
|
70
|
-
break
|
71
|
-
end
|
72
|
-
column.succ!
|
73
|
-
end
|
74
|
-
last_column
|
75
|
-
end
|
76
|
-
|
77
|
-
def xls_data
|
78
|
-
line = "1"
|
79
|
-
data = []
|
80
|
-
while @worksheet.Range("a#{line}")['Value']
|
81
|
-
data << @worksheet.Range("a#{line}:#{number_columns}#{line}")['Value']
|
82
|
-
line.succ!
|
83
|
-
end
|
84
|
-
|
85
|
-
header = data[0].flatten
|
86
|
-
dataObject = Struct.new("DataObject", *header)
|
87
|
-
data.shift
|
88
|
-
data_array = []
|
89
|
-
data.each do |line|
|
90
|
-
data_array << dataObject.new(*line.flatten)
|
91
|
-
end
|
92
|
-
@excel.Quit
|
93
|
-
@excel = nil
|
94
|
-
GC.start
|
95
|
-
data_array
|
96
|
-
end
|
97
|
-
|
98
|
-
def data
|
99
|
-
extension = @datafile.split(".")[-1]
|
100
|
-
if extension == "xls"
|
101
|
-
xls_data
|
102
|
-
elsif extension == "csv"
|
103
|
-
csv_data
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|
1
|
+
require 'watir/win32ole'
|
2
|
+
|
3
|
+
class String
|
4
|
+
|
5
|
+
def pred
|
6
|
+
self[0..-2] << (self[-1]-1).chr
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
class DataHandler
|
12
|
+
|
13
|
+
# This allows you to put data in a csv file or an xls file and access it in your scripts for
|
14
|
+
# a data driven approach.
|
15
|
+
#
|
16
|
+
# You can supply a file with extension csv or xls and it will just work
|
17
|
+
#
|
18
|
+
# e.g.
|
19
|
+
# require 'datahandler'
|
20
|
+
# d = DataHandler.new("data.csv")
|
21
|
+
# loginId = d.data[0].LoginId --> line 1 of the csv file and column LoginId
|
22
|
+
# pin = d.data[0].Pin --> line 1 of the cvs file and column Pin
|
23
|
+
#
|
24
|
+
# b = Datahandler.new("data.xls")
|
25
|
+
# loginId = b.data[0].LoginId --> line 1 of workbook 1 of the xls file with column LoginId
|
26
|
+
#
|
27
|
+
# Remember that line 1 of the data is referenced by using 0 - and this excludes the header line.
|
28
|
+
#
|
29
|
+
def initialize(datafile)
|
30
|
+
|
31
|
+
# if the data files are in the same dir as the one you execute from this works
|
32
|
+
directory = `dir`
|
33
|
+
directory.match(/Directory of(.+)$/)
|
34
|
+
working_directory = $1.to_s.gsub(/\\/,"/").gsub(/^\s/,"")
|
35
|
+
file = "#{working_directory.chomp}\\#{datafile}"
|
36
|
+
|
37
|
+
# otherwise it will take the location you specify
|
38
|
+
if File.exists?(file)
|
39
|
+
@datafile = file
|
40
|
+
else
|
41
|
+
@datafile = datafile
|
42
|
+
end
|
43
|
+
|
44
|
+
@excel = WIN32OLE::new('excel.Application')
|
45
|
+
@workbook = @excel.Workbooks.Open(@datafile)
|
46
|
+
@worksheet = @workbook.Worksheets(1)
|
47
|
+
@excel['Visible'] = false
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
def csv_data
|
52
|
+
csv_data = File.readlines(@datafile)
|
53
|
+
header = csv_data[0].split(",")
|
54
|
+
header.each{|z| z.chomp!}
|
55
|
+
data = Struct.new("Data", *header)
|
56
|
+
csv_data.shift
|
57
|
+
data_array = []
|
58
|
+
csv_data.each do |line|
|
59
|
+
line.each{|z| line.chomp!}
|
60
|
+
data_array << data.new(*line.split(","))
|
61
|
+
end
|
62
|
+
return data_array
|
63
|
+
end
|
64
|
+
|
65
|
+
def number_columns
|
66
|
+
column = last_column = "a"
|
67
|
+
while @worksheet.Range("a1:#{column}1")['Value']
|
68
|
+
if !@worksheet.Range("#{column}1")['Value']
|
69
|
+
last_column = column.pred
|
70
|
+
break
|
71
|
+
end
|
72
|
+
column.succ!
|
73
|
+
end
|
74
|
+
last_column
|
75
|
+
end
|
76
|
+
|
77
|
+
def xls_data
|
78
|
+
line = "1"
|
79
|
+
data = []
|
80
|
+
while @worksheet.Range("a#{line}")['Value']
|
81
|
+
data << @worksheet.Range("a#{line}:#{number_columns}#{line}")['Value']
|
82
|
+
line.succ!
|
83
|
+
end
|
84
|
+
|
85
|
+
header = data[0].flatten
|
86
|
+
dataObject = Struct.new("DataObject", *header)
|
87
|
+
data.shift
|
88
|
+
data_array = []
|
89
|
+
data.each do |line|
|
90
|
+
data_array << dataObject.new(*line.flatten)
|
91
|
+
end
|
92
|
+
@excel.Quit
|
93
|
+
@excel = nil
|
94
|
+
GC.start
|
95
|
+
data_array
|
96
|
+
end
|
97
|
+
|
98
|
+
def data
|
99
|
+
extension = @datafile.split(".")[-1]
|
100
|
+
if extension == "xls"
|
101
|
+
xls_data
|
102
|
+
elsif extension == "csv"
|
103
|
+
csv_data
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|