watir-classic 3.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/.gitmodules +3 -0
- data/.rspec +1 -0
- data/.yardopts +5 -0
- data/CHANGES +20 -10
- data/CONTRIBUTORS.txt +55 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +78 -0
- data/README.rdoc +8 -14
- data/Rakefile +32 -0
- data/VERSION +1 -1
- data/lib/watir-classic.rb +0 -1
- data/lib/watir-classic/IEDialog/IEDialog.cpp +225 -0
- data/lib/watir-classic/IEDialog/IEDialog.h +15 -0
- data/lib/watir-classic/IEDialog/IEDialog.vcproj +159 -0
- data/lib/watir-classic/IEDialog/ReadMe.txt +40 -0
- data/lib/watir-classic/IEDialog/stdafx.cpp +8 -0
- data/lib/watir-classic/IEDialog/stdafx.h +21 -0
- data/lib/watir-classic/browser.rb +1 -1
- data/lib/watir-classic/container.rb +4 -33
- data/lib/watir-classic/core.rb +1 -3
- data/lib/watir-classic/dialogs/alert.rb +46 -0
- data/lib/watir-classic/dialogs/file_field.rb +1 -0
- data/lib/watir-classic/drag_and_drop_helper.rb +18 -6
- data/lib/watir-classic/element.rb +0 -2
- data/lib/watir-classic/ext/json2.js +487 -0
- data/lib/watir-classic/ie-class.rb +10 -164
- data/lib/watir-classic/ie.rb +2 -0
- data/lib/watir-classic/input_elements.rb +1 -1
- data/lib/watir-classic/modal_dialog.rb +1 -7
- data/lib/watir-classic/module.rb +1 -10
- data/lib/watir-classic/non_control_elements.rb +11 -0
- data/lib/watir-classic/page-container.rb +22 -24
- data/lib/watir-classic/screenshot.rb +33 -0
- data/lib/watir-classic/win32ole/1.8.7/win32ole.patch +56 -0
- data/lib/watir-classic/win32ole/1.9.3/win32ole.patch +63 -0
- data/lib/watir-classic/win32ole/build_notes.txt +18 -0
- data/lib/watir-classic/win32ole/history.txt +88 -0
- data/spec/browser_spec.rb +34 -0
- data/spec/implementation.rb +18 -0
- data/watir-classic.gemspec +40 -0
- data/watir.gif +0 -0
- metadata +159 -192
- data/bin/watir-console +0 -5
- data/lib/watir-classic/assertions.rb +0 -44
- data/lib/watir-classic/dialogs/javascript.rb +0 -43
- data/lib/watir-classic/irb-history.rb +0 -31
- data/lib/watir-classic/logger.rb +0 -19
- data/lib/watir-classic/screen_capture.rb +0 -115
- data/lib/watir-classic/testcase.rb +0 -97
- data/lib/watir-classic/waiter.rb +0 -98
- data/rakefile.rb +0 -54
- data/unittests/all_tests.rb +0 -10
- data/unittests/buttons_xpath_test.rb +0 -68
- data/unittests/checkbox_test.rb +0 -163
- data/unittests/checkbox_xpath_test.rb +0 -106
- data/unittests/click_no_wait_test.rb +0 -23
- data/unittests/close_all_test.rb +0 -17
- data/unittests/core_tests.rb +0 -17
- data/unittests/css_selector_test.rb +0 -44
- data/unittests/css_test.rb +0 -38
- data/unittests/dialog_test.rb +0 -64
- data/unittests/div2_xpath_test.rb +0 -21
- data/unittests/div_test.rb +0 -170
- data/unittests/div_xpath_test.rb +0 -95
- data/unittests/document_standards.rb +0 -63
- data/unittests/element_collection_indexes_test.rb +0 -57
- data/unittests/element_collections_test.rb +0 -100
- data/unittests/element_test.rb +0 -47
- data/unittests/errorchecker_test.rb +0 -31
- data/unittests/filefield_test.rb +0 -43
- data/unittests/filefield_xpath_test.rb +0 -35
- data/unittests/form_test.rb +0 -282
- data/unittests/form_xpath_test.rb +0 -254
- data/unittests/frame_test.rb +0 -165
- data/unittests/google_form_test.rb +0 -15
- data/unittests/html/JavascriptClick.html +0 -39
- data/unittests/html/blankpage.html +0 -11
- data/unittests/html/buttons1.html +0 -40
- data/unittests/html/checkboxes1.html +0 -89
- data/unittests/html/click_no_wait.html +0 -14
- data/unittests/html/complex_table.html +0 -35
- data/unittests/html/cssTest.html +0 -42
- data/unittests/html/depot_store.html +0 -59
- data/unittests/html/div.html +0 -92
- data/unittests/html/div_xml.html +0 -21
- data/unittests/html/fileupload.html +0 -44
- data/unittests/html/formTest1.html +0 -38
- data/unittests/html/forms2.html +0 -44
- data/unittests/html/forms3.html +0 -131
- data/unittests/html/forms4.html +0 -26
- data/unittests/html/frame_buttons.html +0 -4
- data/unittests/html/frame_links.html +0 -4
- data/unittests/html/frame_multi.html +0 -5
- data/unittests/html/google_india.html +0 -119
- data/unittests/html/ie7_document_standards.html +0 -9
- data/unittests/html/ie8_document_standards.html +0 -9
- data/unittests/html/ie9_document_standards.html +0 -9
- data/unittests/html/iframe.html +0 -3
- data/unittests/html/iframeTest.html +0 -17
- data/unittests/html/iframeTest1.html +0 -7
- data/unittests/html/iframeTest2.html +0 -5
- 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 +0 -65
- data/unittests/html/javascriptevents.html +0 -33
- data/unittests/html/link_pass.html +0 -11
- data/unittests/html/links1.html +0 -37
- data/unittests/html/links2.html +0 -11
- data/unittests/html/links_multi.html +0 -12
- data/unittests/html/list_matters.html +0 -720
- data/unittests/html/lists.html +0 -18
- data/unittests/html/map_test.html +0 -30
- data/unittests/html/modal_dialog.html +0 -10
- data/unittests/html/modal_dialog_launcher.html +0 -12
- data/unittests/html/multiple_specifiers.html +0 -64
- data/unittests/html/nestedFrames.html +0 -6
- data/unittests/html/new_browser.html +0 -17
- data/unittests/html/pass.html +0 -13
- data/unittests/html/popups1.html +0 -59
- data/unittests/html/pre.html +0 -29
- data/unittests/html/quirks_document_standards.html +0 -8
- data/unittests/html/radioButtons1.html +0 -71
- data/unittests/html/select_tealeaf.html +0 -54
- data/unittests/html/selectboxes1.html +0 -52
- data/unittests/html/simple_table.html +0 -25
- data/unittests/html/simple_table_buttons.html +0 -104
- data/unittests/html/simple_table_columns.html +0 -75
- data/unittests/html/table1.html +0 -179
- data/unittests/html/tableCell_using_xpath.html +0 -19
- data/unittests/html/table_and_tablerow_to_a.html +0 -174
- data/unittests/html/textarea.html +0 -30
- data/unittests/html/textfields1.html +0 -100
- data/unittests/html/textsearch.html +0 -44
- data/unittests/html/wallofcheckboxes.html +0 -1003
- data/unittests/html/xpath_nbsp.html +0 -11
- data/unittests/html/zeroindex.html +0 -11
- data/unittests/ie_exists_test.rb +0 -16
- data/unittests/ie_mock.rb +0 -94
- data/unittests/ie_test.rb +0 -54
- data/unittests/images_test.rb +0 -156
- data/unittests/images_xpath_test.rb +0 -90
- data/unittests/index_specifier_test.rb +0 -31
- data/unittests/js_events_test.rb +0 -31
- data/unittests/links_multi_test.rb +0 -34
- data/unittests/links_test.rb +0 -131
- data/unittests/links_xpath_test.rb +0 -38
- data/unittests/lists_test.rb +0 -23
- data/unittests/map_test.rb +0 -98
- data/unittests/minmax_test.rb +0 -37
- data/unittests/navigate_test.rb +0 -38
- data/unittests/nbsp_xpath_test.rb +0 -16
- data/unittests/no_wait_test.rb +0 -28
- data/unittests/non_core_tests.rb +0 -12
- data/unittests/other/all_tests_concurrent.rb +0 -57
- data/unittests/other/navigate_exception_test.rb +0 -24
- data/unittests/other/rexml_unit_test.rb +0 -27
- data/unittests/other/screen_capture_test.rb +0 -53
- data/unittests/other/testcase_method_order_test.rb +0 -36
- data/unittests/other/testcase_verify_test.rb +0 -25
- data/unittests/other/wait_until_test.rb +0 -102
- data/unittests/pagecontainstext_test.rb +0 -69
- data/unittests/parent_child_test.rb +0 -27
- data/unittests/perf_test.rb +0 -20
- data/unittests/pre_test.rb +0 -49
- data/unittests/radios_test.rb +0 -181
- data/unittests/radios_xpath_test.rb +0 -100
- data/unittests/security_setting_test.rb +0 -24
- data/unittests/selectbox_test.rb +0 -144
- data/unittests/selectbox_xpath_test.rb +0 -102
- data/unittests/setup.rb +0 -69
- data/unittests/speed_settings_test.rb +0 -67
- data/unittests/table_cell_using_xpath_test.rb +0 -34
- data/unittests/table_test.rb +0 -296
- data/unittests/table_xpath_test.rb +0 -109
- data/unittests/test_tests.rb +0 -9
- data/unittests/textarea_test.rb +0 -92
- data/unittests/textarea_xpath_test.rb +0 -77
- data/unittests/textfield_for_ch_char_test.rb +0 -32
- data/unittests/textfields_test.rb +0 -184
- data/unittests/textfields_xpath_test.rb +0 -110
- data/unittests/version_test.rb +0 -15
- data/unittests/win32ole_so_test.rb +0 -35
- data/unittests/window_tests.rb +0 -10
- data/unittests/windows/attach_to_existing_window_test.rb +0 -52
- data/unittests/windows/attach_to_new_window_test.rb +0 -74
- data/unittests/windows/close_window_test.rb +0 -20
- data/unittests/windows/frame_links_test.rb +0 -23
- data/unittests/windows/ie-each_test.rb +0 -46
- data/unittests/windows/modal_dialog_test.rb +0 -95
- data/unittests/windows/new_process_test.rb +0 -24
- data/unittests/windows/new_test.rb +0 -58
- data/unittests/windows/open_close_test.rb +0 -19
- data/unittests/windows/send_keys_test.rb +0 -26
- data/unittests/xpath_tests.rb +0 -11
- data/watir-rdoc.rb +0 -7
@@ -74,8 +74,6 @@ module Watir
|
|
74
74
|
|
75
75
|
# the OLE Internet Explorer object
|
76
76
|
attr_accessor :ie
|
77
|
-
# access to the logger object
|
78
|
-
attr_accessor :logger
|
79
77
|
|
80
78
|
# this contains the list of unique urls that have been visited
|
81
79
|
attr_reader :url_list
|
@@ -176,9 +174,6 @@ module Watir
|
|
176
174
|
@page_container = self
|
177
175
|
@error_checkers = []
|
178
176
|
@activeObjectHighLightColor = HIGHLIGHT_COLOR
|
179
|
-
|
180
|
-
|
181
|
-
@logger = DefaultLogger.new
|
182
177
|
@url_list = []
|
183
178
|
end
|
184
179
|
|
@@ -328,6 +323,10 @@ module Watir
|
|
328
323
|
end
|
329
324
|
attr_writer :hwnd
|
330
325
|
|
326
|
+
def name
|
327
|
+
:ie
|
328
|
+
end
|
329
|
+
|
331
330
|
# Are we attached to an open browser?
|
332
331
|
def exists?
|
333
332
|
begin
|
@@ -338,15 +337,6 @@ module Watir
|
|
338
337
|
end
|
339
338
|
alias :exist? :exists?
|
340
339
|
|
341
|
-
# deprecated: use logger= instead
|
342
|
-
def set_logger(logger)
|
343
|
-
@logger = logger
|
344
|
-
end
|
345
|
-
|
346
|
-
def log(what)
|
347
|
-
@logger.debug(what) if @logger
|
348
|
-
end
|
349
|
-
|
350
340
|
#
|
351
341
|
# Accessing data outside the document
|
352
342
|
#
|
@@ -493,6 +483,10 @@ module Watir
|
|
493
483
|
return @ie.LocationURL
|
494
484
|
end
|
495
485
|
|
486
|
+
def screenshot
|
487
|
+
Screenshot.new(hwnd)
|
488
|
+
end
|
489
|
+
|
496
490
|
def window(specifiers={}, &blk)
|
497
491
|
win = Window.new(self, specifiers, &blk)
|
498
492
|
win.use &blk if blk
|
@@ -585,153 +579,6 @@ module Watir
|
|
585
579
|
@error_checkers.delete(checker)
|
586
580
|
end
|
587
581
|
|
588
|
-
#
|
589
|
-
# Show me state
|
590
|
-
#
|
591
|
-
|
592
|
-
# Show all forms displays all the forms that are on a web page.
|
593
|
-
def show_forms
|
594
|
-
if all_forms = self.forms
|
595
|
-
count = all_forms.length
|
596
|
-
puts "There are #{count} forms"
|
597
|
-
all_forms.each do |form|
|
598
|
-
puts "Form name: #{form.name}"
|
599
|
-
puts " id: #{form.id}"
|
600
|
-
puts " method: #{form.method}"
|
601
|
-
puts " action: #{form.action}"
|
602
|
-
end
|
603
|
-
else
|
604
|
-
puts "No forms"
|
605
|
-
end
|
606
|
-
end
|
607
|
-
|
608
|
-
# this method shows all the images availble in the document
|
609
|
-
def show_images
|
610
|
-
doc = document
|
611
|
-
index = 1
|
612
|
-
doc.images.each do |l|
|
613
|
-
puts "image: name: #{l.name}"
|
614
|
-
puts " id: #{l.invoke("id")}"
|
615
|
-
puts " src: #{l.src}"
|
616
|
-
puts " index: #{index}"
|
617
|
-
index += 1
|
618
|
-
end
|
619
|
-
end
|
620
|
-
|
621
|
-
# this method shows all the links availble in the document
|
622
|
-
def show_links
|
623
|
-
props = ["name", "id", "href"]
|
624
|
-
print_sizes = [12, 12, 60]
|
625
|
-
doc = document
|
626
|
-
index = 0
|
627
|
-
text_size = 60
|
628
|
-
# draw the table header
|
629
|
-
s = "index".ljust(6)
|
630
|
-
props.each_with_index do |p, i|
|
631
|
-
s += p.ljust(print_sizes[i])
|
632
|
-
end
|
633
|
-
s += "text/src".ljust(text_size)
|
634
|
-
s += "\n"
|
635
|
-
|
636
|
-
# now get the details of the links
|
637
|
-
doc.links.each do |n|
|
638
|
-
index += 1
|
639
|
-
s = s + index.to_s.ljust(6)
|
640
|
-
props.each_with_index do |prop, i|
|
641
|
-
printsize = print_sizes[i]
|
642
|
-
begin
|
643
|
-
p = n.invoke(prop)
|
644
|
-
temp_var = "#{p}".to_s.ljust(printsize)
|
645
|
-
rescue
|
646
|
-
# this object probably doesnt have this property
|
647
|
-
temp_var = "".to_s.ljust(printsize)
|
648
|
-
end
|
649
|
-
s += temp_var
|
650
|
-
end
|
651
|
-
s += n.innerText
|
652
|
-
if n.getElementsByTagName("IMG").length > 0
|
653
|
-
s += " / " + n.getElementsByTagName("IMG").item(0).src
|
654
|
-
end
|
655
|
-
s += "\n"
|
656
|
-
end
|
657
|
-
puts s
|
658
|
-
end
|
659
|
-
|
660
|
-
# this method shows the name, id etc of the object that is currently active - ie the element that has focus
|
661
|
-
# its mostly used in irb when creating a script
|
662
|
-
def show_active
|
663
|
-
s = ""
|
664
|
-
|
665
|
-
current = document.activeElement
|
666
|
-
begin
|
667
|
-
s += current.invoke("type").to_s.ljust(16)
|
668
|
-
rescue
|
669
|
-
end
|
670
|
-
props = ["name", "id", "value", "alt", "src", "innerText", "href"]
|
671
|
-
props.each do |prop|
|
672
|
-
begin
|
673
|
-
p = current.invoke(prop)
|
674
|
-
s += " " + "#{prop}=#{p}".to_s.ljust(18)
|
675
|
-
rescue
|
676
|
-
#this object probably doesnt have this property
|
677
|
-
end
|
678
|
-
end
|
679
|
-
s += "\n"
|
680
|
-
end
|
681
|
-
|
682
|
-
# this method shows all the divs availble in the document
|
683
|
-
def show_divs
|
684
|
-
divs = document.getElementsByTagName("DIV")
|
685
|
-
puts "Found #{divs.length} div tags"
|
686
|
-
index = 1
|
687
|
-
divs.each do |d|
|
688
|
-
puts "#{index} id=#{d.invoke('id')} class=#{d.invoke("className")}"
|
689
|
-
index += 1
|
690
|
-
end
|
691
|
-
end
|
692
|
-
|
693
|
-
# this method is used to show all the tables that are available
|
694
|
-
def show_tables
|
695
|
-
tables = document.getElementsByTagName("TABLE")
|
696
|
-
puts "Found #{tables.length} tables"
|
697
|
-
index = 1
|
698
|
-
tables.each do |d|
|
699
|
-
puts "#{index} id=#{d.invoke('id')} rows=#{d.rows.length} columns=#{begin d.rows["0"].cells.length; rescue; end}"
|
700
|
-
index += 1
|
701
|
-
end
|
702
|
-
end
|
703
|
-
|
704
|
-
def show_pres
|
705
|
-
pres = document.getElementsByTagName("PRE")
|
706
|
-
puts "Found #{ pres.length } pre tags"
|
707
|
-
index = 1
|
708
|
-
pres.each do |d|
|
709
|
-
puts "#{index} id=#{d.invoke('id')} class=#{d.invoke("className")}"
|
710
|
-
index+=1
|
711
|
-
end
|
712
|
-
end
|
713
|
-
|
714
|
-
# this method shows all the spans availble in the document
|
715
|
-
def show_spans
|
716
|
-
spans = document.getElementsByTagName("SPAN")
|
717
|
-
puts "Found #{spans.length} span tags"
|
718
|
-
index = 1
|
719
|
-
spans.each do |d|
|
720
|
-
puts "#{index} id=#{d.invoke('id')} class=#{d.invoke("className")}"
|
721
|
-
index += 1
|
722
|
-
end
|
723
|
-
end
|
724
|
-
|
725
|
-
def show_labels
|
726
|
-
labels = document.getElementsByTagName("LABEL")
|
727
|
-
puts "Found #{labels.length} label tags"
|
728
|
-
index = 1
|
729
|
-
labels.each do |d|
|
730
|
-
puts "#{index} text=#{d.invoke('innerText')} class=#{d.invoke("className")} for=#{d.invoke("htmlFor")}"
|
731
|
-
index += 1
|
732
|
-
end
|
733
|
-
end
|
734
|
-
|
735
582
|
# Gives focus to the frame
|
736
583
|
def focus
|
737
584
|
active_element = document.activeElement
|
@@ -750,13 +597,12 @@ module Watir
|
|
750
597
|
end
|
751
598
|
|
752
599
|
def attach_browser_window how, what
|
753
|
-
log "Seeking Window with #{how}: #{what}"
|
754
600
|
ieTemp = nil
|
755
601
|
begin
|
756
|
-
|
602
|
+
Wait.until(IE.attach_timeout) do
|
757
603
|
ieTemp = IE._find how, what
|
758
604
|
end
|
759
|
-
rescue
|
605
|
+
rescue Wait::TimeoutError
|
760
606
|
raise NoMatchingWindowFoundException,
|
761
607
|
"Unable to locate a window with #{how} of #{what}"
|
762
608
|
end
|
data/lib/watir-classic/ie.rb
CHANGED
@@ -2,6 +2,8 @@ require 'watir-classic'
|
|
2
2
|
require 'watir-classic/core'
|
3
3
|
require 'watir-classic/close_all'
|
4
4
|
require 'watir-classic/ie-process'
|
5
|
+
require 'watir-classic/screenshot'
|
6
|
+
require 'yajl'
|
5
7
|
|
6
8
|
# these switches need to be deleted from ARGV to enable the Test::Unit
|
7
9
|
# functionality that grabs
|
@@ -232,6 +232,7 @@ module Watir
|
|
232
232
|
dispatch_event("onSelect")
|
233
233
|
dispatch_event("ondragstart")
|
234
234
|
dispatch_event("ondrag")
|
235
|
+
destination.assert_exists
|
235
236
|
destination.dispatch_event("onDragEnter")
|
236
237
|
destination.dispatch_event("onDragOver")
|
237
238
|
destination.dispatch_event("ondrop")
|
@@ -362,7 +363,6 @@ module Watir
|
|
362
363
|
return value if @o.invoke('type') =~ /textarea/i # text areas don't have maxlength
|
363
364
|
if value.length > maxlength
|
364
365
|
value = value[0 .. maxlength - 1]
|
365
|
-
@container.log " Supplied string is #{value.length} chars, which exceeds the max length (#{maxlength}) of the field. Using value: #{value}"
|
366
366
|
end
|
367
367
|
value
|
368
368
|
end
|
@@ -1,9 +1,3 @@
|
|
1
|
-
class WinClicker
|
2
|
-
def initialize
|
3
|
-
raise NotImplementedError, 'Watir no longer supports WinClicker. Please use click_no_wait and the javascript_dialog method.'
|
4
|
-
end
|
5
|
-
end
|
6
|
-
|
7
1
|
module Watir
|
8
2
|
class ModalDialog
|
9
3
|
include Container
|
@@ -19,7 +13,7 @@ module Watir
|
|
19
13
|
@modal.wait_until_present rescue raise NoMatchingWindowFoundException
|
20
14
|
|
21
15
|
intUnknown = 0
|
22
|
-
|
16
|
+
Wait.until do
|
23
17
|
intPointer = " " * 4 # will contain the int value of the IUnknown*
|
24
18
|
GetUnknown.call(hwnd, intPointer)
|
25
19
|
intArray = intPointer.unpack('L')
|
data/lib/watir-classic/module.rb
CHANGED
@@ -1,12 +1,3 @@
|
|
1
1
|
module Watir
|
2
2
|
include Watir::Exception
|
3
|
-
|
4
|
-
# Directory containing the watir.rb file
|
5
|
-
@@dir = File.expand_path(File.dirname(__FILE__))
|
6
|
-
|
7
|
-
# Like regular Ruby "until", except that a Wait::TimeoutError is raised
|
8
|
-
# if the timeout is exceeded. Timeout is IE.attach_timeout.
|
9
|
-
def self.until_with_timeout # block
|
10
|
-
Wait.until(IE.attach_timeout) { yield }
|
11
|
-
end
|
12
|
-
end
|
3
|
+
end
|
@@ -22,6 +22,17 @@ module Watir
|
|
22
22
|
attr_ole :value
|
23
23
|
end
|
24
24
|
|
25
|
+
class Dl < Element
|
26
|
+
def to_hash
|
27
|
+
dts.each_with_index.reduce({}) do |memo, item|
|
28
|
+
dt, i = *item
|
29
|
+
dd = dds[i]
|
30
|
+
memo[dt.text] = dd.present? ? dd.text : nil
|
31
|
+
memo
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
25
36
|
class Embed < Element
|
26
37
|
attr_ole :src
|
27
38
|
attr_ole :type
|
@@ -37,17 +37,17 @@ module Watir
|
|
37
37
|
def execute_script(source)
|
38
38
|
result = nil
|
39
39
|
begin
|
40
|
-
source =
|
40
|
+
source = with_json2_if_needed source
|
41
41
|
result = document.parentWindow.eval(source)
|
42
42
|
rescue WIN32OLERuntimeError, NoMethodError #if eval fails we need to use execScript(source.to_s) which does not return a value, hence the workaround
|
43
|
-
escaped_src = source.gsub(
|
43
|
+
escaped_src = source.gsub(/\r?\n/, "\\n").gsub("'", "\\\\'")
|
44
44
|
wrapper = "_watir_helper_div_#{::Time.now.to_i + ::Time.now.usec}"
|
45
45
|
cmd = "var e = document.createElement('DIV'); e.style.display='none'; e.id='#{wrapper}'; e.innerHTML = eval('#{escaped_src}'); document.body.appendChild(e);"
|
46
46
|
document.parentWindow.execScript(cmd)
|
47
47
|
result = document.getElementById(wrapper).innerHTML
|
48
48
|
end
|
49
49
|
|
50
|
-
result
|
50
|
+
Yajl::Parser.parse(result) rescue nil
|
51
51
|
end
|
52
52
|
|
53
53
|
# The HTML of the current page
|
@@ -70,27 +70,6 @@ module Watir
|
|
70
70
|
@page_container = self
|
71
71
|
end
|
72
72
|
|
73
|
-
# This method is used to display the available html frames that Internet Explorer currently has loaded.
|
74
|
-
# This method is usually only used for debugging test scripts.
|
75
|
-
def show_frames
|
76
|
-
if allFrames = document.frames
|
77
|
-
count = allFrames.length
|
78
|
-
puts "there are #{count} frames"
|
79
|
-
for i in 0..count-1 do
|
80
|
-
begin
|
81
|
-
fname = allFrames.item(i).name.to_s
|
82
|
-
puts "frame index: #{i + 1} name: #{fname}"
|
83
|
-
rescue => e
|
84
|
-
if e.to_s.match(/Access is denied/)
|
85
|
-
puts "frame index: #{i + 1} Access Denied, see http://wiki.openqa.org/display/WTR/FAQ#access-denied"
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
else
|
90
|
-
puts "no frames"
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
73
|
# Search the current page for specified text or regexp.
|
95
74
|
# Returns the index if the specified text was found.
|
96
75
|
# Returns matchdata object if the specified regexp was found.
|
@@ -110,5 +89,24 @@ module Watir
|
|
110
89
|
end
|
111
90
|
end
|
112
91
|
|
92
|
+
def with_json2_if_needed source
|
93
|
+
%Q[
|
94
|
+
(function() {
|
95
|
+
if (!window.JSON || !window.JSON.stringify) {
|
96
|
+
var json2=document.createElement('script');
|
97
|
+
json2.type='text/javascript';
|
98
|
+
json2.src='file:///#{File.expand_path(File.dirname(__FILE__) + "/ext/json2.js")}';
|
99
|
+
document.getElementsByTagName('head')[0].appendChild(json2)
|
100
|
+
}
|
101
|
+
|
102
|
+
return JSON.stringify((function() {#{source}})());
|
103
|
+
})()
|
104
|
+
]
|
105
|
+
end
|
106
|
+
|
107
|
+
private :with_json2_if_needed
|
108
|
+
|
113
109
|
end # module
|
114
110
|
end
|
111
|
+
|
112
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "tmpdir"
|
2
|
+
require "base64"
|
3
|
+
require "win32/screenshot"
|
4
|
+
|
5
|
+
module Watir
|
6
|
+
class Screenshot
|
7
|
+
def initialize(browser_hwnd)
|
8
|
+
@hwnd = browser_hwnd
|
9
|
+
end
|
10
|
+
|
11
|
+
def save(path)
|
12
|
+
screenshot.write(path)
|
13
|
+
end
|
14
|
+
|
15
|
+
def png
|
16
|
+
path = File.expand_path "temporary-image-#{Time.now.to_i}.png", Dir.tmpdir
|
17
|
+
save path
|
18
|
+
File.open(path, "rb") {|file| file.read}
|
19
|
+
ensure
|
20
|
+
File.delete path rescue nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def base64
|
24
|
+
Base64.encode64 png
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def screenshot
|
30
|
+
::Win32::Screenshot::Take.of(:window, :hwnd => @hwnd)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
Index: win32ole.c
|
2
|
+
===================================================================
|
3
|
+
--- win32ole.c (revision 29867)
|
4
|
+
+++ win32ole.c (revision )
|
5
|
+
@@ -6368,6 +6368,43 @@
|
6
|
+
}
|
7
|
+
|
8
|
+
|
9
|
+
+/*
|
10
|
+
+ * WIN32OLE.connect_unknown( pUnknown ) --> aWIN32OLE
|
11
|
+
+ * ----
|
12
|
+
+ * Returns running OLE Automation object or WIN32OLE object from a
|
13
|
+
+IUnknown pointer
|
14
|
+
+ * the IUnknown pointer is passed in as a FIXNUM
|
15
|
+
+ */
|
16
|
+
+static VALUE
|
17
|
+
+fole_s_connect_unknown(self, iUnknown)
|
18
|
+
+ VALUE self;
|
19
|
+
+ VALUE iUnknown;
|
20
|
+
+{
|
21
|
+
+ HRESULT hr;
|
22
|
+
+ IDispatch *pDispatch;
|
23
|
+
+ IUnknown *pUnknown;
|
24
|
+
+
|
25
|
+
+ /* initialize to use OLE */
|
26
|
+
+ ole_initialize();
|
27
|
+
+
|
28
|
+
+ //cast from int to IUnknown*
|
29
|
+
+ pUnknown = (IUnknown*)FIX2INT(iUnknown);
|
30
|
+
+
|
31
|
+
+ hr = pUnknown->lpVtbl->QueryInterface(pUnknown, &IID_IDispatch,
|
32
|
+
+ (void **)&pDispatch);
|
33
|
+
+ if(FAILED(hr)) {
|
34
|
+
+ OLE_RELEASE(pUnknown);
|
35
|
+
+ ole_raise(hr, eWIN32OLE_RUNTIME_ERROR,
|
36
|
+
+ "Failed to connect to WIN32OLE server `%d'",
|
37
|
+
+ FIX2INT(iUnknown));
|
38
|
+
+ }
|
39
|
+
+
|
40
|
+
+ OLE_RELEASE(pUnknown);
|
41
|
+
+
|
42
|
+
+ return create_win32ole_object(self, pDispatch, Qnil, Qnil);
|
43
|
+
+}
|
44
|
+
+
|
45
|
+
+
|
46
|
+
void
|
47
|
+
Init_win32ole()
|
48
|
+
{
|
49
|
+
@@ -6400,6 +6437,7 @@
|
50
|
+
rb_define_method(cWIN32OLE, "initialize", fole_initialize, -1);
|
51
|
+
|
52
|
+
rb_define_singleton_method(cWIN32OLE, "connect", fole_s_connect, -1);
|
53
|
+
+ rb_define_singleton_method(cWIN32OLE, "connect_unknown", fole_s_connect_unknown, 1);
|
54
|
+
rb_define_singleton_method(cWIN32OLE, "const_load", fole_s_const_load, -1);
|
55
|
+
|
56
|
+
rb_define_singleton_method(cWIN32OLE, "ole_free", fole_s_free, 1);
|