watir 1.8.1 → 1.9.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/CHANGES +10 -0
  2. data/VERSION +1 -1
  3. data/lib/watir/container.rb +7 -2
  4. data/lib/watir/core.rb +4 -0
  5. data/lib/watir/dialogs/file_upload.rb +36 -0
  6. data/lib/watir/dialogs/javascript.rb +47 -0
  7. data/lib/watir/element.rb +44 -4
  8. data/lib/watir/frame.rb +15 -2
  9. data/lib/watir/ie-class.rb +42 -18
  10. data/lib/watir/ie.rb +3 -6
  11. data/lib/watir/image.rb +5 -4
  12. data/lib/watir/input_elements.rb +40 -89
  13. data/lib/watir/modal_dialog.rb +6 -0
  14. data/lib/watir/module.rb +0 -23
  15. data/lib/watir/win32.rb +4 -0
  16. data/lib/watir/win32ole.rb +5 -2
  17. data/lib/watir/win32ole/1.8.7/win32ole.so +0 -0
  18. data/rakefile.rb +2 -1
  19. data/unittests/click_no_wait_test.rb +4 -2
  20. data/unittests/close_all_test.rb +1 -1
  21. data/unittests/dialog_test.rb +22 -38
  22. data/unittests/filefield_xpath_test.rb +4 -1
  23. data/unittests/form_test.rb +1 -0
  24. data/unittests/frame_test.rb +17 -1
  25. data/unittests/html/ie_9.html +6 -0
  26. data/unittests/html/iframe.html +3 -0
  27. data/unittests/ie9_test.rb +16 -0
  28. data/unittests/images_test.rb +1 -1
  29. data/unittests/minmax_test.rb +16 -9
  30. data/unittests/no_wait_test.rb +10 -4
  31. data/unittests/setup.rb +0 -13
  32. data/unittests/version_test.rb +15 -0
  33. data/unittests/win32ole_so_test.rb +35 -0
  34. data/unittests/windows/send_keys_test.rb +0 -6
  35. data/watir.gemspec +6 -4
  36. metadata +67 -38
  37. data/lib/watir/AutoItX.chm +0 -0
  38. data/lib/watir/AutoItX3.dll +0 -0
  39. data/lib/watir/WindowHelper.rb +0 -49
  40. data/lib/watir/clickJSDialog.rb +0 -19
  41. data/lib/watir/dialog.rb +0 -46
  42. data/lib/watir/popup.rb +0 -30
  43. data/lib/watir/setFileDialog.rb +0 -16
  44. data/lib/watir/win32ole/win32ole.so +0 -0
  45. data/lib/watir/winClicker.rb +0 -460
  46. data/unittests/other/WindowLogonExample.rb +0 -28
  47. data/unittests/other/WindowLogonExtra.rb +0 -7
  48. data/unittests/other/jscriptExtraAlert.rb +0 -7
  49. data/unittests/other/jscriptExtraConfirmCancel.rb +0 -7
  50. data/unittests/other/jscriptExtraConfirmOk.rb +0 -7
  51. data/unittests/other/jscriptPushButton.rb +0 -6
  52. data/unittests/other/jscript_test.rb +0 -63
  53. data/unittests/popups_test.rb +0 -41
@@ -1,3 +1,9 @@
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
+
1
7
  module Watir
2
8
  class ModalDialog
3
9
  include Container
data/lib/watir/module.rb CHANGED
@@ -9,27 +9,4 @@ module Watir
9
9
  def self.until_with_timeout # block
10
10
  Wait.until(IE.attach_timeout) { yield }
11
11
  end
12
-
13
- @@autoit = nil
14
-
15
- def self.autoit
16
- unless @@autoit
17
- begin
18
- @@autoit = WIN32OLE.new('AutoItX3.Control')
19
- rescue WIN32OLERuntimeError
20
- _register('AutoItX3.dll')
21
- @@autoit = WIN32OLE.new('AutoItX3.Control')
22
- end
23
- end
24
- @@autoit
25
- end
26
-
27
- def self._register(dll)
28
- system("regsvr32.exe /s " + "#{@@dir}/#{dll}".gsub('/', '\\'))
29
- end
30
-
31
- def self._unregister(dll)
32
- system("regsvr32.exe /s /u " + "#{@@dir}/#{dll}".gsub('/', '\\'))
33
- end
34
-
35
12
  end
