watir-webdriver 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. data/README.rdoc +9 -1
  2. data/Rakefile +2 -1
  3. data/VERSION +1 -1
  4. data/lib/watir-webdriver.rb +6 -7
  5. data/lib/watir-webdriver/attribute_helper.rb +17 -10
  6. data/lib/watir-webdriver/browser.rb +1 -1
  7. data/lib/watir-webdriver/cell_container.rb +19 -0
  8. data/lib/watir-webdriver/container.rb +8 -0
  9. data/lib/watir-webdriver/element_collection.rb +2 -2
  10. data/lib/watir-webdriver/elements/button.rb +3 -2
  11. data/lib/watir-webdriver/elements/element.rb +41 -1
  12. data/lib/watir-webdriver/elements/generated.rb +3 -3
  13. data/lib/watir-webdriver/elements/input.rb +0 -52
  14. data/lib/watir-webdriver/elements/select.rb +0 -1
  15. data/lib/watir-webdriver/elements/table.rb +26 -4
  16. data/lib/watir-webdriver/elements/table_cell.rb +36 -0
  17. data/lib/watir-webdriver/elements/table_row.rb +23 -14
  18. data/lib/watir-webdriver/elements/table_section.rb +9 -0
  19. data/lib/watir-webdriver/extensions/alerts.rb +69 -0
  20. data/lib/watir-webdriver/extensions/performance.rb +54 -0
  21. data/lib/watir-webdriver/locators/button_locator.rb +3 -5
  22. data/lib/watir-webdriver/locators/{table_row_locator.rb → child_cell_locator.rb} +11 -6
  23. data/lib/watir-webdriver/locators/child_row_locator.rb +37 -0
  24. data/lib/watir-webdriver/locators/element_locator.rb +24 -14
  25. data/lib/watir-webdriver/row_container.rb +19 -0
  26. data/lib/watir-webdriver/window_switching.rb +37 -10
  27. data/spec/alert_spec.rb +49 -0
  28. data/spec/element_locator_spec.rb +15 -16
  29. data/spec/element_spec.rb +0 -32
  30. data/spec/html/alerts.html +11 -0
  31. data/spec/input_spec.rb +8 -46
  32. data/spec/locator_spec_helper.rb +19 -5
  33. data/spec/spec_helper.rb +3 -0
  34. data/spec/watirspec/areas_spec.rb +8 -0
  35. data/spec/watirspec/browser_spec.rb +4 -4
  36. data/spec/watirspec/button_spec.rb +3 -4
  37. data/spec/watirspec/buttons_spec.rb +8 -0
  38. data/spec/watirspec/checkboxes_spec.rb +8 -0
  39. data/spec/watirspec/dds_spec.rb +8 -0
  40. data/spec/watirspec/dels_spec.rb +8 -0
  41. data/spec/watirspec/divs_spec.rb +8 -0
  42. data/spec/watirspec/dls_spec.rb +8 -0
  43. data/spec/watirspec/dts_spec.rb +8 -0
  44. data/spec/watirspec/element_spec.rb +71 -2
  45. data/spec/watirspec/ems_spec.rb +8 -0
  46. data/spec/watirspec/filefield_spec.rb +16 -11
  47. data/spec/watirspec/filefields_spec.rb +8 -0
  48. data/spec/watirspec/font_spec.rb +21 -19
  49. data/spec/watirspec/form_spec.rb +5 -3
  50. data/spec/watirspec/forms_spec.rb +11 -5
  51. data/spec/watirspec/frames_spec.rb +8 -0
  52. data/spec/watirspec/hiddens_spec.rb +8 -0
  53. data/spec/watirspec/hns_spec.rb +8 -0
  54. data/spec/watirspec/images_spec.rb +8 -0
  55. data/spec/watirspec/inses_spec.rb +8 -0
  56. data/spec/watirspec/label_spec.rb +2 -0
  57. data/spec/watirspec/labels_spec.rb +8 -0
  58. data/spec/watirspec/lib/server.rb +19 -1
  59. data/spec/watirspec/lib/spec_helper.rb +1 -1
  60. data/spec/watirspec/links_spec.rb +8 -0
  61. data/spec/watirspec/lis_spec.rb +8 -0
  62. data/spec/watirspec/maps_spec.rb +8 -0
  63. data/spec/watirspec/metas_spec.rb +8 -0
  64. data/spec/watirspec/ols_spec.rb +8 -0
  65. data/spec/watirspec/pres_spec.rb +8 -0
  66. data/spec/watirspec/ps_spec.rb +8 -0
  67. data/spec/watirspec/radios_spec.rb +8 -0
  68. data/spec/watirspec/select_list_spec.rb +6 -6
  69. data/spec/watirspec/select_lists_spec.rb +8 -0
  70. data/spec/watirspec/spans_spec.rb +8 -0
  71. data/spec/watirspec/strongs_spec.rb +8 -0
  72. data/spec/watirspec/table_nesting_spec.rb +50 -0
  73. data/spec/watirspec/table_spec.rb +62 -102
  74. data/spec/watirspec/tables_spec.rb +8 -0
  75. data/spec/watirspec/{table_body_spec.rb → tbody_spec.rb} +21 -31
  76. data/spec/watirspec/{table_bodies_spec.rb → tbodys_spec.rb} +8 -0
  77. data/spec/watirspec/td_spec.rb +72 -0
  78. data/spec/watirspec/{table_cells_spec.rb → tds_spec.rb} +18 -25
  79. data/spec/watirspec/text_fields_spec.rb +8 -0
  80. data/spec/watirspec/{table_footer_spec.rb → tfoot_spec.rb} +21 -28
  81. data/spec/watirspec/{table_footers_spec.rb → tfoots_spec.rb} +8 -0
  82. data/spec/watirspec/{table_header_spec.rb → thead_spec.rb} +21 -29
  83. data/spec/watirspec/{table_headers_spec.rb → theads_spec.rb} +8 -0
  84. data/spec/watirspec/tr_spec.rb +88 -0
  85. data/spec/watirspec/trs_spec.rb +68 -0
  86. data/spec/watirspec/uls_spec.rb +8 -0
  87. data/spec/watirspec/window_switching_spec.rb +165 -0
  88. data/support/html5.html +884 -422
  89. data/watir-webdriver.gemspec +91 -85
  90. metadata +159 -161
  91. data/Gemfile.lock +0 -48
  92. data/spec/html/closeable.html +0 -13
  93. data/spec/html/data_attributes.html +0 -9
  94. data/spec/html/window_switching.html +0 -12
  95. data/spec/watirspec/table_cell_spec.rb +0 -74
  96. data/spec/watirspec/table_row_spec.rb +0 -99
  97. data/spec/watirspec/table_rows_spec.rb +0 -60
  98. data/spec/window_switching_spec.rb +0 -116
