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
@@ -0,0 +1,49 @@
1
+ require File.expand_path("watirspec/spec_helper", File.dirname(__FILE__))
2
+ require "watir-webdriver/extensions/alerts"
3
+
4
+ describe "AlertHelper" do
5
+ before do
6
+ browser.goto("file://" + File.expand_path("html/alerts.html", File.dirname(__FILE__)))
7
+ end
8
+
9
+ it "handles an alert()" do
10
+ returned = browser.alert do
11
+ browser.button(:id => "alert").click
12
+ end
13
+
14
+ returned.should == "ok"
15
+ end
16
+
17
+ it "handles a confirmed confirm()" do
18
+ returned = browser.confirm(true) do
19
+ browser.button(:id => "confirm").click
20
+ end
21
+
22
+ returned.should == "set the value"
23
+
24
+ browser.button(:id => "confirm").value.should == "true"
25
+ end
26
+
27
+ it "handles a cancelled confirm()" do
28
+ returned = browser.confirm(false) do
29
+ browser.button(:id => "confirm").click
30
+ end
31
+
32
+ returned.should == "set the value"
33
+
34
+ browser.button(:id => "confirm").value.should == "false"
35
+ end
36
+
37
+ it "handles a prompt()" do
38
+ returned = browser.prompt("my name") do
39
+ browser.button(:id => "prompt").click
40
+ end
41
+
42
+ returned.should == {
43
+ :message => "enter your name",
44
+ :default => "John Doe"
45
+ }
46
+
47
+ browser.button(:id => "prompt").value.should == "my name"
48
+ end
49
+ end
@@ -27,18 +27,18 @@ describe Watir::ElementLocator do
27
27
  end
28
28
 
29
29
  it "handles selector with tag name and multiple attributes" do
30
- expect_one :xpath, %r".//div\[(@class='foo' and @title='bar'|@title='bar' and @class='foo')\]"
30
+ expect_one :xpath, ".//div[@class='foo' and @title='bar']"
31
31
 
32
- locate_one :tag_name => "div",
33
- :class => "foo",
34
- :title => 'bar'
32
+ locate_one [:tag_name, "div",
33
+ :class , "foo",
34
+ :title , 'bar']
35
35
  end
36
36
 
37
37
  it "handles selector with no tag name and multiple attributes" do
38
- expect_one :xpath, %r".//\*\[(@class='foo' and @title='bar'|@title='bar' and @class='foo')\]"
38
+ expect_one :xpath, ".//*[@class='foo' and @title='bar']"
39
39
 
40
- locate_one :class => "foo",
41
- :title => "bar"
40
+ locate_one [:class, "foo",
41
+ :title, "bar"]
42
42
  end
43
43
  end
44
44
 
@@ -85,11 +85,11 @@ describe Watir::ElementLocator do
85
85
  it "uses the corresponding <label>'s @for attribute when locating by label" do
86
86
  expect_one :xpath, ".//input[@type='text' and @id=//label[normalize-space()='foo']/@for]"
87
87
 
88
- selector = {
89
- :tag_name => "input",
90
- :type => "text",
91
- :label => "foo"
92
- }
88
+ selector = [
89
+ :tag_name, "input",
90
+ :type , "text",
91
+ :label , "foo"
92
+ ]
93
93
 
94
94
  locate_one selector, Watir::Input.attributes
95
95
  end
@@ -203,7 +203,6 @@ describe Watir::ElementLocator do
203
203
 
204
204
  selector = {
205
205
  :tag_name => "input",
206
- :type => "radio",
207
206
  :xpath => "//div"
208
207
  }
209
208
 
@@ -255,9 +254,9 @@ describe Watir::ElementLocator do
255
254
  it "handles selector with tag name and multiple attributes" do
256
255
  expect_all :xpath, ".//div[@class='foo' and @title='bar']"
257
256
 