data/lib/watir/win32.rb CHANGED
@@ -1,3 +1,7 @@
1
+ require 'dl/import'
2
+ require 'dl/struct'
3
+ require 'Win32API'
4
+
1
5
  module Watir
2
6
  module Win32
3
7
  # this will find the IEDialog.dll file in its build location
@@ -3,9 +3,12 @@
3
3
  # Use our modified win32ole library
4
4
 
5
5
  if RUBY_VERSION =~ /^1\.8/
6
- $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'watir', 'win32ole'))
6
+ $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'watir', 'win32ole', '1.8.7'))
7
+ # WIP
8
+ #elsif RUBY_VERSION =~ /^1\.9/
9
+ # $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'watir', 'win32ole', '1.9.2'))
7
10
  else
8
- # loading win32ole from stdlib on 1.9
11
+ # loading win32ole from stdlib
9
12
  end
10
13
 
11
14
 
data/rakefile.rb CHANGED
@@ -18,7 +18,8 @@ Rake::RDocTask.new('rdoc') do |rdoc|
18
18
  rdoc.rdoc_files.include(file)
19
19
  end
20
20
  rdoc.rdoc_files.include('lib/watir/contrib/*.rb')
21
- rdoc.rdoc_files.include('lib/watir/*.rb')
21
+ rdoc.rdoc_files.include('lib/watir/dialogs/*.rb')
22
+ rdoc.rdoc_files.include('lib/watir/*.rb')
22
23
  rdoc.rdoc_files.exclude('lib/watir/camel_case.rb')
23
24
  end
24
25
 
@@ -11,11 +11,13 @@ class ClickNoWait_Tests < Watir::TestCase
11
11
  message_div = browser.div(:id => 'div1')
12
12
  assert_equal("nothing", message_div.text)
13
13
  browser.link(:id => 'link1').click_no_wait
14
- assert_equal("message!", message_div.text)
14
+ assert_nothing_raised {
15
+ Watir::Wait.until {message_div.text == "message!"}
16
+ }
15
17
  end
16
18
 
17
19
  def test_spawned_click_no_wait_command
18
- assert_equal("start rubyw -e \"some command\"", browser.link(:id => 'link1').send(:__spawned_no_wait_command, "some command"))
20
+ assert_equal("start rubyw -e \"some command\"", browser.link(:id => 'link1').send(:spawned_no_wait_command, "some command"))
19
21
  end
20
22
 
21
23
  end
@@ -1,4 +1,4 @@
1
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..') unless $SETUP_LOADED
1
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
2
2
  require 'unittests/setup'
3
3
 
4
4
  class TC_CloseAllWindows < Watir::TestCase
@@ -2,7 +2,6 @@
2
2
 
3
3
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
4
4
  require 'unittests/setup'
5
- require 'watir/dialog'
6
5
 
7
6
  class TC_Dialog_Test < Test::Unit::TestCase
8
7
  tags :must_be_visible
@@ -11,67 +10,52 @@ class TC_Dialog_Test < Test::Unit::TestCase
11
10
  def setup
12
11
  goto_page 'JavascriptClick.html'
13
12
  end
14
- def teardown
15
- begin
16
- sleep 0.4 # XXX
17
- dialog.button('OK').click
18
- rescue
19
- end
20
- end
21
-
13
+
22
14
  def test_alert_without_bonus_script
23
15
  browser.button(:id, 'btnAlert').click_no_wait
24
- sleep 0.4 # FIXME: need to be able to poll for window to exist
25
- dialog.button("OK").click
26
- assert_match(/Alert button!/, browser.text_field(:id, "testResult").value)
16
+ browser.javascript_dialog.button("OK").click
17
+ assert_match(/Alert button!/, browser.text_field(:id, "testResult").value)
27
18
  end
28
-
19
+
29
20
  def test_button_name_not_found
30
21
  browser.button(:id, 'btnAlert').click_no_wait
31
- sleep 0.4 # FIXME replace with dialog.exists?
32
- assert_raises(UnknownObjectException) { dialog.button("Yes").click }
33
- dialog.button("OK").click
22
+ assert_raises(::RAutomation::UnknownButtonException) {browser.javascript_dialog.button("Yes").click}
23
+ browser.javascript_dialog.button("OK").click
34
24
  end
