watir 1.5.4 → 1.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/bin/watir-console +1 -0
  2. data/changes.rb +16 -2
  3. data/readme.rb +2 -16
  4. data/unittests/buttons_test.rb +74 -101
  5. data/unittests/buttons_xpath_test.rb +3 -3
  6. data/unittests/checkbox_test.rb +3 -3
  7. data/unittests/checkbox_xpath_test.rb +3 -3
  8. data/unittests/core_tests.rb +1 -1
  9. data/unittests/css_test.rb +2 -7
  10. data/unittests/defer_test.rb +2 -2
  11. data/unittests/dialog_test.rb +2 -2
  12. data/unittests/div2_xpath_test.rb +1 -1
  13. data/unittests/div_test.rb +122 -121
  14. data/unittests/div_xpath_test.rb +3 -3
  15. data/unittests/errorchecker_test.rb +3 -8
  16. data/unittests/filefield_test.rb +4 -7
  17. data/unittests/filefield_xpath_test.rb +3 -5
  18. data/unittests/form_test.rb +7 -7
  19. data/unittests/form_xpath_test.rb +6 -6
  20. data/unittests/frame_test.rb +8 -9
  21. data/unittests/google_form_test.rb +1 -2
  22. data/unittests/html/div.html +7 -1
  23. data/unittests/html/lists.html +1 -1
  24. data/unittests/ie_mock.rb +4 -2
  25. data/unittests/ie_test.rb +2 -2
  26. data/unittests/images_test.rb +2 -2
  27. data/unittests/images_xpath_test.rb +2 -2
  28. data/unittests/links_multi_test.rb +23 -9
  29. data/unittests/links_test.rb +7 -7
  30. data/unittests/links_xpath_test.rb +2 -3
  31. data/unittests/lists_test.rb +6 -3
  32. data/unittests/map_test.rb +1 -2
  33. data/unittests/minmax_test.rb +4 -5
  34. data/unittests/navigate_test.rb +18 -23
  35. data/unittests/nbsp_xpath_test.rb +4 -5
  36. data/unittests/{screen_capture_test.rb → other/screen_capture_test.rb} +1 -1
  37. data/unittests/pagecontainstext_test.rb +3 -4
  38. data/unittests/parent_child_test.rb +1 -1
  39. data/unittests/pre_test.rb +2 -3
  40. data/unittests/radios_test.rb +13 -17
  41. data/unittests/radios_xpath_test.rb +3 -3
  42. data/unittests/selectbox_test.rb +6 -14
  43. data/unittests/selectbox_xpath_test.rb +3 -3
  44. data/unittests/setup.rb +30 -10
  45. data/unittests/speed_settings_test.rb +2 -3
  46. data/unittests/table_cell_using_xpath_test.rb +2 -7
  47. data/unittests/table_test.rb +144 -136
  48. data/unittests/table_xpath_test.rb +5 -9
  49. data/unittests/textarea_test.rb +3 -7
  50. data/unittests/textarea_xpath_test.rb +5 -9
  51. data/unittests/textfield_for_ch_char_test.rb +1 -1
  52. data/unittests/textfields_test.rb +3 -4
  53. data/unittests/textfields_xpath_test.rb +3 -3
  54. data/unittests/windows/attach_to_existing_window_test.rb +2 -2
  55. data/unittests/windows/attach_to_new_window_test.rb +2 -2
  56. data/unittests/windows/close_window_test.rb +2 -3
  57. data/unittests/windows/frame_links_test.rb +1 -1
  58. data/unittests/windows/iedialog_test.rb +3 -3
  59. data/unittests/windows/js_events_test.rb +2 -4
  60. data/unittests/windows/modal_dialog_test.rb +2 -2
  61. data/unittests/windows/send_keys_test.rb +2 -4
  62. data/watir.rb +4 -13
  63. data/watir/assertions.rb +9 -1
  64. data/watir/collections.rb +6 -11
  65. data/watir/container.rb +9 -99
  66. data/watir/cookiemanager.rb +4 -1
  67. data/watir/element.rb +8 -1
  68. data/watir/ie.rb +2 -2
  69. data/watir/input_elements.rb +2 -2
  70. data/watir/non_control_elements.rb +39 -2
  71. data/watir/page-container.rb +1 -1
  72. data/watir/table.rb +25 -23
  73. metadata +68 -54
  74. data/watir/bonus-elements.rb +0 -65
  75. data/watir/testUnitAddons.rb +0 -8
@@ -1 +1,2 @@
1
+ #!/usr/bin/env ruby
1
2
  exec 'irb.bat -r irb/completion -r watir/irb-history -r watir --simple-prompt --readline'
data/changes.rb CHANGED
@@ -1,4 +1,18 @@
1
1
  =begin rdoc
