watir 1.4.1 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/watir-console +1 -0
- data/changes.rb +119 -0
- data/license.rb +37 -0
- data/readme.rb +55 -120
- data/unittests/buttons_test.rb +107 -104
- data/unittests/buttons_xpath_test.rb +69 -0
- data/unittests/checkbox_test.rb +154 -141
- data/unittests/checkbox_xpath_test.rb +107 -0
- data/unittests/core_tests.rb +6 -2
- data/unittests/css_test.rb +50 -50
- data/unittests/defer_test.rb +47 -0
- data/unittests/dialog_test.rb +78 -0
- data/unittests/div2_xpath_test.rb +22 -0
- data/unittests/div_test.rb +159 -159
- data/unittests/div_xpath_test.rb +96 -0
- data/unittests/errorchecker_test.rb +22 -22
- data/unittests/filefield_test.rb +30 -23
- data/unittests/filefield_xpath_test.rb +35 -0
- data/unittests/form_test.rb +250 -229
- data/unittests/form_xpath_test.rb +253 -0
- data/unittests/frame_test.rb +123 -108
- data/unittests/google_form_test.rb +17 -0
- data/unittests/html/JavascriptClick.html +39 -0
- data/unittests/html/buttons1.html +3 -2
- data/unittests/html/checkboxes1.html +32 -14
- data/unittests/html/complex_table.html +1 -1
- data/unittests/html/depot_store.html +59 -0
- data/unittests/html/div.html +3 -21
- data/unittests/html/div_xml.html +21 -0
- data/unittests/html/fileupload.html +2 -2
- data/unittests/html/forms2.html +3 -3
- data/unittests/html/forms3.html +2 -2
- data/unittests/html/frame_links.html +2 -2
- data/unittests/html/google_india.html +119 -0
- data/unittests/html/iframeTest.html +2 -2
- data/unittests/html/images/map.GIF +0 -0
- data/unittests/html/images/map2.gif +0 -0
- data/unittests/html/images1.html +17 -2
- data/unittests/html/javascriptevents.html +3 -7
- data/unittests/html/links1.html +9 -8
- data/unittests/html/links_multi.html +14 -0
- data/unittests/html/list_matters.html +720 -0
- data/unittests/html/lists.html +18 -0
- data/unittests/html/map_test.html +31 -0
- data/unittests/html/modal_dialog.html +10 -0
- data/unittests/html/modal_dialog_launcher.html +12 -0
- data/unittests/html/new_browser.html +17 -0
- data/unittests/html/pass.html +3 -0
- data/unittests/html/popups1.html +1 -1
- data/unittests/html/pre.html +28 -0
- data/unittests/html/radioButtons1.html +6 -5
- data/unittests/html/selectboxes1.html +12 -11
- data/unittests/html/simple_table.html +1 -1
- data/unittests/html/simple_table_columns.html +1 -1
- data/unittests/html/table1.html +1 -1
- data/unittests/html/tableCell_using_xpath.html +19 -0
- data/unittests/html/textfields1.html +6 -4
- data/unittests/html/xpath_nbsp.html +12 -0
- data/unittests/ie_exists_test.rb +32 -0
- data/unittests/ie_mock.rb +78 -79
- data/unittests/ie_test.rb +39 -39
- data/unittests/images_test.rb +132 -155
- data/unittests/images_xpath_test.rb +91 -0
- data/unittests/links_multi_test.rb +36 -0
- data/unittests/links_test.rb +158 -152
- data/unittests/links_xpath_test.rb +40 -0
- data/unittests/lists_test.rb +29 -0
- data/unittests/map_test.rb +99 -0
- data/unittests/minmax_test.rb +23 -23
- data/unittests/navigate_test.rb +43 -51
- data/unittests/nbsp_xpath_test.rb +18 -0
- data/unittests/other/WindowLogonExample.rb +28 -0
- data/unittests/{WindowLogonExtra.rb → other/WindowLogonExtra.rb} +0 -0
- data/unittests/{all_tests_concurrent.rb → other/all_tests_concurrent.rb} +23 -23
- data/unittests/other/navigate_exception_test.rb +14 -0
- data/unittests/other/rexml_unit_test.rb +24 -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 +99 -0
- data/unittests/pagecontainstext_test.rb +56 -37
- data/unittests/parent_child_test.rb +55 -0
- data/unittests/popups_test.rb +37 -37
- data/unittests/pre_test.rb +52 -0
- data/unittests/radios_test.rb +186 -155
- data/unittests/radios_xpath_test.rb +101 -0
- data/unittests/screen_capture_test.rb +41 -41
- data/unittests/selectbox_test.rb +223 -181
- data/unittests/selectbox_xpath_test.rb +113 -0
- data/unittests/setup.rb +29 -25
- data/unittests/speed_settings_test.rb +22 -0
- data/unittests/table_cell_using_xpath_test.rb +40 -0
- data/unittests/table_test.rb +315 -284
- data/unittests/table_xpath_test.rb +114 -0
- data/unittests/textarea_test.rb +81 -0
- data/unittests/textarea_xpath_test.rb +82 -0
- data/unittests/textfields_test.rb +205 -229
- data/unittests/textfields_xpath_test.rb +111 -0
- data/unittests/window_tests.rb +7 -0
- data/unittests/windows/attach_to_existing_window_test.rb +52 -0
- data/unittests/windows/attach_to_new_window_test.rb +82 -0
- data/unittests/windows/close_window_test.rb +22 -0
- data/unittests/windows/frame_links_test.rb +25 -0
- data/unittests/windows/ie-each_test.rb +48 -0
- data/unittests/windows/iedialog_test.rb +55 -0
- data/unittests/windows/js_events_test.rb +57 -0
- data/unittests/windows/jscriptExtraAlert.rb +6 -0
- data/unittests/windows/jscriptExtraConfirmCancel.rb +7 -0
- data/unittests/windows/jscriptExtraConfirmOk.rb +7 -0
- data/unittests/{jscriptPushButton.rb → windows/jscriptPushButton.rb} +1 -1
- data/unittests/windows/jscript_test.rb +64 -0
- data/unittests/windows/modal_dialog_test.rb +127 -0
- data/unittests/windows/new.rb +56 -0
- data/unittests/windows/open_close_test.rb +22 -0
- data/unittests/windows/send_keys_test.rb +34 -0
- data/unittests/xpath_tests.rb +10 -0
- data/watir.rb +4344 -3565
- data/watir/IEDialog/Release/IEDialog.dll +0 -0
- data/watir/WindowHelper.rb +13 -11
- data/watir/assertions.rb +36 -0
- data/watir/camel_case.rb +14 -5
- data/watir/close_all.rb +38 -0
- data/watir/contrib/enabled_popup.rb +21 -0
- data/watir/contrib/ie-new-process.rb +27 -0
- data/watir/contrib/page_checker.rb +29 -0
- data/watir/contrib/visible.rb +47 -0
- data/watir/cookiemanager.rb +4 -4
- data/watir/datahandler.rb +107 -0
- data/watir/dialog.rb +46 -0
- data/watir/elements.rb +65 -0
- data/watir/exceptions.rb +18 -36
- data/watir/ie-process.rb +40 -0
- data/watir/irb-history.rb +31 -0
- data/watir/process.rb +20 -0
- data/watir/testUnitAddons.rb +3 -42
- data/watir/testcase.rb +58 -0
- data/watir/utils.rb +20 -0
- data/watir/waiter.rb +88 -0
- data/watir/watir_simple.rb +4 -4
- data/watir/win32ole.rb +8 -0
- data/watir/win32ole/win32ole.so +0 -0
- data/watir/winClicker.rb +374 -400
- metadata +209 -128
- data/unittests/WindowLogonExample.rb +0 -30
- data/unittests/attachToExistingWindow_test.rb +0 -40
- data/unittests/js_events_test.rb +0 -77
- data/unittests/jscriptExtraAlert.rb +0 -6
- data/unittests/jscriptExtraConfirmCancel.rb +0 -7
- data/unittests/jscriptExtraConfirmOk.rb +0 -7
- data/unittests/jscript_test.rb +0 -57
- data/unittests/send_keys_test.rb +0 -29
- data/unittests/textAreafields_test.rb +0 -81
|
Binary file
|
data/watir/WindowHelper.rb
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
require 'win32ole'
|
|
1
|
+
require 'watir/win32ole'
|
|
2
|
+
require 'watir' # for Watir.autoit
|
|
2
3
|
|
|
3
4
|
class WindowHelper
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
@@ie_window_name = "Windows Internet Explorer"
|
|
6
|
+
def initialize()
|
|
7
|
+
@autoit = Watir.autoit
|
|
6
8
|
end
|
|
7
9
|
|
|
8
|
-
def push_alert_button
|
|
9
|
-
@autoit.WinWait
|
|
10
|
+
def push_alert_button
|
|
11
|
+
@autoit.WinWait @@ie_window_name, ""
|
|
10
12
|
@autoit.Send "{ENTER}"
|
|
11
13
|
end
|
|
12
14
|
|
|
13
|
-
def push_confirm_button_ok
|
|
14
|
-
@autoit.WinWait
|
|
15
|
+
def push_confirm_button_ok
|
|
16
|
+
@autoit.WinWait @@ie_window_name, ""
|
|
15
17
|
@autoit.Send "{ENTER}"
|
|
16
18
|
end
|
|
17
19
|
|
|
18
|
-
def push_confirm_button_cancel
|
|
19
|
-
@autoit.WinWait
|
|
20
|
+
def push_confirm_button_cancel
|
|
21
|
+
@autoit.WinWait @@ie_window_name, ""
|
|
20
22
|
@autoit.Send "{ESCAPE}"
|
|
21
23
|
end
|
|
22
24
|
|
|
23
|
-
def push_security_alert_yes
|
|
25
|
+
def push_security_alert_yes
|
|
24
26
|
@autoit.WinWait "Security Alert", ""
|
|
25
27
|
@autoit.Send "{TAB}"
|
|
26
28
|
@autoit.Send "{TAB}"
|
|
@@ -37,7 +39,7 @@ class WindowHelper
|
|
|
37
39
|
|
|
38
40
|
def WindowHelper.check_autoit_installed
|
|
39
41
|
begin
|
|
40
|
-
|
|
42
|
+
Watir.autoit
|
|
41
43
|
rescue
|
|
42
44
|
raise Watir::Exception::WatirException, "The AutoIt dll must be correctly registered for this feature to work properly"
|
|
43
45
|
end
|
data/watir/assertions.rb
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'test/unit/assertions'
|
|
2
|
+
|
|
3
|
+
module Watir
|
|
4
|
+
# Verification methods
|
|
5
|
+
module Assertions
|
|
6
|
+
include Test::Unit::Assertions
|
|
7
|
+
|
|
8
|
+
# Log a failure if the boolean is true. The message is the failure
|
|
9
|
+
# message logged.
|
|
10
|
+
# Whether true or false, the assertion count is incremented.
|
|
11
|
+
def verify boolean, message = 'verify failed.'
|
|
12
|
+
add_assertion
|
|
13
|
+
add_failure message, caller unless boolean
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def verify_equal expected, actual, message=nil
|
|
17
|
+
full_message = build_message(message, <<EOT, expected, actual)
|
|
18
|
+
<?> expected but was
|
|
19
|
+
<?>.
|
|
20
|
+
EOT
|
|
21
|
+
verify(expected == actual, full_message)
|
|
22
|
+
end
|
|
23
|
+
def verify_match pattern, string, message=nil
|
|
24
|
+
pattern = case(pattern)
|
|
25
|
+
when String
|
|
26
|
+
Regexp.new(Regexp.escape(pattern))
|
|
27
|
+
else
|
|
28
|
+
pattern
|
|
29
|
+
end
|
|
30
|
+
full_message = build_message(message, "<?> expected to be =~\n<?>.", string, pattern)
|
|
31
|
+
verify(string =~ pattern, full_message)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
data/watir/camel_case.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# These are provided for backwards compatability with Watir 1.1
|
|
2
2
|
|
|
3
3
|
module Watir
|
|
4
|
-
module
|
|
4
|
+
module Container
|
|
5
5
|
alias waitForIE wait
|
|
6
6
|
alias fileField file_field
|
|
7
7
|
alias textField text_field
|
|
@@ -21,7 +21,16 @@ module Watir
|
|
|
21
21
|
alias showLinks show_links
|
|
22
22
|
alias showActive show_active
|
|
23
23
|
alias showAllObjects show_all_objects
|
|
24
|
+
def getIE; @ie; end
|
|
25
|
+
|
|
24
26
|
end
|
|
27
|
+
class Element
|
|
28
|
+
alias getOLEObject ole_object
|
|
29
|
+
alias fireEvent fire_event
|
|
30
|
+
alias innerText text
|
|
31
|
+
alias afterText after_text
|
|
32
|
+
alias beforeText before_text
|
|
33
|
+
end
|
|
25
34
|
class Frame
|
|
26
35
|
alias getDocument document
|
|
27
36
|
alias waitForIE wait
|
|
@@ -29,9 +38,9 @@ module Watir
|
|
|
29
38
|
class Form
|
|
30
39
|
alias waitForIE wait
|
|
31
40
|
end
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
alias
|
|
41
|
+
class TextField
|
|
42
|
+
alias readOnly? :readonly?
|
|
43
|
+
alias getContents value
|
|
44
|
+
alias maxLength maxlength
|
|
35
45
|
end
|
|
36
|
-
|
|
37
46
|
end
|
data/watir/close_all.rb
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'watir'
|
|
2
|
+
|
|
3
|
+
module Watir
|
|
4
|
+
class IE
|
|
5
|
+
# close all ie browser windows
|
|
6
|
+
def self.close_all
|
|
7
|
+
close_all_but nil
|
|
8
|
+
end
|
|
9
|
+
# find other ie browser windows and close them
|
|
10
|
+
def close_others
|
|
11
|
+
IE.close_all_but self
|
|
12
|
+
end
|
|
13
|
+
private
|
|
14
|
+
def self.close_all_but(except=nil)
|
|
15
|
+
Watir::IE.each do |ie|
|
|
16
|
+
ie.close_modal
|
|
17
|
+
ie.close unless except and except.hwnd == window.hwnd
|
|
18
|
+
end
|
|
19
|
+
sleep 1.0 # replace with polling for window count to be zero?
|
|
20
|
+
end
|
|
21
|
+
public
|
|
22
|
+
# close modal dialog. unlike IE#modal_dialog.close, does not wait for dialog
|
|
23
|
+
# to appear and does not raise exception if no window is found.
|
|
24
|
+
# returns true if modal was found and close, otherwise false
|
|
25
|
+
def close_modal
|
|
26
|
+
begin
|
|
27
|
+
original_attach_timeout = IE.attach_timeout
|
|
28
|
+
IE.attach_timeout = 0
|
|
29
|
+
self.modal_dialog.close
|
|
30
|
+
true
|
|
31
|
+
rescue NoMatchingWindowFoundException, TimeOutException
|
|
32
|
+
false
|
|
33
|
+
ensure
|
|
34
|
+
IE.attach_timeout = original_attach_timeout
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# http://www.vbcity.com/forums/topic.asp?tid=108859
|
|
2
|
+
|
|
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
|
+
end
|
|
@@ -0,0 +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
|
|
@@ -0,0 +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
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# visible.rb
|
|
2
|
+
# Original Author: David Schmidt
|
|
3
|
+
|
|
4
|
+
# See http://wiki.openqa.org/pages/viewpage.action?pageId=1119
|
|
5
|
+
# for description and sample code.
|
|
6
|
+
|
|
7
|
+
# Here is an example of adding a new #visible? method to the Watir::Element
|
|
8
|
+
# class which returns true or false to indicate whether the cell is visible.
|
|
9
|
+
# The question of visibility isn't as easy as it seems, because there are
|
|
10
|
+
# multiple styles to indicate visibility ("display: none" or
|
|
11
|
+
# "visibility: hidden"). In addition, an element is hidden if any PARENT
|
|
12
|
+
# element is hidden, even if that element would otherwise be visible.
|
|
13
|
+
|
|
14
|
+
# This method first checks the current element and then each parent element
|
|
15
|
+
# for visibility until it reaches the top of the DOM element tree. Note that
|
|
16
|
+
# this method is quite slow compared to other methods because it must recurse
|
|
17
|
+
# all the way to the top of the DOM to guarantee that an element is truly
|
|
18
|
+
# visible.
|
|
19
|
+
|
|
20
|
+
class Watir::Element
|
|
21
|
+
|
|
22
|
+
# If any parent element isn't visible then we cannot write to the
|
|
23
|
+
# element. The only realiable way to determine this is to iterate
|
|
24
|
+
# up the DOM element tree checking every element to make sure it's
|
|
25
|
+
# visible.
|
|
26
|
+
def visible?
|
|
27
|
+
# Now iterate up the DOM element tree and return false if any
|
|
28
|
+
# parent element isn't visible or is disabled.
|
|
29
|
+
object = document
|
|
30
|
+
while object
|
|
31
|
+
begin
|
|
32
|
+
if object.style.invoke('visibility') =~ /^hidden$/i
|
|
33
|
+
return false
|
|
34
|
+
end
|
|
35
|
+
if object.style.invoke('display') =~ /^none$/i
|
|
36
|
+
return false
|
|
37
|
+
end
|
|
38
|
+
if object.invoke('isDisabled')
|
|
39
|
+
return false
|
|
40
|
+
end
|
|
41
|
+
rescue WIN32OLERuntimeError
|
|
42
|
+
end
|
|
43
|
+
object = object.parentElement
|
|
44
|
+
end
|
|
45
|
+
true
|
|
46
|
+
end
|
|
47
|
+
end
|
data/watir/cookiemanager.rb
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
require 'find'
|
|
2
|
+
module Watir
|
|
3
|
+
module CookieManager
|
|
1
4
|
|
|
2
5
|
class Dir
|
|
3
6
|
def Dir.visit(dir = '.', files_first = false, &block)
|
|
@@ -27,9 +30,6 @@
|
|
|
27
30
|
end
|
|
28
31
|
end
|
|
29
32
|
|
|
30
|
-
module Watir
|
|
31
|
-
module CookieManager
|
|
32
|
-
|
|
33
33
|
class WatirHelper
|
|
34
34
|
#taken from shlObj.h used in win32 SHGetSpecialFolderLocation
|
|
35
35
|
#define CSIDL_INTERNET_CACHE 0x0020
|
|
@@ -39,7 +39,7 @@ module Watir
|
|
|
39
39
|
INTERNET_CACHE = 0x0020
|
|
40
40
|
|
|
41
41
|
def WatirHelper.getSpecialFolderLocation(specFolderName)
|
|
42
|
-
shell = WIN32OLE.new(
|
|
42
|
+
shell = WIN32OLE.new('Shell.Application')
|
|
43
43
|
folder = shell.Namespace(specFolderName)
|
|
44
44
|
folderItem = folder.Self
|
|
45
45
|
folderPath = folderItem.Path
|
|
@@ -0,0 +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
|
data/watir/dialog.rb
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'watir'
|
|
2
|
+
# TODO: move this file to watir/contrib
|
|
3
|
+
|
|
4
|
+
module Watir
|
|
5
|
+
|
|
6
|
+
class Dialog
|
|
7
|
+
WindowName = 'Windows Internet Explorer'
|
|
8
|
+
def button(name)
|
|
9
|
+
DialogButton.new(name)
|
|
10
|
+
end
|
|
11
|
+
def close
|
|
12
|
+
# TODO: register autoit before use
|
|
13
|
+
autoit = WIN32OLE.new('AutoItX3.Control')
|
|
14
|
+
autoit.WinClose WindowName, ""
|
|
15
|
+
end
|
|
16
|
+
def exists?
|
|
17
|
+
# TODO: register autoit before use
|
|
18
|
+
autoit = WIN32OLE.new('AutoItX3.Control')
|
|
19
|
+
found = autoit.WinWait(WindowName, "", 1)
|
|
20
|
+
return found == 1
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def dialog
|
|
25
|
+
Dialog.new
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class DialogButton
|
|
29
|
+
def initialize(name)
|
|
30
|
+
@name = name
|
|
31
|
+
end
|
|
32
|
+
def click
|
|
33
|
+
# TODO: register autoit before use
|
|
34
|
+
autoit = WIN32OLE.new('AutoItX3.Control')
|
|
35
|
+
autoit.WinWait Dialog::WindowName, "", 1
|
|
36
|
+
name_pattern = Regexp.new "^#{@name}$"
|
|
37
|
+
unless name_pattern =~ autoit.WinGetText(Dialog::WindowName, "")
|
|
38
|
+
raise Watir::Exception::UnknownObjectException
|
|
39
|
+
end
|
|
40
|
+
autoit.Send "{ENTER}"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
|