35
-
36
- def xtest_exists
37
- assert_false( dialog.exists?) # known bug: finds main window instead of dialog!
38
- browser.button(:id, 'btnAlert').click_no_wait
39
- sleep 0.4 # FIXME: need to add polling
40
- assert dialog.exists?
41
- dialog.button('OK').click
42
- end
43
-
44
- def test_leaves_dialog_open
45
- # should be closed in teardown
25
+
26
+ def test_exists
27
+ assert_false(browser.javascript_dialog.exists?)
46
28
  browser.button(:id, 'btnAlert').click_no_wait
29
+ Watir::Wait.until(5) {browser.javascript_dialog.exists?}
30
+ browser.javascript_dialog.button("OK").click
47
31
  end
48
-
32
+
49
33
  def test_copy_array_elements
50
34
  a = ['a', 'b', 'c']
51
35
  copy = Array.new(a)
52
- c = []
36
+ c = []
53
37
  code = _code_that_copies_readonly_array(a, "c")
54
38
  eval code
55
39
  assert_equal copy, c
56
40
  end
57
-
41
+
58
42
  def test_confirm_ok
59
43
  browser.button(:value, 'confirm').click_no_wait
60
- assert dialog.exists?
61
- dialog.button('OK').click
44
+ Watir::Wait.until(5) {browser.javascript_dialog.exists?}
45
+ browser.javascript_dialog.button("OK").click
62
46
  assert_equal "You pressed the Confirm and OK button!", browser.text_field(:id, 'testResult').value
63
47
  end
64
-
48
+
65
49
  def xtest_confirm_cancel
66
50
  browser.button(:value, 'confirm').click_no_wait
67
- assert dialog.exists?
68
- dialog.button('Cancel').click
51
+ assert browser.javascript_dialog.exists?
52
+ browser.javascript_dialog.button("Cancel").click
69
53
  assert_equal "You pressed the Confirm and Cancel button!", browser.text_field(:id, 'testResult').value
70
54
  end
71
-
55
+
72
56
  def test_dialog_close
73
- dialog.close
74
- assert !dialog.exists?
57
+ browser.javascript_dialog.close
58
+ assert !browser.javascript_dialog.exists?
75
59
  end
76
60
 
77
61
  end
@@ -18,7 +18,10 @@ class TC_FileField_XPath < Test::Unit::TestCase
18
18
  assert_false(browser.file_field(:xpath, "//input[@name='missing']/").exists?)
19
19
  assert_false(browser.file_field(:xpath, "//input[@name='totallybogus']/").exists?)
20
20
  #pop one open and put something in it.
21
- browser.file_field(:xpath, "//input[@name='file1']/").set($htmlRoot + "fileupload.html")
21
+ file = $htmlRoot + "fileupload.html"
22
+ file.gsub! 'file:///', ''
23
+ file.gsub! '/', '\\'
24
+ browser.file_field(:xpath, "//input[@name='file1']/").set(file)
22
25
  #click the upload button
23
26
  browser.button(:xpath, "//input[@name='upload']/").click
24
27
 
@@ -46,6 +46,7 @@ class TC_Forms2 < Test::Unit::TestCase # Note: there is no TC_Forms1
46
46
  def test_form_outer_html
47
47
  expected = "\r\n<FORM id=f2 name=test2 action=pass2.html method=get><BR><INPUT type=submit value=Submit> </FORM>"
48
48
  actual = browser.form(:name, 'test2').html
49
+ actual.sub!('style=""','') # ie9 adds in a style tag so just strip it out
49
50
 
50
51
  # ignore attributes order by sorting them
51
52
  sorted_expected, sorted_actual = [expected, actual].map! do |html|
@@ -168,7 +168,9 @@ class TC_Frames_click_no_wait < Test::Unit::TestCase
168
168
  frame = browser.frame("buttonFrame")
169
169
  assert !frame.text.include?("PASS")
170
170
  frame.button(:id => "b2").click_no_wait
171
- assert frame.text.include?("PASS")
171
+ assert_nothing_raised {
172
+ Watir::Wait.until {frame.text.include?("PASS")}
173
+ }
172
174
  end