@@ -7,6 +7,14 @@ describe "Dts" do
7
7
  browser.goto(WatirSpec.files + "/definition_lists.html")
8
8
  end
9
9
 
10
+ bug "http://github.com/jarib/celerity/issues#issue/25", :celerity do
11
+ describe "with selectors" do
12
+ it "returns the matching elements" do
13
+ browser.dts(:class => "current-industry").to_a.should == [browser.dt(:class => "current-industry")]
14
+ end
15
+ end
16
+ end
17
+
10
18
  describe "#length" do
11
19
  it "returns the number of dts" do
12
20
  browser.dts.length.should == 11
@@ -24,6 +24,69 @@ describe "Element" do
24
24
  end
25
25
  end
26
26
 
27
+ describe "#== and #eql?" do
28
+ before { browser.goto(WatirSpec.files + "/definition_lists.html") }
29
+
30
+ it "returns true if the two elements point to the same DOM element" do
31
+ a = browser.dl(:id => "experience-list")
32
+ b = browser.dl
33
+
34
+ a.should == b
35
+ a.should eql(b)
36
+ end
37
+
38
+ it "returns false if the two elements are not the same" do
39
+ a = browser.dls[0]
40
+ b = browser.dls[1]
41
+
42
+ a.should_not == b
43
+ a.should_not eql(b)
44
+ end
45
+
46
+ it "returns false if the other object is not an Element" do
47
+ browser.dl.should_not == 1
48
+ end
49
+ end
50
+
51
+ describe "data-* attributes" do
52
+ before { browser.goto("file://" + File.expand_path("html/data_attributes.html", File.dirname(__FILE__))) }
53
+
54
+ bug "http://github.com/jarib/celerity/issues#issue/27", :celerity do
55
+ it "finds elements by a data-* attribute" do
56
+ browser.p(:data_type => "ruby-library").should exist
57
+ end
58
+
59
+ it "returns the value of a data-* attribute" do
60
+ browser.p.data_type.should == "ruby-library"
61
+ end
62
+ end
63
+ end
64
+
65
+ describe "finding with unknown tag name" do
66
+ it "finds an element by xpath" do
67
+ browser.element(:xpath => "//*[@for='new_user_first_name']").should exist
68
+ end
69
+
70
+ it "finds an element by arbitrary attribute" do
71
+ browser.element(:id => "new_user").should exist
72
+ end
73
+
74
+ it "finds several elements by xpath" do
75
+ browser.elements(:xpath => "//a").length.should == 1
76
+ end
77
+
78
+ it "finds finds several elements by arbitrary attribute" do
79
+ browser.elements(:name => /^new_user/).length.should == 30
80
+ end
81
+ end
82
+
83
+ describe "#to_subtype" do
84
+ it "returns a more precise subtype of Element" do
85
+ el = browser.element(:xpath => "//input[@type='radio']").to_subtype
86
+ el.should be_kind_of(Watir::Radio)
87
+ end
88
+ end
89
+
27
90
  describe "#focus" do