2
+ == Version 1.5.4
3
+ New Features
4
+ * Add new speed, :zippy. This is like fast, but, in effect, it does a TextField#value= instead of a TextField#set. If you have specific text fields that you never want this to happen to, use ie.text_field(:how, what).requires_typing.set instead.
5
+ http://svn.openqa.org/fisheye/changelog/watir/?cs=1295
6
+ * Add support for Chinese input as supplied by Vincent Xu.
7
+ http://jira.openqa.org/browse/WTR-71.
8
+
9
+ Bug Fixes
10
+ * Add dependency on windows-pr 0.6.6, which seems to be necessary on Vista.
11
+ * Fix for bug in IE.close_others provided by Paul Taylor.
12
+ http://jira.openqa.org/browse/WTR-194
13
+ * Fix for error when using verify_equal with ci_reporter, provided by Marcog.
14
+ http://svn.openqa.org/fisheye/changelog/watir/?cs=1301
15
+
2
16
  == Version 1.5.3
3
17
  Bug fixes and minor cleanup.
4
18
 
@@ -10,7 +24,7 @@ Bug fixes and minor cleanup.
10
24
  * Fix tests.
11
25
  * Update documentation.
12
26
 
13
- Major Changes in 1.5.1
27
+ Major Changes in 1.5.2
14
28
  Support for IE's Modal Dialogs.
15
29
  showModalDialog()
16
30
  Any method can be used to specify an element (:text, :class, etc.).
@@ -20,7 +34,7 @@ Major Changes in 1.5.1
20
34
  One can now use multiple attributes to specify an element.
21
35
  ie.span(:class =>'Label', :text => 'Add new').click
22
36
 
23
- Other Changes in 1.5.1
37
+ Other Changes in 1.5.2
24
38
  * Migrated IE.new_process from watir/contrib and improved its reliability. We now recommend IE.new_process over IE.new as a way to avoid numerous errors detailed in http://jira.openqa.org/browse/WTR-150.
25
39
  * Added IE.start_process. This works like IE.start, but uses the new_process mechanism to start IE.
26
40
  * Added IE.new_window and IE.start_window. This are synonyms for IE.new and IE.start.
data/readme.rb CHANGED
@@ -66,21 +66,6 @@ Typical Usage
66
66
 
67
67
  * :id and :name are the quickest of these to process, and so should be used when possible to speed up scripts.
68
68
 
69
- The objects that are currently supported include
70
- Button
71
- Radio
72
- CheckBox
73
- TextField (Including TextArea and Password)
74
- Hidden
75
- SelectList
76
- Label
77
- Span
78
- Div
79
- P
80
- Link
81
- Table
82
- Image
83
-
84
69
  These 2 web sites provide info on Internet Explorer and on the DOM as implemented by Internet Explorer
85
70
  http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/webbrowser.asp
86
71
  http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/overview/overview.asp
@@ -98,9 +83,9 @@ Javascript Pop Up Support
98
83
  This is the prefered method for dealing wth pop ups, file requesters etc. Support for Winclickers will be removed.
99
84
 
100
85
  Contacts:
101
- Paul Rogers (paul.rogers@shaw.ca)
102
86
  Bret Pettichord (bret@pettichord.com)
103
87
  Charley Baker (charley.baker@gmail.com)
88
+ Paul Rogers (paul.rogers@shaw.ca)
104
89
  The mailing list: http://groups.google.com/group/watir-general
105
90
 
106
91
  Contributors:
@@ -141,6 +126,7 @@ Contributors:
141
126
  Zeljko Filipin
142
127
  Paul Taylor - Bug fix 194
143
128
  Vincent Xu - Chinese input support
129
+ Tomislav Car - Filefield fix (210)
144
130
 
145
131
  Acknowledgements:
146
132
  Chris Morris
@@ -1,133 +1,106 @@
1
1
  # feature tests for Buttons
2
- # revision: $Revision: 962 $
2
+ # revision: $Revision: 1348 $
3
3
 
4
4
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
5
5
  require 'unittests/setup'
6
6
 
7
- class TC_Buttons < Test::Unit::TestCase
8
- include Watir
9
-
7
+ class TC_Button < Test::Unit::TestCase
8
+ include Watir::Exception
10
9
  def setup
11
- $ie.goto($htmlRoot + "buttons1.html")
12
- end
13
-
14
- def goto_frames_page
15
- $ie.goto($htmlRoot + "frame_buttons.html")
10
+ goto_page "buttons1.html"
16
11
  end
17
12
 
18
- def aatest_Spinner
19
- s = Spinner.new
20
- i = 0
21
- while(i < 100)
22
- sleep 0.05
23
- print s.next
24
- i+=1
25
- end
26
- s = nil
27
- end
28
-
29
- def aaatest_Button_to_s
30
- # i think the tests for to_s should be dropped. The output is not in a nice format to be tested, and the
31
- # individual properties are tested in the test_properties method
32
-
33
- b4 = ['name b4',
34
- 'type button',
35
- 'id b5',
36
- 'value Disabled Button',
37
- 'disabled true']
38
- b1 = ['name b1',
39
- 'type button',
40
- 'id b2',
41
- 'value Click Me',
42
- 'disabled false']
43
-
44
- assert_equal(b4, $ie.button(:name, "b4").to_s)
45
- assert_equal(b1, $ie.button(:caption, "Click Me").to_s)
46
- assert_equal(b1, $ie.button(:index, 1).to_s)
47
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ie.button(:name, "noName").to_s }
13
+ def test_to_s
14
+ b4 = [
15
+ 'type: *button',
16
+ 'id: *b5',
17
+ 'name: *b4',
18
+ 'value: *Disabled Button',
19
+ 'disabled: *true']
20
+ b1 = [
21
+ 'type: *button',
22
+ 'id: *b2',
23
+ 'name: *b1',
24
+ 'value: *Click Me',
25
+ 'disabled: *false']
26
+ assert_match(Regexp.new(b4.join("\n")), browser.button(:name, "b4").to_s)
27
+ assert_match(Regexp.new(b1.join("\n")), browser.button(:caption, "Click Me").to_s)
28
+ assert_match(Regexp.new(b1.join("\n")), browser.button(:index, 1).to_s)
29
+ assert_raises(UnknownObjectException) { browser.button(:name, "noName").to_s }
48
30
  end
