watir-webdriver 0.0.1.dev6 → 0.0.1.dev7

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.
Files changed (94) hide show
  1. data/Rakefile +1 -2
  2. data/VERSION +1 -1
  3. data/lib/watir-webdriver.rb +1 -4
  4. data/lib/watir-webdriver/base_element.rb +14 -7
  5. data/lib/watir-webdriver/browser.rb +3 -1
  6. data/lib/watir-webdriver/elements/button.rb +1 -0
  7. data/lib/watir-webdriver/elements/form.rb +1 -1
  8. data/lib/watir-webdriver/elements/frame.rb +77 -0
  9. data/lib/watir-webdriver/elements/generated.rb +536 -536
  10. data/lib/watir-webdriver/elements/option.rb +3 -0
  11. data/lib/watir-webdriver/elements/table_row.rb +1 -0
  12. data/lib/watir-webdriver/elements/text_field.rb +5 -1
  13. data/lib/watir-webdriver/xpath_support.rb +0 -1
  14. data/spec/base_element_spec.rb +16 -0
  15. data/spec/html/keylogger.html +15 -0
  16. data/spec/watirspec/area_spec.rb +78 -0
  17. data/spec/watirspec/areas_spec.rb +31 -0
  18. data/spec/watirspec/browser_spec.rb +274 -0
  19. data/spec/watirspec/button_spec.rb +242 -0
  20. data/spec/watirspec/buttons_spec.rb +48 -0
  21. data/spec/watirspec/checkbox_spec.rb +272 -0
  22. data/spec/watirspec/checkboxes_spec.rb +32 -0
  23. data/spec/watirspec/dd_spec.rb +123 -0
  24. data/spec/watirspec/dds_spec.rb +31 -0
  25. data/spec/watirspec/div_spec.rb +211 -0
  26. data/spec/watirspec/divs_spec.rb +31 -0
  27. data/spec/watirspec/dl_spec.rb +123 -0
  28. data/spec/watirspec/dls_spec.rb +32 -0
  29. data/spec/watirspec/dt_spec.rb +123 -0
  30. data/spec/watirspec/dts_spec.rb +31 -0
  31. data/spec/watirspec/element_spec.rb +89 -0
  32. data/spec/watirspec/em_spec.rb +97 -0
  33. data/spec/watirspec/ems_spec.rb +32 -0
  34. data/spec/watirspec/filefield_spec.rb +119 -0
  35. data/spec/watirspec/filefields_spec.rb +32 -0
  36. data/spec/watirspec/font_spec.rb +26 -0
  37. data/spec/watirspec/form_spec.rb +63 -0
  38. data/spec/watirspec/forms_spec.rb +33 -0
  39. data/spec/watirspec/frame_spec.rb +135 -0
  40. data/spec/watirspec/frames_spec.rb +62 -0
  41. data/spec/watirspec/hidden_spec.rb +102 -0
  42. data/spec/watirspec/hiddens_spec.rb +32 -0
  43. data/spec/watirspec/hn_spec.rb +93 -0
  44. data/spec/watirspec/hns_spec.rb +38 -0
  45. data/spec/watirspec/image_spec.rb +207 -0
  46. data/spec/watirspec/images_spec.rb +31 -0
  47. data/spec/watirspec/label_spec.rb +75 -0
  48. data/spec/watirspec/labels_spec.rb +31 -0
  49. data/spec/watirspec/li_spec.rb +112 -0
  50. data/spec/watirspec/lib/guards.rb +59 -0
  51. data/spec/watirspec/lib/server.rb +136 -0
  52. data/spec/watirspec/lib/spec_helper.rb +79 -0
  53. data/spec/watirspec/lib/watirspec.rb +72 -0
  54. data/spec/watirspec/link_spec.rb +168 -0
  55. data/spec/watirspec/links_spec.rb +35 -0
  56. data/spec/watirspec/lis_spec.rb +31 -0
  57. data/spec/watirspec/map_spec.rb +76 -0
  58. data/spec/watirspec/maps_spec.rb +32 -0
  59. data/spec/watirspec/meta_spec.rb +22 -0
  60. data/spec/watirspec/metas_spec.rb +30 -0
  61. data/spec/watirspec/ol_spec.rb +78 -0
  62. data/spec/watirspec/ols_spec.rb +31 -0
  63. data/spec/watirspec/option_spec.rb +173 -0
  64. data/spec/watirspec/p_spec.rb +128 -0
  65. data/spec/watirspec/pre_spec.rb +112 -0
  66. data/spec/watirspec/pres_spec.rb +31 -0
  67. data/spec/watirspec/ps_spec.rb +31 -0
  68. data/spec/watirspec/radio_spec.rb +255 -0
  69. data/spec/watirspec/radios_spec.rb +32 -0
  70. data/spec/watirspec/select_list_spec.rb +318 -0
  71. data/spec/watirspec/select_lists_spec.rb +35 -0
  72. data/spec/watirspec/span_spec.rb +142 -0
  73. data/spec/watirspec/spans_spec.rb +31 -0
  74. data/spec/watirspec/spec_helper.rb +17 -0
  75. data/spec/watirspec/strong_spec.rb +89 -0
  76. data/spec/watirspec/strongs_spec.rb +32 -0
  77. data/spec/watirspec/table_bodies_spec.rb +45 -0
  78. data/spec/watirspec/table_body_spec.rb +98 -0
  79. data/spec/watirspec/table_cell_spec.rb +68 -0
  80. data/spec/watirspec/table_cells_spec.rb +47 -0
  81. data/spec/watirspec/table_footer_spec.rb +85 -0
  82. data/spec/watirspec/table_footers_spec.rb +47 -0
  83. data/spec/watirspec/table_header_spec.rb +85 -0
  84. data/spec/watirspec/table_headers_spec.rb +45 -0
  85. data/spec/watirspec/table_row_spec.rb +87 -0
  86. data/spec/watirspec/table_rows_spec.rb +50 -0
  87. data/spec/watirspec/table_spec.rb +160 -0
  88. data/spec/watirspec/tables_spec.rb +33 -0
  89. data/spec/watirspec/text_field_spec.rb +276 -0
  90. data/spec/watirspec/text_fields_spec.rb +35 -0
  91. data/spec/watirspec/ul_spec.rb +76 -0
  92. data/spec/watirspec/uls_spec.rb +33 -0
  93. data/support/html5/html5.idl +1 -1
  94. metadata +181 -21
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe "Dls" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/definition_lists.html")
8
+ end
9
+
10
+ describe "#length" do
11
+ it "returns the number of dls" do
12
+ browser.dls.length.should == 3
13
+ end
14
+ end
15
+
16
+ describe "#[]" do
17
+ it "returns the dl at the given index" do
18
+ browser.dls[0].id.should == "experience-list"
19
+ end
20
+ end
21
+
22
+ describe "#each" do
23
+ it "iterates through dls correctly" do
24
+ browser.dls.each_with_index do |d, index|
25
+ d.text.should == browser.dl(:index, index).text
26
+ d.id.should == browser.dl(:index, index).id
27
+ d.class_name.should == browser.dl(:index, index).class_name
28
+ end
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,123 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe "Dt" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/definition_lists.html")
8
+ end
9
+
10
+ # Exists method
11
+ describe "#exists?" do
12
+ it "returns true if the element exists" do
13
+ browser.dt(:id, "experience").should exist
14
+ browser.dt(:class, "current-industry").should exist
15
+ browser.dt(:xpath, "//dt[@id='experience']").should exist
16
+ browser.dt(:index, 0).should exist
17
+ end
18
+
19
+ it "returns false if the element does not exist" do
20
+ browser.dt(:id, "no_such_id").should_not exist
21
+ end
22
+
23
+ it "raises TypeError when 'what' argument is invalid" do
24
+ lambda { browser.dt(:id, 3.14).exists? }.should raise_error(TypeError)
25
+ end
26
+
27
+ it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
28
+ lambda { browser.dt(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
29
+ end
30
+ end
31
+
32
+ # Attribute methods
33
+ describe "#class_name" do
34
+ it "returns the class attribute if the element exists" do
35
+ browser.dt(:id , "experience").class_name.should == "industry"
36
+ end
37
+
38
+ it "returns an empty string if the element exists but the attribute doesn't" do
39
+ browser.dt(:id , "education").class_name.should == ""
40
+ end
41
+
42
+ it "raises UnknownObjectException if the element does not exist" do
43
+ lambda { browser.dt(:id, "no_such_id").class_name }.should raise_error(UnknownObjectException)
44
+ lambda { browser.dt(:title, "no_such_title").class_name }.should raise_error(UnknownObjectException)
45
+ lambda { browser.dt(:index, 1337).class_name }.should raise_error(UnknownObjectException)
46
+ lambda { browser.dt(:xpath, "//dt[@id='no_such_id']").class_name }.should raise_error(UnknownObjectException)
47
+ end
48
+ end
49
+
50
+ describe "#id" do
51
+ it "returns the id attribute if the element exists" do
52
+ browser.dt(:class, 'industry').id.should == "experience"
53
+ end
54
+
55
+ it "returns an empty string if the element exists, but the attribute doesn't" do
56
+ browser.dt(:class, 'current-industry').id.should == ""
57
+ end
58
+
59
+ it "raises UnknownObjectException if the element does not exist" do
60
+ lambda {browser.dt(:id, "no_such_id").id }.should raise_error(UnknownObjectException)
61
+ lambda {browser.dt(:title, "no_such_id").id }.should raise_error(UnknownObjectException)
62
+ lambda {browser.dt(:index, 1337).id }.should raise_error(UnknownObjectException)
63
+ end
64
+ end
65
+
66
+ describe "#title" do
67
+ it "returns the title of the element" do
68
+ browser.dt(:id, "experience").title.should == "experience"
69
+ end
70
+ end
71
+
72
+ describe "#text" do
73
+ it "returns the text of the element" do
74
+ browser.dt(:id, "experience").text.should == "Experience"
75
+ end
76
+
77
+ it "returns an empty string if the element exists but contains no text" do
78
+ browser.dt(:class, 'noop').text.should == ""
79
+ end
80
+
81
+ it "raises UnknownObjectException if the element does not exist" do
82
+ lambda { browser.dt(:id, "no_such_id").text }.should raise_error(UnknownObjectException)
83
+ lambda { browser.dt(:title, "no_such_title").text }.should raise_error(UnknownObjectException)
84
+ lambda { browser.dt(:index, 1337).text }.should raise_error(UnknownObjectException)
85
+ lambda { browser.dt(:xpath, "//dt[@id='no_such_id']").text }.should raise_error(UnknownObjectException)
86
+ end
87
+ end
88
+
89
+ describe "#respond_to?" do
90
+ it "returns true for all attribute methods" do
91
+ browser.dt(:index, 0).should respond_to(:id)
92
+ browser.dt(:index, 0).should respond_to(:class_name)
93
+ browser.dt(:index, 0).should respond_to(:style)
94
+ browser.dt(:index, 0).should respond_to(:text)
95
+ browser.dt(:index, 0).should respond_to(:title)
96
+ end
97
+ end
98
+
99
+ # Manipulation methods
100
+ describe "#click" do
101
+ it "fires events when clicked" do
102
+ browser.dt(:id, 'education').text.should_not == 'changed'
103
+ browser.dt(:id, 'education').click
104
+ browser.dt(:id, 'education').text.should == 'changed'
105
+ end
106
+
107
+ it "raises UnknownObjectException if the element does not exist" do
108
+ lambda { browser.dt(:id, "no_such_id").click }.should raise_error(UnknownObjectException)
109
+ lambda { browser.dt(:title, "no_such_title").click }.should raise_error(UnknownObjectException)
110
+ lambda { browser.dt(:index, 1337).click }.should raise_error(UnknownObjectException)
111
+ lambda { browser.dt(:xpath, "//dt[@id='no_such_id']").click }.should raise_error(UnknownObjectException)
112
+ end
113
+ end
114
+
115
+ describe "#html" do
116
+ it "returns the HTML of the element" do
117
+ html = browser.dt(:id, 'name').html
118
+ html.should =~ %r[<div>.*Name.*</div>]mi
119
+ html.should_not include('</body>')
120
+ end
121
+ end
122
+
123
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe "Dts" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/definition_lists.html")
8
+ end
9
+
10
+ describe "#length" do
11
+ it "returns the number of dts" do
12
+ browser.dts.length.should == 11
13
+ end
14
+ end
15
+
16
+ describe "#[]" do
17
+ it "returns the dt at the given index" do
18
+ browser.dts[0].id.should == "experience"
19
+ end
20
+ end
21
+
22
+ describe "#each" do
23
+ it "iterates through dts correctly" do
24
+ browser.dts.each_with_index do |d, index|
25
+ d.id.should == browser.dt(:index, index).id
26
+ d.class_name.should == browser.dt(:index, index).class_name
27
+ end
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,89 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe "Element" do
5
+
6
+ Element = BaseElement if WatirSpec.implementation = :webdriver # hack
7
+
8
+ before :each do
9
+ browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
10
+ end
11
+
12
+ describe ".new" do
13
+ it "finds elements matching the conditions when given a hash of :how => 'what' arguments" do
14
+ browser.checkbox(:name => 'new_user_interests', :title => 'Dancing is fun!').value.should == 'dancing'
15
+ browser.text_field(:class_name => 'name', :index => 1).id.should == 'new_user_last_name'
16
+ end
17
+
18
+ it "raises UnknownObjectException with a sane error message when given a hash of :how => 'what' arguments (non-existing object)" do
19
+ conditions = {:index => 100, :name => "foo"}
20
+ lambda { browser.text_field(conditions).id }.should raise_error(UnknownObjectException)
21
+ end
22
+
23
+ bug "WTR-351", :watir do
24
+ it "raises ArgumentError if given the wrong number of arguments" do
25
+ container = mock("container", :null_object => true)
26
+ lambda { Element.new(container, 1,2,3,4) }.should raise_error(ArgumentError)
27
+ lambda { Element.new(container, "foo") }.should raise_error(ArgumentError)
28
+ end
29
+ end
30
+ end
31
+
32
+ describe "#focus" do
33
+ bug "http://code.google.com/p/selenium/issues/detail?id=157", :webdriver do
34
+ it "fires the onfocus event for the given element" do
35
+ tf = browser.text_field(:id, "new_user_occupation")
36
+ tf.value.should == "Developer"
37
+ tf.focus
38
+ browser.div(:id, "onfocus_test").text.should == "changed by onfocus event"
39
+ end
40
+ end
41
+ end
42
+
43
+ describe "#fire_event" do
44
+ it "should fire the given event" do
45
+ browser.div(:id, "onfocus_test").text.should be_empty
46
+ browser.text_field(:id, "new_user_occupation").fire_event('onfocus')
47
+ browser.div(:id, "onfocus_test").text.should == "changed by onfocus event"
48
+ end
49
+ end
50
+
51
+ describe "#parent" do
52
+ bug "WTR-352", :watir do
53
+ it "gets the parent of this element" do
54
+ browser.text_field(:id, "new_user_email").parent.should be_instance_of(FieldSet)
55
+ end
56
+ end
57
+ end
58
+
59
+ describe "#visible?" do
60
+ it "returns true if the element is visible" do
61
+ browser.text_field(:id, "new_user_email").should be_visible
62
+ end
63
+
64
+ it "returns false if the element is input element where type == 'hidden'" do
65
+ browser.text_field(:id, "new_user_interests_dolls").should_not be_visible
66
+ end
67
+
68
+ bug "WTR-336", :watir do
69
+ it "returns false if the element has style='display: none;'" do
70
+ browser.div(:id, 'changed_language').should_not be_visible
71
+ end
72
+ end
73
+
74
+ it "returns false if the element has style='visibility: hidden;" do
75
+ browser.div(:id, 'wants_newsletter').should_not be_visible
76
+ end
77
+
78
+ it "returns false if one of the parent elements is hidden" do
79
+ browser.div(:id, 'hidden_parent').should_not be_visible
80
+ end
81
+ end
82
+
83
+ describe "#exist?" do
84
+ it "doesn't raise when called on nested elements" do
85
+ browser.div(:id, 'no_such_div').link(:id, 'no_such_id').should_not exist
86
+ end
87
+ end
88
+
89
+ end
@@ -0,0 +1,97 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe "Em" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
8
+ end
9
+
10
+ # Exists method
11
+ describe "#exists?" do
12
+ it "returns true if the element exists" do
13
+ browser.em(:id, "important-id").should exist
14
+ browser.em(:class, "important-class").should exist
15
+ browser.em(:xpath, "//em[@id='important-id']").should exist
16
+ browser.em(:index, 0).should exist
17
+ end
18
+
19
+ it "returns false if the element does not exist" do
20
+ browser.em(:id, "no_such_id").should_not exist
21
+ end
22
+
23
+ it "raises TypeError when 'what' argument is invalid" do
24
+ lambda { browser.em(:id, 3.14).exists? }.should raise_error(TypeError)
25
+ end
26
+
27
+ it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
28
+ lambda { browser.em(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
29
+ end
30
+ end
31
+
32
+ # Attribute methods
33
+ describe "#class_name" do
34
+ it "returns the class attribute if the element exists" do
35
+ browser.em(:id, "important-id").class_name.should == "important-class"
36
+ end
37
+
38
+ it "raises UnknownObjectException if the element does not exist" do
39
+ lambda { browser.em(:id, "no_such_id").class_name }.should raise_error(UnknownObjectException)
40
+ lambda { browser.em(:title, "no_such_title").class_name }.should raise_error(UnknownObjectException)
41
+ lambda { browser.em(:index, 1337).class_name }.should raise_error(UnknownObjectException)
42
+ lambda { browser.em(:xpath, "//em[@id='no_such_id']").class_name }.should raise_error(UnknownObjectException)
43
+ end
44
+ end
45
+
46
+ describe "#id" do
47
+ it "returns the id attribute if the element exists" do
48
+ browser.em(:class, 'important-class').id.should == "important-id"
49
+ end
50
+
51
+ it "raises UnknownObjectException if the element does not exist" do
52
+ lambda {browser.em(:id, "no_such_id").id }.should raise_error(UnknownObjectException)
53
+ lambda {browser.em(:title, "no_such_id").id }.should raise_error(UnknownObjectException)
54
+ lambda {browser.em(:index, 1337).id }.should raise_error(UnknownObjectException)
55
+ end
56
+ end
57
+
58
+ describe "#title" do
59
+ it "returns the title of the element" do
60
+ browser.em(:class, "important-class").title.should == "ergo cogito"
61
+ end
62
+ end
63
+
64
+ describe "#text" do
65
+ it "returns the text of the element" do
66
+ browser.em(:id, "important-id").text.should == "ergo cogito"
67
+ end
68
+
69
+ it "raises UnknownObjectException if the element does not exist" do
70
+ lambda { browser.em(:id, "no_such_id").text }.should raise_error(UnknownObjectException)
71
+ lambda { browser.em(:title, "no_such_title").text }.should raise_error(UnknownObjectException)
72
+ lambda { browser.em(:index, 1337).text }.should raise_error(UnknownObjectException)
73
+ lambda { browser.em(:xpath, "//em[@id='no_such_id']").text }.should raise_error(UnknownObjectException)
74
+ end
75
+ end
76
+
77
+ describe "#respond_to?" do
78
+ it "returns true for all attribute methods" do
79
+ browser.em(:index, 0).should respond_to(:id)
80
+ browser.em(:index, 0).should respond_to(:class_name)
81
+ browser.em(:index, 0).should respond_to(:style)
82
+ browser.em(:index, 0).should respond_to(:text)
83
+ browser.em(:index, 0).should respond_to(:title)
84
+ end
85
+ end
86
+
87
+ # Manipulation methods
88
+ describe "#click" do
89
+ it "raises UnknownObjectException if the element does not exist" do
90
+ lambda { browser.em(:id, "no_such_id").click }.should raise_error(UnknownObjectException)
91
+ lambda { browser.em(:title, "no_such_title").click }.should raise_error(UnknownObjectException)
92
+ lambda { browser.em(:index, 1337).click }.should raise_error(UnknownObjectException)
93
+ lambda { browser.em(:xpath, "//em[@id='no_such_id']").click }.should raise_error(UnknownObjectException)
94
+ end
95
+ end
96
+
97
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe "Ems" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
8
+ end
9
+
10
+ describe "#length" do
11
+ it "returns the number of ems" do
12
+ browser.ems.length.should == 1
13
+ end
14
+ end
15
+
16
+ describe "#[]" do
17
+ it "returns the em at the given index" do
18
+ browser.ems[0].id.should == "important-id"
19
+ end
20
+ end
21
+
22
+ describe "#each" do
23
+ it "iterates through ems correctly" do
24
+ browser.ems.each_with_index do |e, index|
25
+ e.text.should == browser.em(:index, index).text
26
+ e.id.should == browser.em(:index, index).id
27
+ e.class_name.should == browser.em(:index, index).class_name
28
+ end
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,119 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe "FileField" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
8
+ end
9
+
10
+ describe "#exist?" do
11
+ it "returns true if the file field exists" do
12
+ browser.file_field(:id, 'new_user_portrait').should exist
13
+ browser.file_field(:id, /new_user_portrait/).should exist
14
+ browser.file_field(:name, 'new_user_portrait').should exist
15
+ browser.file_field(:name, /new_user_portrait/).should exist
16
+ browser.file_field(:class, 'portrait').should exist
17
+ browser.file_field(:class, /portrait/).should exist
18
+ browser.file_field(:index, 0).should exist
19
+ browser.file_field(:xpath, "//input[@id='new_user_portrait']").should exist
20
+ end
21
+
22
+ it "returns false if the file field doesn't exist" do
23
+ browser.file_field(:id, 'no_such_id').should_not exist
24
+ browser.file_field(:id, /no_such_id/).should_not exist
25
+ browser.file_field(:name, 'no_such_name').should_not exist
26
+ browser.file_field(:name, /no_such_name/).should_not exist
27
+ browser.file_field(:class, 'no_such_class').should_not exist
28
+ browser.file_field(:class, /no_such_class/).should_not exist
29
+ browser.file_field(:index, 1337).should_not exist
30
+ browser.file_field(:xpath, "//input[@id='no_such_id']").should_not exist
31
+ end
32
+
33
+ it "raises TypeError when 'what' argument is invalid" do
34
+ lambda { browser.file_field(:id, 3.14).exists? }.should raise_error(TypeError)
35
+ end
36
+
37
+ it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
38
+ lambda { browser.file_field(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
39
+ end
40
+ end
41
+
42
+ # Attribute methods
43
+
44
+ describe "#class_name" do
45
+ it "returns the class attribute if the text field exists" do
46
+ browser.file_field(:index, 0).class_name.should == "portrait"
47
+ end
48
+
49
+ it "raises UnknownObjectException if the text field doesn't exist" do
50
+ lambda { browser.file_field(:index, 1337).class_name }.should raise_error(UnknownObjectException)
51
+ end
52
+ end
53
+
54
+ describe "#id" do
55
+ it "returns the id attribute if the text field exists" do
56
+ browser.file_field(:index, 0).id.should == "new_user_portrait"
57
+ end
58
+
59
+ it "raises UnknownObjectException if the text field doesn't exist" do
60
+ lambda { browser.file_field(:index, 1337).id }.should raise_error(UnknownObjectException)
61
+ end
62
+ end
63
+
64
+ describe "#name" do
65
+ it "returns the name attribute if the text field exists" do
66
+ browser.file_field(:index, 0).name.should == "new_user_portrait"
67
+ end
68
+
69
+ it "raises UnknownObjectException if the text field doesn't exist" do
70
+ lambda { browser.file_field(:index, 1337).name }.should raise_error(UnknownObjectException)
71
+ end
72
+ end
73
+
74
+ describe "#title" do
75
+ it "returns the title attribute if the text field exists" do
76
+ browser.file_field(:id, "new_user_portrait").title.should == "Smile!"
77
+ end
78
+ end
79
+
80
+ describe "#type" do
81
+ it "returns the type attribute if the text field exists" do
82
+ browser.file_field(:index, 0).type.should == "file"
83
+ end
84
+
85
+ it "raises UnknownObjectException if the text field doesn't exist" do
86
+ lambda { browser.file_field(:index, 1337).type }.should raise_error(UnknownObjectException)
87
+ end
88
+ end
89
+
90
+ describe "#respond_to?" do
91
+ it "returns true for all attribute methods" do
92
+ browser.file_field(:index, 0).should respond_to(:class_name)
93
+ browser.file_field(:index, 0).should respond_to(:id)
94
+ browser.file_field(:index, 0).should respond_to(:name)
95
+ browser.file_field(:index, 0).should respond_to(:title)
96
+ browser.file_field(:index, 0).should respond_to(:type)
97
+ browser.file_field(:index, 0).should respond_to(:value)
98
+ end
99
+ end
100
+
101
+ # Manipulation methods
102
+
103
+ describe "#set" do
104
+ bug "WTR-336", :watir do
105
+ it "is able to set a file path in the field and click the upload button and fire the onchange event" do
106
+ browser.goto("#{WatirSpec.host}/forms_with_input_elements.html")
107
+
108
+ path = File.expand_path(__FILE__)
109
+
110
+ browser.file_field(:name, "new_user_portrait").set path
111
+ browser.file_field(:name, "new_user_portrait").value.should == path
112
+ messages.first.should include(File.basename(path)) # only some browser will return the full path
113
+ browser.button(:name, "new_user_submit").click
114
+ end
115
+ end
116
+
117
+ end
118
+
119
+ end