258
- locate_all :tag_name => "div",
259
- :class => "foo",
260
- :title => 'bar'
257
+ locate_all [:tag_name, "div",
258
+ :class , "foo",
259
+ :title , 'bar']
261
260
  end
262
261
  end
263
262
 
@@ -11,36 +11,4 @@ describe Watir::Element do
11
11
  end
12
12
  end
13
13
 
14
- describe "#== and #eql?" do
15
- before { browser.goto(WatirSpec.files + "/definition_lists.html") }
16
-
17
- it "returns true if the two elements point to the same DOM element" do
18
- a = browser.dl(:id => "experience-list")
19
- b = browser.dl
20
-
21
- a.should == b
22
- a.should eql(b)
23
- end
24
-
25
- it "returns false if the two elements are not the same" do
26
- a = browser.dls[0]
27
- b = browser.dls[1]
28
-
29
- a.should_not == b
30
- a.should_not eql(b)
31
- end
32
- end
33
-
34
- describe "data-* attributes" do
35
- before { browser.goto("file://" + File.expand_path("html/data_attributes.html", File.dirname(__FILE__))) }
36
-
37
- it "finds elements by a data-* attribute" do
38
- browser.p(:data_type => "ruby-library").should exist
39
- end
40
-
41
- it "returns the value of a data-* attribute" do
42
- browser.p.data_type.should == "ruby-library"
43
- end
44
- end
45
-
46
14
  end
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Alerts</title>
5
+ </head>
6
+ <body>
7
+ <input id=alert type=button onclick="alert('ok')" value=Alert>
8
+ <input id=confirm type=button onclick="this.value = confirm('set the value')" value=Confirm>
9
+ <input id=prompt type=button onclick='this.value = prompt("enter your name", "John Doe")' value=Prompt>
10
+ </body>
11
+ </html>
@@ -6,72 +6,34 @@ describe Watir::Input do
6
6
  browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
7
7
  end
8
8
 
9
- describe "#to_checkbox" do
9
+ describe "#to_subtype" do
10
10
  it "returns a CheckBox instance" do
11
- e = browser.input(:xpath => "//input[@type='checkbox']").to_checkbox
11
+ e = browser.input(:xpath => "//input[@type='checkbox']").to_subtype
12
12
  e.should be_kind_of(Watir::CheckBox)
13
13
  end
14
14
 
15
- it "raises an error if the element is not a checkbox" do
16
- lambda {
17
- browser.input(:xpath => "//input[@type='text']").to_checkbox
18
- }.should raise_error(TypeError)
19
- end
20
- end
21
-
22
- describe "#to_radio" do
23
15
  it "returns a Radio instance" do
24
- e = browser.input(:xpath => "//input[@type='radio']").to_radio
16
+ e = browser.input(:xpath => "//input[@type='radio']").to_subtype
25
17
  e.should be_kind_of(Watir::Radio)
26
18
  end
27
19
 
28
- it "raises an error if the element is not a radio button" do
29
- lambda {
30
- browser.input(:xpath => "//input[@type='text']").to_radio
31
- }.should raise_error(TypeError)
32
- end
33
- end
34
-
35
- describe "#to_button" do
36
20
  it "returns a Button instance" do
37
21
  es = [
38
- browser.input(:xpath => "//input[@type='button']").to_button,
39
- browser.input(:xpath => "//input[@type='submit']").to_button
22
+ browser.input(:xpath => "//input[@type='button']").to_subtype,
23
+ browser.input(:xpath => "//input[@type='submit']").to_subtype
40
24
  ]
41
25
 
42
- es.each { |e| e.should be_kind_of(Watir::Button) }
43
- end
44
-
45
- it "raises an error if the element is not a button" do
46
- lambda {
47
- browser.input(:xpath => "//input[@type='text']").to_button
48
- }.should raise_error(TypeError)
26
+ es.all? { |e| e.should be_kind_of(Watir::Button) }
49
27
  end