49
31
 
50
32
  def test_properties
51
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ie.button(:name, "noName").id }
52
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ie.button(:name, "noName").name }
53
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ie.button(:name, "noName").disabled }
54
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ie.button(:name, "noName").type }
55
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ie.button(:name, "noName").value }
33
+ assert_raises(UnknownObjectException) { browser.button(:name, "noName").id }
34
+ assert_raises(UnknownObjectException) { browser.button(:name, "noName").name }
35
+ assert_raises(UnknownObjectException) { browser.button(:name, "noName").disabled }
36
+ assert_raises(UnknownObjectException) { browser.button(:name, "noName").type }
37
+ assert_raises(UnknownObjectException) { browser.button(:name, "noName").value }
56
38
 
57
- assert_equal("b1" , $ie.button(:index, 1).name )
58
- assert_equal("b2" , $ie.button(:index, 1).id )
59
- assert_equal("button" , $ie.button(:index, 1).type )
60
- assert_equal("Click Me" , $ie.button(:index, 1).value )
61
- assert_equal(false , $ie.button(:index, 1).disabled )
62
- assert_equal("italic_button" , $ie.button(:name, "b1").class_name )
63
- assert_equal("" , $ie.button(:name , "b4").class_name )
39
+ assert_equal("b1", browser.button(:index, 1).name)
40
+ assert_equal("b2", browser.button(:index, 1).id)
41
+ assert_equal("button", browser.button(:index, 1).type)
42
+ assert_equal("Click Me", browser.button(:index, 1).value)
43
+ assert_equal(false, browser.button(:index, 1).disabled)
44
+ assert_equal("italic_button", browser.button(:name, "b1").class_name)
45
+ assert_equal("", browser.button(:name , "b4").class_name)
46
+
47
+ assert_equal("b1" , browser.button(:id, "b2").name )
48
+ assert_equal("b2" , browser.button(:id, "b2").id )
49
+ assert_equal("button" , browser.button(:id, "b2").type )
64
50
 
51
+ assert_equal("b4" , browser.button(:index, 2).name )
52
+ assert_equal("b5" , browser.button(:index, 2).id )
53
+ assert_equal("button" , browser.button(:index, 2).type )
54
+ assert_equal("Disabled Button" , browser.button(:index, 2).value )
55
+ assert_equal(true , browser.button(:index, 2).disabled )
65
56
 
66
- assert_equal("b1" , $ie.button(:id, "b2").name )
67
- assert_equal("b2" , $ie.button(:id, "b2").id )
68
- assert_equal("button" , $ie.button(:id, "b2").type )
69
-
70
- assert_equal("b4" , $ie.button(:index, 2).name )
71
- assert_equal("b5" , $ie.button(:index, 2).id )
72
- assert_equal("button" , $ie.button(:index, 2).type )
73
- assert_equal("Disabled Button" , $ie.button(:index, 2).value )
74
- assert_equal(true , $ie.button(:index, 2).disabled )
75
-
76
- assert_equal( "" , $ie.button(:index, 2).title )
77
- assert_equal( "this is button1" , $ie.button(:index, 1).title )
57
+ assert_equal( "" , browser.button(:index, 2).title )
58
+ assert_equal( "this is button1" , browser.button(:index, 1).title )
78
59
  end
79
60
 
80
-
81
- def test_button_using_default
82
- # since most of the time, a button will be accessed based on its caption, there is a default way of accessing it....
83
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ie.button( "Missing Caption").click }
61
+ def test_default_how
62
+ assert_raises(UnknownObjectException) { browser.button( "Missing Caption").click }
84
63
 
85
- $ie.button("Click Me").click
86
- assert($ie.text.include?("PASS") )
64
+ browser.button("Click Me").click
65
+ assert(browser.text.include?("PASS") )
87
66
  end
88
67
 
89
- def test_Button_click_only
90
- $ie.button(:caption, "Click Me").click
91
- assert($ie.text.include?("PASS") )
92
- end
93
-
94
- def test_button_click
95
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ie.button(:caption, "Missing Caption").click }
96
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ie.button(:id, "missingID").click }
97
-
98
- assert_raises(ObjectDisabledException , "ObjectDisabledException was supposed to be thrown" ) { $ie.button(:caption, "Disabled Button").click }
68
+ def test_click
69
+ assert_raises(UnknownObjectException) { browser.button(:caption, "Missing Caption").click }
70
+ assert_raises(UnknownObjectException) { browser.button(:id, "missingID").click }
71
+ assert_raises(ObjectDisabledException) { browser.button(:caption, "Disabled Button").click }
99
72
 