173
175
  end
174
176
 
@@ -193,4 +195,18 @@ class TC_frames_method_for_container < Test::Unit::TestCase
193
195
  assert_equal('first_frame', frames[1].id)
194
196
  assert_equal('pass.html', frames[3].src)
195
197
  end
198
+ end
199
+
200
+ class TC_iframe_access < Test::Unit::TestCase
201
+ def setup
202
+ goto_page "iframe.html"
203
+ end
204
+
205
+ def test_frame_without_access_should_still_show_properties
206
+ frame = browser.frame(:name, 'iframe')
207
+ assert_nothing_raised {frame.src}
208
+ assert_equal('http://www.google.com', frame.src)
209
+ assert_raises(FrameAccessDeniedException) {frame.button(:index, 1).click}
210
+ end
211
+
196
212
  end
@@ -0,0 +1,6 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" >
4
+ This page loads with the correct document standards for IE. In IE9, without the doctype everything is run in Quirks mode
5
+ <input type = button class="italic_button" name = b1 id = b2 value = "Click Me" onClick="javascript:document.location='pass.html';" title = "this is button1">
6
+ </html>
@@ -0,0 +1,3 @@
1
+ This iframe gives access denied but we still should be able to get the src property
2
+ <br><br>
3
+ <iframe src ="http://www.google.com" name='iframe'>
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
2
+ require 'unittests/setup'
3
+
4
+ class TC_IE9 < Test::Unit::TestCase
5
+ include Watir::Exception
6
+
7
+ def setup
8
+ goto_page "ie_9.html"
9
+ end
10
+
11
+ def test_clicking_button
12
+ browser.button(:value, "Click Me").click
13
+ assert(browser.text.include?("PASS") )
14
+ end
15
+
16
+ end
@@ -30,7 +30,7 @@ class TC_Images < Test::Unit::TestCase
30
30
  assert( browser.image(:id , /squ/ ).exists? )
31
31
 
32
32
  assert( ! browser.image(:src, "missingsrc.gif").exists? )
33
-
33
+
34
34
  assert( browser.image(:src, "file:///#{$myDir}/html/images/triangle.jpg").exists? )
35
35
  assert( browser.image(:src , /triangle/ ).exists? )
36
36
 
@@ -7,24 +7,31 @@ class TC_MinMax< Test::Unit::TestCase
7
7
  tags :must_be_visible
8
8
  def setup
9
9
  goto_page 'pass.html'
10
- end
10
+ end
11
11
  def teardown
12
12
  browser.restore
13
13
  end
14
14
  def test_minimimum
15
15
  browser.minimize
16
+ assert browser.minimized?
16
17
  end
17
18
  def test_maximum
18
19
  browser.maximize
20
+ assert !browser.minimized?
19
21
  end
20
- def test_front
21
- assert browser.front?
22
- ie2 = Watir::IE.start($htmlRoot + 'blankpage.html')
23
- assert ie2.front?
24
- assert ! browser.front?
25
- browser.bring_to_front
26
- assert browser.front?
27
- ie2.close
22
+ def test_activate
23
+ browser.activate
24
+ assert browser.active?
25
+ begin
26
+ new_browser = Watir::IE.start($htmlRoot + 'blankpage.html')
27
+ assert new_browser.active?
28
+ assert !browser.active?
29
+ browser.activate
30
+ browser.activate # bug in rautomation? It's in front just not activated
31
+ assert browser.active?
32
+ ensure
33
+ new_browser.close
34
+ end
28
35
  end
29
36
  end
30
37
 
@@ -1,22 +1,28 @@
1
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..') unless $SETUP_LOADED
1
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
2
2
  require 'unittests/setup'
3
3
 
4
4
  class TC_No_Wait_Commands < Test::Unit::TestCase
5
5
  def test_fire_event_no_wait
6
6
  goto_page "javascriptevents.html"
7
7
  browser.link(:text, "Check the Status").fire_event_no_wait("onMouseOver")
8
- assert_equal("It worked", browser.status)
8
+ assert_nothing_raised{
9
+ Watir::Wait.until {browser.status == "It worked"}
10
+ }
9
11
  end
10
12
 
11
13
  def test_set_no_wait_text_field