50
- end
51
28
 
52
- describe "#to_text_field" do
53
29
  it "returns a TextField instance" do
54
- e = browser.input(:xpath => "//input[@type='text']").to_text_field
30
+ e = browser.input(:xpath => "//input[@type='text']").to_subtype
55
31
  e.should be_kind_of(Watir::TextField)
56
32
  end
57
33
 
58
- it "raises an error if the element is not a text field" do
59
- lambda {
60
- browser.input(:xpath => "//input[@type='radio']").to_text_field
61
- }.should raise_error(TypeError)
62
- end
63
- end
64
-
65
- describe "#to_file_field" do
66
34
  it "returns a TextField instance" do
67
- e = browser.input(:xpath => "//input[@type='file']").to_file_field
35
+ e = browser.input(:xpath => "//input[@type='file']").to_subtype
68
36
  e.should be_kind_of(Watir::FileField)
69
37
  end
70
-
71
- it "raises an error if the element is not a text field" do
72
- lambda {
73
- browser.input(:xpath => "//input[@type='radio']").to_file_field
74
- }.should raise_error(TypeError)
75
- end
76
38
  end
77
39
  end
@@ -1,9 +1,12 @@
1
+ require 'active_support/ordered_hash'
2
+
1
3
  module LocatorSpecHelper
2
4
  def driver
3
5
  @driver ||= mock(Selenium::WebDriver::Driver)
4
6
  end
5
7
 
6
- def locator(selector, attrs = Watir::HTMLElement.attributes)
8
+ def locator(selector, attrs)
9
+ attrs ||= Watir::HTMLElement.attributes
7
10
  Watir::ElementLocator.new(driver, selector, attrs)
8
11
  end
9
12
 
@@ -15,12 +18,12 @@ module LocatorSpecHelper
15
18
  driver.should_receive(:find_elements).with(*args)
16
19
  end
17
20
 
18
- def locate_one(*args)
19
- locator(*args).locate
21
+ def locate_one(selector, attrs = nil)
22
+ locator(ordered_hash(selector), attrs).locate
20
23
  end
21
24
 
22
- def locate_all(*args)
23
- locator(*args).locate_all
25
+ def locate_all(selector, attrs = nil)
26
+ locator(ordered_hash(selector), attrs).locate_all
24
27
  end
25
28
 
26
29
  def element(opts = {})
@@ -33,5 +36,16 @@ module LocatorSpecHelper
33
36
 
34
37
  el
35
38
  end
39
+
40
+ def ordered_hash(selector)
41
+ case selector
42
+ when Hash
43
+ selector
44
+ when Array
45
+ ActiveSupport::OrderedHash[*selector]
46
+ else
47
+ raise ArgumentError, "couldn't create hash for #{selector.inspect}"
48
+ end
49
+ end
36
50
  end
37
51
 
@@ -25,5 +25,8 @@ if defined?(WatirSpec)
25
25
  args.any? { |arg| arg == :webdriver || arg == [:webdriver, browser] }
26
26
  }
27
27
  end
28
+
29
+ # WatirSpec.unguarded = true
28
30
  end
29
31
 
32
+
@@ -7,6 +7,14 @@ describe "Areas" 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.areas(:alt => "Tables").to_a.should == [browser.area(:alt => "Tables")]
14
+ end
15
+ end
16
+ end
17
+
10
18
  describe "#length" do
11
19
  it "returns the number of areas" do
12
20
  browser.areas.length.should == 3
@@ -81,13 +81,13 @@ describe "Browser" do
81
81
  end
82
82
  end
83
83
 
84
- bug "http://github.com/jarib/watirspec/issues/issue/8" [:webdriver, :ie], [:webdriver, :chrome] do
84
+ bug "http://github.com/jarib/watirspec/issues/issue/8", [:webdriver, :ie], [:webdriver, :chrome] do
85
85
  describe ".start" do