100
- $ie.button(:caption, "Click Me").click
101
- assert($ie.text.include?("PASS") )
73
+ browser.button(:caption, "Click Me").click
74
+ assert(browser.text.include?("PASS"))
102
75
  end
103
76
 
104
- def test_Button_Exists
105
- assert($ie.button(:caption, "Click Me").exists?)
106
- assert($ie.button(:caption, "Submit").exists?)
107
- assert($ie.button(:name, "b1").exists?)
108
- assert($ie.button(:id, "b2").exists?)
109
- assert($ie.button(:caption, /sub/i).exists?)
77
+ def test_exists
78
+ assert(browser.button(:caption, "Click Me").exists?)
79
+ assert(browser.button(:caption, "Submit").exists?)
80
+ assert(browser.button(:name, "b1").exists?)
81
+ assert(browser.button(:id, "b2").exists?)
82
+ assert(browser.button(:caption, /sub/i).exists?)
110
83
 
111
- assert(!$ie.button(:caption, "missingcaption").exists?)
112
- assert(!$ie.button(:name, "missingname").exists?)
113
- assert(!$ie.button(:id, "missingid").exists?)
114
- assert(!$ie.button(:caption, /missing/i).exists?)
84
+ assert(!browser.button(:caption, "missingcaption").exists?)
85
+ assert(!browser.button(:name, "missingname").exists?)
86
+ assert(!browser.button(:id, "missingid").exists?)
87
+ assert(!browser.button(:caption, /missing/i).exists?)
115
88
  end
116
89
 
117
- def test_Button_Enabled
90
+ def test_enabled
118
91
  assert($ie.button(:caption, "Click Me").enabled?)
119
- assert(!$ie.button(:caption, "Disabled Button").enabled?)
120
- assert(!$ie.button(:name, "b4").enabled?)
121
- assert(!$ie.button(:id, "b5").enabled?)
92
+ assert(!browser.button(:caption, "Disabled Button").enabled?)
93
+ assert(!browser.button(:name, "b4").enabled?)
94
+ assert(!browser.button(:id, "b5").enabled?)
122
95
 
123
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ie.button(:name, "noName").enabled? }
96
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { browser.button(:name, "noName").enabled? }
124
97
  end
125
98
 
126
- def test_frame
127
- goto_frames_page
128
-
129
- assert($ie.frame("buttonFrame").button(:caption, "Click Me").enabled?)
130
- assert_raises( UnknownObjectException , "UnknownObjectException was supposed to be thrown ( no frame name supplied) " ) { $ie.button(:caption, "Disabled Button").enabled?}
99
+ def test_in_frame
100
+ goto_page "frame_buttons.html"
101
+ assert(browser.frame("buttonFrame").button(:caption, "Click Me").enabled?)
102
+ # frame must be specified
103
+ assert_raises(UnknownObjectException) { browser.button(:caption, "Disabled Button").enabled?}
131
104
  end
132
105
 
133
106
  end
@@ -1,14 +1,14 @@
1
1
  # feature tests for Buttons
2
- # revision: $Revision: 962 $
2
+ # revision: $Revision: 1348 $
3
3
 
4
4
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
5
5
  require 'unittests/setup'
6
6
 
7
7
  class TC_Buttons_XPath < Test::Unit::TestCase
8
- include Watir
8
+ include Watir::Exception
9
9
 
10
10
  def setup
11
- $ie.goto($htmlRoot + "buttons1.html")
11
+ goto_page "buttons1.html"
12
12
  end
13
13
 
14
14
  def test_properties
@@ -1,14 +1,14 @@
1
1
  # feature tests for Check Boxes
2
- # revision: $Revision: 1164 $
2
+ # revision: $Revision: 1348 $
3
3
 
4
4
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
5
5
  require 'unittests/setup'
6
6
 
7
7
  class TC_CheckBox < Test::Unit::TestCase
8
- include Watir
8
+ include Watir::Exception
9
9
 
10
10
  def setup
11
- $ie.goto($htmlRoot + "checkboxes1.html")
11
+ goto_page "checkboxes1.html"
12
12
  end
13
13
 
14
14
  def test_checkbox_properties
@@ -1,14 +1,14 @@
1
1
  # feature tests for Check Boxes
2
- # revision: $Revision: 962 $
2
+ # revision: $Revision: 1348 $
3
3
 
4
4
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
5
5
  require 'unittests/setup'
6
6
 
7
7
  class TC_CheckBox_XPath < Test::Unit::TestCase
8
- include Watir
8
+ include Watir::Exception
9
9
 
10
10
  def setup
11
- $ie.goto($htmlRoot + "checkboxes1.html")
11
+ goto_page "checkboxes1.html"
12
12
  end
13
13
 
14
14
  def test_checkbox_properties
@@ -7,7 +7,7 @@ require 'watir'
7
7
 