28
91
  bug "http://github.com/jarib/watir-webdriver/issues/issue/20", [:webdriver, :firefox] do
29
92
  it "fires the onfocus event for the given element" do
@@ -44,8 +107,10 @@ describe "Element" do
44
107
  end
45
108
 
46
109
  describe "#parent" do
47
- it "gets the parent of this element" do
48
- browser.text_field(:id, "new_user_email").parent.should be_instance_of(FieldSet)
110
+ bug "http://github.com/jarib/celerity/issues#issue/28", :celerity do
111
+ it "gets the parent of this element" do
112
+ browser.text_field(:id, "new_user_email").parent.should be_instance_of(FieldSet)
113
+ end
49
114
  end
50
115
  end
51
116
 
@@ -75,6 +140,10 @@ describe "Element" do
75
140
  it "doesn't raise when called on nested elements" do
76
141
  browser.div(:id, 'no_such_div').link(:id, 'no_such_id').should_not exist
77
142
  end
143
+
144
+ it "raises ArgumentError error if selector hash with :xpath has multiple entries" do
145
+ lambda { browser.div(:xpath => "//div", :class => "foo").exists? }.should raise_error(ArgumentError)
146
+ end
78
147
  end
79
148
 
80
149
  end
@@ -7,6 +7,14 @@ describe "Ems" do
7
7
  browser.goto(WatirSpec.files + "/non_control_elements.html")
8
8
  end
9
9
 
10
+ bug "http://github.com/jarib/celerity/issues#issue/25", :celerity do
11
+ describe "with selectors" do
12
+ it "returns the matching elements" do
13
+ browser.ems(:class => "important-class").to_a.should == [browser.em(:class => "important-class")]
14
+ end
15
+ end
16
+ end
17
+
10
18
  describe "#length" do
11
19
  it "returns the number of ems" do
12
20
  browser.ems.length.should == 1
@@ -108,11 +108,14 @@ describe "FileField" do
108
108
  it "is able to set a file path in the field and click the upload button and fire the onchange event" do
109
109
  browser.goto("#{WatirSpec.host}/forms_with_input_elements.html")
110
110
 
111
- path = File.expand_path(__FILE__)
111
+ path = File.expand_path(__FILE__)
112
+ element = browser.file_field(:name, "new_user_portrait")
112
113
 