86
86
  it "goes to the given URL and return an instance of itself" do
87
87
  browser = WatirSpec.implementation.browser_class.start("#{WatirSpec.files}/non_control_elements.html")
88
88
  browser.should be_instance_of(WatirSpec.implementation.browser_class)
89
89
  browser.title.should == "Non-control elements"
90
- browser.quit
90
+ browser.close
91
91
  end
92
92
  end
93
93
  end
@@ -204,7 +204,7 @@ describe "Browser" do
204
204
  browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
205
205
  end
206
206
 
207
- not_compliant_on [:webdriver, :ie] do
207
+ not_compliant_on [:webdriver, :ie], :celerity do
208
208
  it "returns an Array of matching elements" do
209
209
  objects = browser.elements_by_xpath("//*[@type='text']")
210
210
  objects.should be_kind_of(Array)
@@ -213,7 +213,7 @@ describe "Browser" do
213
213
  end
214
214
  end
215
215
 
216
- deviates_on [:webdriver, :ie] do
216
+ deviates_on [:webdriver, :ie], :celerity do
217
217
  it "returns an Array of matching elements" do
218
218
  objects = browser.elements_by_xpath("//*[@type='text']")
219
219
  objects.should be_kind_of(Array)
@@ -105,10 +105,9 @@ describe "Button" do
105
105
  end
106
106
 
107
107
  describe "#src" do
108
- bug "http://github.com/jarib/watir-webdriver/issues/issue/27", [:webdriver, :ie], [:webdriver, :firefox] do
109
- it "returns the src attribute for the button image" do
110
- browser.button(:name, "new_user_image").src.should == "images/button.jpg"
111
- end
108
+ it "returns the src attribute for the button image" do
109
+ # varies between browsers
110
+ browser.button(:name, "new_user_image").src.should =~ %r"images/button.jpg$"
112
111
  end
113
112
 
114
113
  it "raises UnknownObjectException if the button does not exist" do
@@ -7,6 +7,14 @@ describe "Buttons" 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.buttons(:name => "new_user_button").to_a.should == [browser.button(:name => "new_user_button")]
14
+ end
15
+ end
16
+ end
17
+
10
18
  describe "#length" do
11
19
  it "returns the number of buttons" do
12
20
  browser.buttons.length.should == 8
@@ -7,6 +7,14 @@ describe "CheckBoxes" 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.checkboxes(:value => "books").to_a.should == [browser.checkbox(:value => "books")]
14
+ end
15
+ end
16
+ end
17
+
10
18
  describe "#length" do
11
19
  it "returns the number of checkboxes" do
12
20
  browser.checkboxes.length.should == 7
@@ -7,6 +7,14 @@ describe "Dds" 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.dds(:text => "11 years").to_a.should == [browser.dd(:text => "11 years")]
14
+ end
15
+ end
16
+ end
17
+
10
18
  describe "#length" do
11
19
  it "returns the number of dds" do
12
20
  browser.dds.length.should == 11
@@ -7,6 +7,14 @@ describe "Dels" 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.dels(:class => "lead").to_a.should == [browser.del(:class => "lead")]
14
+ end
15
+ end
16
+ end
17
+
10
18
  describe "#length" do
11
19
  it "returns the number of dels" do
12
20
  browser.dels.length.should == 5
@@ -7,6 +7,14 @@ describe "Divs" 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.divs(:id => "header").to_a.should == [browser.div(:id => "header")]
14
+ end
15
+ end
16
+ end
17
+
10
18
  describe "#length" do
11
19
  it "returns the number of divs" do
12
20
  browser.divs.length.should == 12
@@ -7,6 +7,14 @@ describe "Dls" 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.dls(:title => "experience").to_a.should == [browser.dl(:title => "experience")]
14
+ end
15
+ end
16
+ end
17
+
10
18
  describe "#length" do
11
19
  it "returns the number of dls" do
12
20
  browser.dls.length.should == 3