8
8
  $HIDE_IE = true
9
9
 
10
- require 'unittests/setup.rb'
10
+ require 'unittests/setup'
11
11
 
12
12
  Dir.chdir TOPDIR
13
13
  $core_tests.each {|x| require x}
@@ -1,11 +1,10 @@
1
1
  # feature tests for css
2
- # revision: $Revision: 962 $
2
+ # revision: $Revision: 1348 $
3
3
 
4
4
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
5
5
  require 'unittests/setup'
6
6
 
7
7
  class TC_CSS < Test::Unit::TestCase
8
- include Watir
9
8
 
10
9
  def divTester( message )
11
10
 
@@ -40,12 +39,8 @@ class TC_CSS < Test::Unit::TestCase
40
39
  return s
41
40
  end
42
41
 
43
- def gotoCSSPage
44
- $ie.goto($htmlRoot + "cssTest.html")
45
- end
46
-
47
42
  def test_SuccessMessage
48
- gotoCSSPage
43
+ goto_page "cssTest.html"
49
44
  $ie.button( :caption , "Success").click
50
45
 
51
46
  #isMessageDisplayed( "Success" )
@@ -1,6 +1,6 @@
1
1
  # tests of deferring when a Watir object is bound to a com object (lazy evaluation)
2
2
 
3
- # revision: $Revision: 962 $
3
+ # revision: $Revision: 1348 $
4
4
 
5
5
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
6
6
  require 'unittests/setup'
@@ -22,7 +22,7 @@ class TC_Defer < Test::Unit::TestCase
22
22
  assert_equal('Div Text', div.text)
23
23
  end
24
24
  def test_binding_to_refreshed_page
25
- $ie.goto($htmlRoot + "textfields1.html")
25
+ goto_page "textfields1.html"
26
26
  text_field = $ie.text_field(:name, 'text1')
27
27
  button = $ie.button(:value, 'Clear Events Box')
28
28
  div = $ie.div(:name, 'divvy')
@@ -1,5 +1,5 @@
1
1
  # Feature tests for Dialog class
2
- # revision: $Revision: 1156 $
2
+ # revision: $Revision: 1348 $
3
3
 
4
4
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
5
5
  require 'unittests/setup'
@@ -9,7 +9,7 @@ class TC_Dialog_Test < Test::Unit::TestCase
9
9
  include Watir
10
10
 
11
11
  def setup
12
- $ie.goto($htmlRoot + 'JavascriptClick.html')
12
+ goto_page 'JavascriptClick.html'
13
13
  end
14
14
  def teardown
15
15
  begin
@@ -6,7 +6,7 @@ require 'unittests/setup'
6
6
 
7
7
  class TC_Divs_XPath2 < Test::Unit::TestCase
8
8
  def setup
9
- $ie.goto($htmlRoot + "list_matters.html")
9
+ goto_page "list_matters.html"
10
10
  end
11
11
  def test_div_with_text
12
12
  # Note: this test fails, probably because of bad html to xml translation.
@@ -1,179 +1,180 @@
1
1
  # feature tests for Divs, Spans and P's
2
- # revision: $Revision: 1086 $
2
+ # revision: $Revision: 1354 $
3
3
 
4
4
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
5
5
  require 'unittests/setup'
6
6
 
7
7
  class TC_Divs < Test::Unit::TestCase
8
- include Watir
8
+ include Watir::Exception
9
9
 
10
10
  def setup
11
- $ie.goto($htmlRoot + "div.html")
11
+ uses_page "div.html"
12
12
  end
13
13
 
14
14
  def test_divs
15
- assert_raises(UnknownObjectException) {$ie.div(:id , "div77").click }
16
- assert_raises(UnknownObjectException) {$ie.div(:title , "div77").click }
17
-
18
- assert($ie.text_field(:name, "text1").verify_contains("0") )
19
- $ie.div(:id , "div3").click
20
- assert($ie.text_field(:name, "text1").verify_contains("1") )
21
- $ie.div(:id , "div4").click
22
- assert($ie.text_field(:name, "text1").verify_contains("0") )
15
+ assert_raises(UnknownObjectException) { browser.div(:id, "div77").click }
16
+ assert_raises(UnknownObjectException) { browser.div(:title, "div77").click }
17
+
18
+ assert browser.text_field(:name, "text1").verify_contains("0")
19
+ browser.div(:id, "div3").click
20
+ assert browser.text_field(:name, "text1").verify_contains("1")
21
+ browser.div(:id, "div4").click
22
+ assert browser.text_field(:name, "text1").verify_contains("0")
23
23
  end
24
24
 
25
25
  def test_div_properties
26
- assert_raises(UnknownObjectException) {$ie.div(:id , "div77").text }
27
- assert_raises(UnknownObjectException) {$ie.div(:title , "div77").text }
26
+ assert_raises(UnknownObjectException) { browser.div(:id, "div77").text }
27
+ assert_raises(UnknownObjectException) { browser.div(:title, "div77").text }
28
28
 