113
- browser.file_field(:name, "new_user_portrait").set path
114
- browser.file_field(:name, "new_user_portrait").value.should include(File.basename(path)) # only some browser will return the full path
114
+ element.set path
115
+
116
+ element.value.should include(File.basename(path)) # only some browser will return the full path
115
117
  messages.first.should include(File.basename(path))
118
+
116
119
  browser.button(:name, "new_user_submit").click
117
120
  end
118
121
 
@@ -128,17 +131,19 @@ describe "FileField" do
128
131
  it "is able to set a file path in the field and click the upload button and fire the onchange event" do
129
132
  browser.goto("#{WatirSpec.host}/forms_with_input_elements.html")
130
133
 
131
- path = File.expand_path(__FILE__)
134
+ path = File.expand_path(__FILE__)
135
+ element = browser.file_field(:name, "new_user_portrait")
132
136
 
133
- browser.file_field(:name, "new_user_portrait").value = path
134
- browser.file_field(:name, "new_user_portrait").value.should include(File.basename(path)) # only some browser will return the full path
135
- messages.first.should include(File.basename(path))
136
- browser.button(:name, "new_user_submit").click
137
+ element.value = path
138
+ element.value.should include(File.basename(path)) # only some browser will return the full path
137
139
  end
138
140
 
139
- it "does not raise an error if the file does not exist" do
140
- browser.file_field.value = '/tmp/unlikely-to-exist'
141
- browser.file_field.value.should == '/tmp/unlikely-to-exist'
141
+
142
+ not_compliant_on [:webdriver, :ie] do
143
+ it "does not raise an error if the file does not exist" do
144
+ browser.file_field.value = '/tmp/unlikely-to-exist'
145
+ browser.file_field.value.should == '/tmp/unlikely-to-exist'
146
+ end
142
147
  end
143
148
 
144
149
  it "does not alter its argument" do
@@ -7,6 +7,14 @@ describe "FileFields" do
7
7
  browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
8
8
  end
9
9
 
10
+ bug "http://github.com/jarib/celerity/issues#issue/25", :celerity do
11
+ describe "with selectors" do
12
+ it "returns the matching elements" do
13
+ browser.file_fields(:class => "portrait").to_a.should == [browser.file_field(:class => "portrait")]
14
+ end
15
+ end
16
+ end
17
+
10
18
  describe "#length" do
11
19
  it "returns the correct number of file fields" do
12
20
  browser.file_fields.length.should == 2
@@ -6,25 +6,27 @@ describe "Font" do
6
6
  before :each do
7
7
  browser.goto(WatirSpec.files + "/font.html")
8
8
  end
9
-
10
- it "finds the font element" do
11
- browser.font(:index, 0).should exist
12
- end
13
-
14
- it "knows about the color attribute" do
15
- browser.font(:index, 0).color.should == "#ff00ff"
16
- end
17
-
18
- it "knows about the face attribute" do
19
- browser.font(:index, 0).face.should == "Helvetica"
20
- end
21
-
22
- it "knows about the size attribute" do
23
- browser.font(:index, 0).size.should == "12"
24
- end
25
-
26
- it "finds all font elements" do
27
- browser.fonts.size.should == 1
9
+
10
+ bug "http://github.com/jarib/celerity/issues#issue/29", :celerity do
11
+ it "finds the font element" do
12
+ browser.font(:index, 0).should exist
13
+ end
14
+
15
+ it "knows about the color attribute" do
16
+ browser.font(:index, 0).color.should == "#ff00ff"
17
+ end
18
+
19
+ it "knows about the face attribute" do
20
+ browser.font(:index, 0).face.should == "Helvetica"
21
+ end
22
+
23
+ it "knows about the size attribute" do
24
+ browser.font(:index, 0).size.should == "12"
25
+ end
26
+
27
+ it "finds all font elements" do
28
+ browser.fonts.size.should == 1
29
+ end
28
30
  end
29
31
 
30
32
  end
@@ -52,9 +52,11 @@ describe "Form" do
52
52
  end
53
53
 
54
54
  describe "#submit" do