12
14
  goto_page "textfields1.html"
13
15
  browser.text_field(:name, "text1").set_no_wait("watir IE Controller")
14
- assert_equal("watir IE Controller", browser.text_field(:name, "text1").value)
16
+ assert_nothing_raised{
17
+ Watir::Wait.until {browser.text_field(:name, "text1").value == "watir IE Controller"}
18
+ }
15
19
  end
16
20
 
17
21
  def test_set_no_wait_text_select_list
18
22
  goto_page "selectboxes1.html"
19
23
  browser.select_list(:name,'sel1').set_no_wait(/Option 1/)
20
- assert_equal('Option 1', browser.select_list(:name , 'sel1').selected_options.first)
24
+ assert_nothing_raised{
25
+ Watir::Wait.until {browser.select_list(:name , 'sel1').selected_options.first == 'Option 1'}
26
+ }
21
27
  end
22
28
  end
data/unittests/setup.rb CHANGED
@@ -68,16 +68,3 @@ end
68
68
  =end
69
69
 
70
70
  $window_tests = Dir["unittests/windows/*_test.rb"] - ["unittests/windows/ie-each_test.rb"]
71
-
72
- # load development libs also in #click_no_wait processes
73
- Watir::Element.class_eval do
74
- alias_method :__spawned_no_wait_command, :spawned_no_wait_command
75
-
76
- def spawned_no_wait_command(command)
77
- # make it actually wait in tests for easier testing
78
- #
79
- # please note that this implementation of click_no_wait takes considerably more time than
80
- # in real situation due to the loading of setup.rb!
81
- "ruby -r#{File.expand_path(File.join(File.dirname(__FILE__), "setup.rb"))} -e #{command.inspect}"
82
- end
83
- end
@@ -0,0 +1,15 @@
1
+
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
3
+ require 'unittests/setup'
4
+
5
+ class TC_Version < Test::Unit::TestCase
6
+
7
+ def test_full_version
8
+ assert !Watir::IE.version.nil?
9
+ end
10
+
11
+ def test_version_part
12
+ assert Watir::IE.version_parts[0] =~ /^\d+$/
13
+ end
14
+
15
+ end
@@ -0,0 +1,35 @@
1
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..')
2
+ require 'Win32API'
3
+ require 'unittests/setup'
4
+
5
+ # This test makes sure that the win32ole changes will return
6
+ # the dom using GetUnknown, which is added via the win32ole patch
7
+ class TC_Win32OLE < Test::Unit::TestCase
8
+
9
+ def setup
10
+ # this will find the IEDialog.dll file in its build location
11
+ @iedialog_file = (File.expand_path(File.dirname(__FILE__)) + "/../lib/watir/IEDialog/Release/IEDialog.dll").gsub('/', '\\')
12
+
13
+ @ie = Watir::IE.new
14
+ @ie.goto 'www.google.com'
15
+ end
16
+
17
+ def teardown
18
+ @ie.close
19
+ end
20
+
21
+ def test_win32ole_modifications
22
+ fnGetUnknown = Win32API.new(@iedialog_file, 'GetUnknown', ['p', 'p'], 'v')
23
+ intPointer = " " * 4 # will contain the int value of the IUnknown*
24
+ fnGetUnknown.call(@ie.hwnd, intPointer)
25
+ assert_true intPointer
26
+ intArray = intPointer.unpack('L')
27
+ intUnknown = intArray.first
28
+ htmlDoc = WIN32OLE.connect_unknown(intUnknown);
29
+ scriptEngine = htmlDoc.Script
30
+
31
+ # now we get the HTML DOM object!
32
+ body = scriptEngine.document.body
33
+ assert(body.innerHTML =~ /html/)
34
+ end
35
+ end
@@ -23,10 +23,4 @@ class TC_SendKeys < Test::Unit::TestCase
23
23
  assert(browser.text.include?('PASS'))
24
24
  end
25
25
 
26
- tag_method :test_autoregistration, :fails_on_ie
27
- def test_autoregistration
28
- Watir::_unregister('AutoItX3.dll')
29
- assert_raises(WIN32OLERuntimeError) { WIN32OLE.new('AutoItX3.Control') }
30
- assert_nothing_raised { browser.send_keys('{tab}') }
31
- end
32
26
  end