29
29
  assert_equal("This div has an onClick that increments text1",
30
- $ie.div(:id , "div3").text.strip )
30
+ browser.div(:id , "div3").text.strip )
31
31
  assert_equal("This text is in a div with an id of div1 and title of test1",
32
- $ie.div(:title , "Test1").text.strip )
33
-
34
- assert_raises(UnknownObjectException) {$ie.div(:id , "div77").class_name }
35
- assert_equal("blueText" , $ie.div(:id , "div2").class_name )
36
- assert_equal("" , $ie.div(:id , "div1").class_name )
37
-
38
- assert_raises(UnknownObjectException) {$ie.div(:index , 44).class_name }
39
- assert_equal("div1" , $ie.div(:index , 1).id )
40
- assert_equal("" , $ie.div(:index , 1).class_name )
41
- assert_equal("blueText" , $ie.div(:index , 2).class_name )
42
- assert_equal("" , $ie.div(:index , 2).value)
43
- assert_equal(false , $ie.div(:index , 2).disabled)
44
- assert_equal("" , $ie.div(:index , 2).name)
45
- assert_equal("div2", $ie.div(:index , 2).id)
32
+ browser.div(:title , "Test1").text.strip )
33
+
34
+ assert_raises(UnknownObjectException) { browser.div(:id , "div77").class_name }
35
+ assert_equal("blueText", browser.div(:id, "div2").class_name)
36
+ assert_equal("", browser.div(:id, "div1").class_name)
37
+
38
+ assert_raises(UnknownObjectException) { browser.div(:index, 44).class_name }
39
+ assert_equal("div1" , browser.div(:index, 1).id)
40
+ assert_equal("" , browser.div(:index, 1).class_name)
41
+ assert_equal("blueText" , browser.div(:index, 2).class_name)
42
+ assert_equal("" , browser.div(:index, 2).value)
43
+ assert_equal(false , browser.div(:index, 2).disabled)
44
+ assert_equal("" , browser.div(:index, 2).name)
45
+ assert_equal("div2", browser.div(:index, 2).id)
46
46
  end
47
47
 
48
48
  def test_div_iterator
49
- assert_equal( 7 , $ie.divs.length)
50
- assert_equal( "div1" , $ie.divs[1].id )
51
-
52
- index =1
53
- $ie.divs.each do |s|
54
- # puts "each - div= " + s.to_s
55
- assert_equal($ie.div(:index, index ).name , s.name )
56
- assert_equal($ie.div(:index, index ).id , s.id )
57
- assert_equal($ie.div(:index, index ).class_name , s.class_name )
58
- index +=1
49
+ assert_equal(8, browser.divs.length)
50
+ assert_equal("div1", browser.divs[1].id)
51
+
52
+ index = 1
53
+ browser.divs.each do |s|
54
+ assert_equal(browser.div(:index,index).name, s.name)
55
+ assert_equal(browser.div(:index,index).id, s.id)
56
+ assert_equal(browser.div(:index,index).class_name , s.class_name)
57
+ index += 1
59
58
  end
60
- assert_equal(index-1, $ie.divs.length) # -1 as we add 1 at the end of the loop
59
+ assert_equal(index - 1, browser.divs.length) # -1 as we add 1 at the end of the loop
61
60
  end
62
61
 
63
62
  def test_objects_in_div
64
- assert($ie.div(:id, 'buttons1').button(:index,1).exists? )
65
- assert(!$ie.div(:id, 'buttons1').button(:index,3).exists? )
66
- assert($ie.div(:id, 'buttons1').button(:name,'b1').exists? )
63
+ assert browser.div(:id, 'buttons1').button(:index,1).exists?
64
+ assert !browser.div(:id, 'buttons1').button(:index,3).exists?
65
+ assert browser.div(:id, 'buttons1').button(:name,'b1').exists?
67
66
 
68
- assert($ie.div(:id, 'buttons2').button(:index,1).exists? )
69
- assert($ie.div(:id, 'buttons2').button(:index,2).exists? )
70
- assert(!$ie.div(:id, 'buttons1').button(:index,3).exists? )
67
+ assert browser.div(:id, 'buttons2').button(:index,1).exists?
68
+ assert browser.div(:id, 'buttons2').button(:index,2).exists?
69
+ assert !browser.div(:id, 'buttons1').button(:index,3).exists?
71
70
 
72
- $ie.div(:id, 'buttons1').button(:index,1).click
71
+ browser.div(:id, 'buttons1').button(:index, 1).click
72
+ assert_equal('button1', browser.div(:id, 'text_fields1').text_field(:index,1).value)
73
73
 
74
- assert_equal( 'button1' , $ie.div(:id , 'text_fields1').text_field(:index,1).value)
75
-
76
- assert_equal( 3 , $ie.div(:id , 'text_fields1').text_fields.length )
77
- $ie.div(:id, 'text_fields1').text_field(:name, 'div_text1').set("drink me")
78
- assert_equal("drink me", $ie.div(:id, 'text_fields1').text_field(:name, 'div_text1').getContents)
74
+ assert_equal(3, browser.div(:id, 'text_fields1').text_fields.length )
75
+ browser.div(:id, 'text_fields1').text_field(:name, 'div_text1').set("drink me")
76
+ assert_equal("drink me", browser.div(:id, 'text_fields1').text_field(:name, 'div_text1').getContents)
77
+ end
78
+
79
+ def test_images_inside_a_div
80
+ assert_equal(3, browser.div(:id, 'hasImages').images.length)
81
+ assert_match(/triangle/, browser.div(:id, 'hasImages').images[1].src)
82
+ assert_match(/circle/, browser.div(:id, 'hasImages').image(:id , 'circle').src)
79
83
  end