55
- it "submits the form" do
56
- browser.form(:id, "delete_user").submit
57
- browser.text.should include("Semantic table")
55
+ not_compliant_on :celerity do
56
+ it "submits the form" do
57
+ browser.form(:id, "delete_user").submit
58
+ browser.text.should include("Semantic table")
59
+ end
58
60
  end
59
61
  end
60
62
 
@@ -7,6 +7,14 @@ describe "Forms" do
7
7
  browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
8
8
  end
9
9
 
10
+ bug "http://github.com/jarib/celerity/issues#issue/25", :celerity do
11
+ describe "with selectors" do
12
+ it "returns the matching elements" do
13
+ browser.forms(:method => "post").to_a.should == [browser.form(:method => "post")]
14
+ end
15
+ end
16
+ end
17
+
10
18
  describe "#length" do
11
19
  it "returns the number of forms in the container" do
12
20
  browser.forms.length.should == 2
@@ -14,11 +22,9 @@ describe "Forms" do
14
22
  end
15
23
 
16
24
  describe "#[]n" do
17
- bug "http://github.com/jarib/watir-webdriver/issues/issue/27", [:webdriver, :firefox], [:webdriver, :ie] do
18
- it "provides access to the nth form" do
19
- browser.forms[0].action.should == 'post_to_me'
20
- browser.forms[0].attribute_value('method').should == 'post'
21
- end
25
+ it "provides access to the nth form" do
26
+ browser.forms[0].action.should =~ /post_to_me$/ # varies between browsers
27
+ browser.forms[0].attribute_value('method').should == 'post'
22
28
  end
23
29
  end
24
30
 
@@ -9,6 +9,14 @@ bug "http://github.com/jarib/watir-webdriver/issues#issue/17", :webdriver do
9
9
  browser.goto(WatirSpec.files + "/frames.html")
10
10
  end
11
11
 
12
+ bug "http://github.com/jarib/celerity/issues#issue/25", :celerity do
13
+ describe "with selectors" do
14
+ it "returns the matching elements" do
15
+ browser.frames(:name => "frame1").to_a.should == [browser.frame(:class => "frame1")]
16
+ end
17
+ end
18
+ end
19
+
12
20
  describe "#length" do
13
21
  it "returns the correct number of frames" do
14
22
  browser.frames.length.should == 2
@@ -7,6 +7,14 @@ describe "Hiddens" do
7
7
  browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
8
8
  end
9
9
 
10
+ bug "http://github.com/jarib/celerity/issues#issue/25", :celerity do
11
+ describe "with selectors" do
12
+ it "returns the matching elements" do
13
+ browser.hiddens(:value => "dolls").to_a.should == [browser.hidden(:value => "dolls")]
14
+ end
15
+ end
16
+ end
17
+
10
18
  describe "#length" do
11
19
  it "returns the number of hiddens" do
12
20
  browser.hiddens.length.should == 1
@@ -6,6 +6,14 @@ describe "H1s", "H2s", "H3s", "H4s", "H5s", "H6s" do
6
6
  browser.goto(WatirSpec.files + "/non_control_elements.html")
7
7
  end
8
8
 
9
+ bug "http://github.com/jarib/celerity/issues#issue/25", :celerity do
10
+ describe "with selectors" do
11
+ it "returns the matching elements" do
12
+ browser.h1s(:class => "primary").to_a.should == [browser.h1(:class => "primary")]
13
+ end
14
+ end
15
+ end
16
+
9
17
  describe "#length" do
10
18
  it "returns the number of h1s" do
11
19
  browser.h2s.length.should == 9
@@ -7,6 +7,14 @@ describe "Images" do
7
7
  browser.goto(WatirSpec.files + "/images.html")
8
8
  end
9
9
 
10
+ bug "http://github.com/jarib/celerity/issues#issue/25", :celerity do
11
+ describe "with selectors" do
12
+ it "returns the matching elements" do
13
+ browser.images(:alt => "circle").to_a.should == [browser.image(:alt => "circle")]
14
+ end
15
+ end
16
+ end
17
+
10
18
  describe "#length" do
11
19
  it "returns the number of images" do
12
20
  browser.images.length.should == 9
@@ -7,6 +7,14 @@ describe "Inses" do
7
7
  browser.goto(WatirSpec.files + "/non_control_elements.html")
8
8
  end
9
9
 
10
+ bug "http://github.com/jarib/celerity/issues#issue/25", :celerity do
11
+ describe "with selectors" do
12
+ it "returns the matching elements" do
13
+ browser.inses(:class => "lead").to_a.should == [browser.ins(:class => "lead")]
14
+ end
15
+ end
16
+ end
17
+
10
18
  describe "#length" do
11
19
  it "returns the number of inses" do
12
20
  browser.inses.length.should == 5
@@ -12,6 +12,8 @@ describe "Label" do
12
12
  it "returns true if the element exists" do
13
13
  browser.label(:id, 'first_label').should exist
14
14
  browser.label(:id, /first_label/).should exist
15
+ browser.label(:for, "new_user_first_name").should exist
16
+ browser.label(:for, /new_user_first_name/).should exist
15
17
  browser.label(:text, 'First name').should exist
16
18
  browser.label(:text, /First name/).should exist
17
19
  browser.label(:index, 0).should exist
@@ -7,6 +7,14 @@ describe "Labels" do
7
7
  browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
8
8
  end
9
9
 
10
+ bug "http://github.com/jarib/celerity/issues#issue/25", :celerity do
11
+ describe "with selectors" do
12
+ it "returns the matching elements" do
13
+ browser.labels(:for => "new_user_first_name").to_a.should == [browser.label(:for => "new_user_first_name")]
14
+ end
15
+ end
16
+ end
17
+
10
18
  describe "#length" do
11
19
  it "returns the number of labels" do
12
20
  browser.labels.length.should == 26 # changed this from 25 - Jari
@@ -52,6 +52,16 @@ module WatirSpec
52
52
  false
53
53
  end
54
54
 
55
+ def find_free_port_above(int)
56
+ port = int
57
+
58
+ until free_port?(port)
59
+ port += 1
60
+ end
61
+
62
+ port
63
+ end
64
+
55
65
  def autorun
56
66
  @autorun ||= true
57
67
  end
@@ -63,6 +73,14 @@ module WatirSpec
63
73
  def running?
64
74
  defined?(@running) && @running
65
75
  end
76
+
77
+ def free_port?(port)
78
+ s = TCPServer.new(@host, port)
79
+ s.close
80
+ true
81
+ rescue SocketError, Errno::EADDRINUSE
82
+ false
83
+ end
66
84
  end # class << Server
67
85
 
68
86
  set :public, WatirSpec.html
@@ -70,7 +88,7 @@ module WatirSpec
70
88
  set :run, false
71
89
  set :environment, :production
72
90
  set :bind, "localhost" if WatirSpec.platform == :windows
73
- set :port, 2000
91
+ set :port, find_free_port_above(2000)
74
92
  set :server, %w[mongrel webrick]
75
93
 
76
94
  get '/' do
@@ -46,7 +46,7 @@ module WatirSpec
46
46
 
47
47
  def load_requires
48
48
  # load spec_helper from containing folder, if it exists
49
- hook = File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper.rb")
49
+ hook = File.expand_path("../../spec_helper.rb", File.dirname(__FILE__))
50
50
  raise(Errno::ENOENT, hook) unless File.exist?(hook)
51
51
 
52
52
  load hook
@@ -7,6 +7,14 @@ describe "Links" do
7
7
  browser.goto(WatirSpec.files + "/non_control_elements.html")
8
8
  end
9
9
 
10
+ bug "http://github.com/jarib/celerity/issues#issue/25", :celerity do
11
+ describe "with selectors" do
12
+ it "returns the matching elements" do
13
+ browser.links(:title => "link_title_2").to_a.should == [browser.link(:title => "link_title_2")]
14
+ end
15
+ end
16
+ end
17
+
10
18
  describe "#length" do
11
19
  it "returns the number of links" do
12
20
  browser.links.length.should == 4