80
84
 
81
85
  #---- Span Tests ---
82
86
  def test_spans
83
- assert_raises(UnknownObjectException) {$ie.span(:id , "span77").click }
84
- assert_raises(UnknownObjectException) {$ie.span(:title , "span77").click }
85
-
86
- assert($ie.text_field(:name, "text2").verify_contains("0") )
87
- $ie.span(:id , "span3").click
88
- assert($ie.text_field(:name, "text2").verify_contains("1") )
87
+ assert_raises(UnknownObjectException) {browser.span(:id , "span77").click }
88
+ assert_raises(UnknownObjectException) {browser.span(:title , "span77").click }
89
89
 
90
- $ie.span(:id , "span4").click
91
- assert($ie.text_field(:name, "text2").verify_contains("0") )
90
+ assert(browser.text_field(:name, "text2").verify_contains("0") )
91
+ browser.span(:id , "span3").click
92
+ assert(browser.text_field(:name, "text2").verify_contains("1") )
92
93
 
94
+ browser.span(:id , "span4").click
95
+ assert(browser.text_field(:name, "text2").verify_contains("0") )
93
96
  end
94
97
 
95
98
  def test_span_properties
96
- assert_raises(UnknownObjectException) {$ie.span(:id , "span77").text }
97
- assert_raises(UnknownObjectException) {$ie.span(:title , "span77").text }
98
-
99
- assert_equal("This span has an onClick that increments text2" , $ie.span(:id , "span3").text.strip )
100
- assert_equal("This text is in a span with an id of span1 and title of test2" , $ie.span(:title , "Test2").text.strip )
101
-
102
- assert_raises(UnknownObjectException) {$ie.span(:id , "span77").class_name }
103
- assert_equal("blueText" , $ie.span(:id , "span2").class_name )
104
- assert_equal("" , $ie.span(:id , "span1").class_name )
105
-
106
- assert_raises(UnknownObjectException) {$ie.span(:index , 44).class_name }
107
- assert_equal("span1" , $ie.span(:index , 1).id )
108
- assert_equal("" , $ie.span(:index , 1).class_name )
109
- assert_equal("blueText" , $ie.span(:index , 2).class_name )
110
- assert_equal("" , $ie.span(:index , 2).value)
111
- assert_equal(false , $ie.span(:index , 2).disabled)
112
- assert_equal("" , $ie.span(:index , 2).name)
113
- assert_equal("span2", $ie.span(:index , 2).id)
99
+ assert_raises(UnknownObjectException) {browser.span(:id , "span77").text }
100
+ assert_raises(UnknownObjectException) {browser.span(:title , "span77").text }
101
+
102
+ assert_equal("This span has an onClick that increments text2" , browser.span(:id , "span3").text.strip )
103
+ assert_equal("This text is in a span with an id of span1 and title of test2" , browser.span(:title , "Test2").text.strip )
104
+
105
+ assert_raises(UnknownObjectException) {browser.span(:id , "span77").class_name }
106
+ assert_equal("blueText" , browser.span(:id , "span2").class_name )
107
+ assert_equal("" , browser.span(:id , "span1").class_name )
108
+
109
+ assert_raises(UnknownObjectException) {browser.span(:index , 44).class_name }
110
+ assert_equal("span1" , browser.span(:index , 1).id )
111
+ assert_equal("" , browser.span(:index , 1).class_name )
112
+ assert_equal("blueText" , browser.span(:index , 2).class_name )
113
+ assert_equal("" , browser.span(:index , 2).value)
114
+ assert_equal(false , browser.span(:index , 2).disabled)
115
+ assert_equal("" , browser.span(:index , 2).name)
116
+ assert_equal("span2", browser.span(:index , 2).id)
114
117
  end
115
118
 
116
119
  def test_span_iterator
117
- assert_equal(7, $ie.spans.length)
118
- assert_equal("span1", $ie.spans[1].id)
120
+ assert_equal(7, browser.spans.length)
121
+ assert_equal("span1", browser.spans[1].id)
119
122
 
120
123
  index = 1
121
- $ie.spans.each do |s|
124
+ browser.spans.each do |s|
122
125
  # puts "each - span = " + s.to_s
123
- assert_equal($ie.span(:index, index ).name , s.name )
124
- assert_equal($ie.span(:index, index ).id , s.id )
125
- assert_equal($ie.span(:index, index ).class_name , s.class_name )
126
+ assert_equal(browser.span(:index, index ).name , s.name )
127
+ assert_equal(browser.span(:index, index ).id , s.id )
128
+ assert_equal(browser.span(:index, index ).class_name , s.class_name )
126
129
  index += 1
127
130
  end
128
- assert_equal(index - 1, $ie.spans.length) # -1 as we add 1 at the end of the loop
131
+ assert_equal(index - 1, browser.spans.length) # -1 as we add 1 at the end of the loop
129
132
  end
130
133
 
131
134
  def test_objects_in_span
132
- assert($ie.span(:id, 'buttons1').button(:index,1).exists? )
133
- assert(!$ie.span(:id, 'buttons1').button(:index,3).exists? )
134
- assert($ie.span(:id, 'buttons1').button(:name,'b1').exists? )
135
-
136
- assert($ie.span(:id, 'buttons2').button(:index,1).exists? )
137
- assert($ie.span(:id, 'buttons2').button(:index,2).exists? )
138
- assert(!$ie.span(:id, 'buttons1').button(:index,3).exists? )
139
-
140
- $ie.span(:id, 'buttons1').button(:index,1).click
135
+ assert(browser.span(:id, 'buttons1').button(:index,1).exists? )
136
+ assert(!browser.span(:id, 'buttons1').button(:index,3).exists? )
137
+ assert(browser.span(:id, 'buttons1').button(:name,'b1').exists? )
141
138
 
142
- assert_equal( 'button1' , $ie.span(:id , 'text_fields1').text_field(:index,1).value)
139
+ assert(browser.span(:id, 'buttons2').button(:index,1).exists? )
140
+ assert(browser.span(:id, 'buttons2').button(:index,2).exists? )
141
+ assert(!browser.span(:id, 'buttons1').button(:index,3).exists? )
143
142
 
144
- assert_equal( 3 , $ie.span(:id , 'text_fields1').text_fields.length )
143
+ browser.span(:id, 'buttons1').button(:index,1).click
144
+ assert_equal( 'button1' , browser.span(:id , 'text_fields1').text_field(:index,1).value)
145
+ assert_equal( 3 , browser.span(:id , 'text_fields1').text_fields.length )
145
146
  end
146
147
 
147
148
  def test_p
148
- assert($ie.p(:id, 'number1').exists?)
149
- assert($ie.p(:index, 3).exists?)
150
- assert($ie.p(:title, 'test_3').exists?)
151
-
152
- assert(!$ie.p(:id, 'missing').exists?)
153
- assert(!$ie.p(:index, 8).exists?)
154
- assert(!$ie.p(:title, 'test_55').exists?)
155
-
156
- assert_raises( UnknownObjectException) {$ie.p(:id , 'missing').class_name }
157
- assert_raises( UnknownObjectException) {$ie.p(:id , 'missing').text }
158
- assert_raises( UnknownObjectException) {$ie.p(:id , 'missing').title }
159
- assert_raises( UnknownObjectException) {$ie.p(:id , 'missing').to_s }
160
- assert_raises( UnknownObjectException) {$ie.p(:id , 'missing').disabled }
161
-
162
- assert_equal( 'redText' , $ie.p(:index,1).class_name)
163
- assert_equal( 'P_tag_1' , $ie.p(:index,1).title)
164
- assert_equal( 'This text is in a p with an id of number2' , $ie.p(:index,2).text)
149
+ assert(browser.p(:id, 'number1').exists?)
150
+ assert(browser.p(:index, 3).exists?)
151
+ assert(browser.p(:title, 'test_3').exists?)
152
+
153
+ assert(!browser.p(:id, 'missing').exists?)
154
+ assert(!browser.p(:index, 8).exists?)
155
+ assert(!browser.p(:title, 'test_55').exists?)
156
+
157
+ assert_raises( UnknownObjectException) {browser.p(:id , 'missing').class_name }
158
+ assert_raises( UnknownObjectException) {browser.p(:id , 'missing').text }
159
+ assert_raises( UnknownObjectException) {browser.p(:id , 'missing').title }
160
+ assert_raises( UnknownObjectException) {browser.p(:id , 'missing').to_s }
161
+ assert_raises( UnknownObjectException) {browser.p(:id , 'missing').disabled }
162
+
163
+ assert_equal('redText' , browser.p(:index,1).class_name)
164
+ assert_equal('P_tag_1' , browser.p(:index,1).title)
165
+ assert_equal('This text is in a p with an id of number2' , browser.p(:index,2).text)
165
166
  end
166
167
 
167
168
  def test_p_iterator
168
- assert_equal( 3, $ie.ps.length)
169
- assert_equal( 'italicText', $ie.ps[2].class_name)
170
- assert_equal( 'number3', $ie.ps[3].id)
171
-
172
- count=1
173
- $ie.ps.each do |p|
174
- assert_equal('number'+count.to_s , p.id)
175
- count+=1
169
+ assert_equal(3, browser.ps.length)
170
+ assert_equal('italicText', browser.ps[2].class_name)
171
+ assert_equal('number3', browser.ps[3].id)
172
+
173
+ count = 1
174
+ browser.ps.each do |p|
175
+ assert_equal('number'+count.to_s, p.id)
176
+ count += 1
176
177
  end
177
- assert_equal( count-1 , $ie.ps.length)
178
+ assert_equal(count - 1, browser.ps.length)
178
179
  end
179
180
  end