celerity 0.0.1 → 0.0.2

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 (93) hide show
  1. data/History.txt +10 -0
  2. data/README.txt +8 -11
  3. data/Rakefile +5 -3
  4. data/benchmark/bm_2000_spans.rb +48 -0
  5. data/benchmark/bm_digg.rb +26 -0
  6. data/benchmark/bm_google_images.rb +36 -0
  7. data/benchmark/bm_input_locator.rb +69 -0
  8. data/benchmark/loader.rb +9 -0
  9. data/lib/celerity.rb +3 -1
  10. data/lib/celerity/container.rb +23 -171
  11. data/lib/celerity/disabled_element.rb +1 -1
  12. data/lib/celerity/element.rb +78 -47
  13. data/lib/celerity/element_collections.rb +16 -32
  14. data/lib/celerity/element_locator.rb +135 -0
  15. data/lib/celerity/elements/button.rb +15 -0
  16. data/lib/celerity/elements/file_field.rb +1 -1
  17. data/lib/celerity/elements/form.rb +2 -1
  18. data/lib/celerity/elements/frame.rb +18 -21
  19. data/lib/celerity/elements/image.rb +2 -8
  20. data/lib/celerity/elements/label.rb +1 -3
  21. data/lib/celerity/elements/link.rb +1 -1
  22. data/lib/celerity/elements/option.rb +16 -0
  23. data/lib/celerity/elements/radio_check.rb +18 -7
  24. data/lib/celerity/elements/select_list.rb +1 -17
  25. data/lib/celerity/elements/table.rb +4 -4
  26. data/lib/celerity/elements/table_body.rb +6 -8
  27. data/lib/celerity/elements/table_cell.rb +3 -14
  28. data/lib/celerity/elements/table_row.rb +4 -10
  29. data/lib/celerity/elements/text_field.rb +16 -4
  30. data/lib/celerity/extra/method_generator.rb +144 -0
  31. data/lib/celerity/identifier.rb +10 -0
  32. data/lib/celerity/ie.rb +28 -13
  33. data/lib/celerity/input_element.rb +0 -4
  34. data/lib/celerity/non_control_elements.rb +12 -12
  35. data/lib/celerity/version.rb +1 -1
  36. data/spec/area_spec.rb +41 -41
  37. data/spec/areas_spec.rb +11 -11
  38. data/spec/button_spec.rb +73 -68
  39. data/spec/buttons_spec.rb +10 -10
  40. data/spec/checkbox_spec.rb +102 -96
  41. data/spec/checkboxes_spec.rb +10 -10
  42. data/spec/div_spec.rb +78 -73
  43. data/spec/divs_spec.rb +10 -10
  44. data/spec/element_spec.rb +20 -11
  45. data/spec/filefield_spec.rb +36 -41
  46. data/spec/filefields_spec.rb +10 -10
  47. data/spec/form_spec.rb +29 -29
  48. data/spec/forms_spec.rb +11 -11
  49. data/spec/frame_spec.rb +54 -49
  50. data/spec/hidden_spec.rb +43 -43
  51. data/spec/hiddens_spec.rb +10 -10
  52. data/spec/html/2000_spans.html +2009 -0
  53. data/spec/html/forms_with_input_elements.html +15 -9
  54. data/spec/html/non_control_elements.html +4 -2
  55. data/spec/ie_spec.rb +82 -48
  56. data/spec/image_spec.rb +83 -100
  57. data/spec/images_spec.rb +10 -10
  58. data/spec/label_spec.rb +29 -29
  59. data/spec/labels_spec.rb +10 -10
  60. data/spec/li_spec.rb +41 -41
  61. data/spec/link_spec.rb +65 -59
  62. data/spec/links_spec.rb +11 -11
  63. data/spec/lis_spec.rb +10 -10
  64. data/spec/map_spec.rb +30 -30
  65. data/spec/maps_spec.rb +10 -10
  66. data/spec/p_spec.rb +49 -49
  67. data/spec/pre_spec.rb +41 -41
  68. data/spec/pres_spec.rb +10 -10
  69. data/spec/ps_spec.rb +10 -10
  70. data/spec/radio_spec.rb +104 -97
  71. data/spec/radios_spec.rb +11 -11
  72. data/spec/select_list_spec.rb +118 -106
  73. data/spec/select_lists_spec.rb +15 -15
  74. data/spec/span_spec.rb +54 -54
  75. data/spec/spans_spec.rb +11 -11
  76. data/spec/spec.opts +1 -1
  77. data/spec/spec_helper.rb +23 -3
  78. data/spec/table_bodies.rb +8 -8
  79. data/spec/table_bodies_spec.rb +9 -9
  80. data/spec/table_body_spec.rb +28 -27
  81. data/spec/table_cell_spec.rb +25 -25
  82. data/spec/table_cells_spec.rb +16 -16
  83. data/spec/table_row_spec.rb +16 -16
  84. data/spec/table_rows_spec.rb +12 -12
  85. data/spec/table_spec.rb +36 -36
  86. data/spec/tables_spec.rb +12 -12
  87. data/spec/text_field_spec.rb +111 -92
  88. data/spec/text_fields_spec.rb +13 -13
  89. data/tasks/benchmark.rake +3 -0
  90. data/tasks/rspec.rake +2 -2
  91. data/tasks/testserver.rake +15 -0
  92. metadata +58 -46
  93. data/tasks/simple_ci.rake +0 -94
@@ -0,0 +1,10 @@
1
+ module Celerity
2
+
3
+ class Identifier < Struct.new(:tag, :attributes)
4
+ attr_accessor :text
5
+
6
+ def initialize(t, a={})
7
+ super(t, a)
8
+ end
9
+ end
10
+ end
data/lib/celerity/ie.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Celerity
2
2
  class IE
3
3
  include Container
4
- attr_accessor :page, :object
4
+ attr_accessor :page, :object, :webclient
5
5
 
6
6
  def self.start(uri)
7
7
  browser = new
@@ -10,12 +10,14 @@ module Celerity
10
10
  end
11
11
 
12
12
  def initialize(opts = {})
13
+ @page_container = self
14
+ @error_checkers = []
15
+ @last_url, @page = nil
16
+
13
17
  browser = RUBY_PLATFORM =~ /java/ ? ::HtmlUnit::BrowserVersion::FIREFOX_2 : ::HtmlUnit::BrowserVersion.FIREFOX_2
14
18
  @webclient = ::HtmlUnit::WebClient.new(browser)
15
19
  @webclient.setThrowExceptionOnScriptError(false) unless $DEBUG || opts[:enable_javascript_exceptions]
16
20
  @webclient.setCssEnabled(false) if opts[:disable_css]
17
- @page_container = self
18
- @error_checkers = []
19
21
  end
20
22
 
21
23
  def goto(uri)
@@ -29,7 +31,7 @@ module Celerity
29
31
  end
30
32
 
31
33
  def set_page(value)
32
- # Log.debug(value.pretty_inspect)
34
+ @last_url = url() if exist?
33
35
  @page = value
34
36
  @object = @page.getDocumentElement
35
37
  run_error_checks
@@ -41,29 +43,35 @@ module Celerity
41
43
  end
42
44
 
43
45
  def base_url
46
+ # FIXME: base_url HTTPS
44
47
  "http://" + URI.parse( url() ).host
45
48
  end
46
49
 
47
50
  def title
48
- @page.getTitleText
51
+ @page ? @page.getTitleText : ''
49
52
  end
50
53
 
51
54
  def html
52
- @page ? @page.getDocumentElement.asXml : ''
55
+ @page ? @page.getWebResponse.getContentAsString : ''
53
56
  end
54
57
 
55
58
  def text
56
59
  # nicer way to do this?
57
- assert_exists
58
- @page.getFirstByXPath("//body").asText
60
+ @page ? @page.getFirstByXPath("//body").asText : ''
61
+ end
62
+
63
+ def document
64
+ @object
59
65
  end
60
66
 
61
67
  def back
62
- raise NotImplementedError
68
+ # FIXME: this is naive, need capability from HtmlUnit
69
+ goto(@last_url) if @last_url
63
70
  end
64
71
 
65
72
  def refresh
66
- raise NotImplementedError
73
+ assert_exists
74
+ set_page(@page.refresh)
67
75
  end
68
76
 
69
77
  def exist?
@@ -78,7 +86,7 @@ module Celerity
78
86
  end
79
87
 
80
88
  def contains_text(expected_text)
81
- return "" unless exist?
89
+ return nil unless exist?
82
90
  case expected_text
83
91
  when Regexp
84
92
  text().match(expected_text)
@@ -89,6 +97,11 @@ module Celerity
89
97
  end
90
98
  end
91
99
 
100
+ def execute_script(source)
101
+ assert_exists
102
+ @page.executeJavaScript(source.to_s)
103
+ end
104
+
92
105
  def run_error_checks
93
106
  @error_checkers.each { |e| e.call(self) }
94
107
  end
@@ -99,14 +112,14 @@ module Celerity
99
112
  elsif Proc === checker
100
113
  @error_checkers << checker
101
114
  else
102
- raise ArgumentError, "argument must be a Proc or a block"
115
+ raise ArgumentError, "argument must be a Proc or block"
103
116
  end
104
117
  end
105
118
 
106
119
  def disable_checker(checker)
107
120
  @error_checkers.delete(checker)
108
121
  end
109
-
122
+
110
123
  # these are just for Watir compatability - should we keep them?
111
124
  class << self
112
125
  attr_accessor :speed, :attach_timeout, :visible
@@ -124,3 +137,5 @@ module Celerity
124
137
 
125
138
  end # IE
126
139
  end # Celerity
140
+
141
+ Celerity::Browser = Celerity::IE
@@ -7,10 +7,6 @@ module Celerity
7
7
  :src, :alt, :usemap, :ismap, :tabindex, :accesskey, :onfocus, :onblur,
8
8
  :onselect, :onchange, :accept, :align]
9
9
 
10
- def locate
11
- @object = @container.locate_input_element(self, @how, @what)
12
- end
13
-
14
10
  def readonly?
15
11
  assert_exists
16
12
  @object.isAttributeDefined('readonly')
@@ -13,38 +13,38 @@ module Celerity
13
13
  assert_exists
14
14
  @container.update_page(@object.click)
15
15
  end
16
-
17
- # # These elements can't be disabled
18
- # def disabled?; false; end
19
- # alias_method :disabled, :disabled?
20
16
  end
21
17
 
22
18
  class Pre < NonControlElement
23
- TAGS = ['pre']
19
+ TAGS = [ Identifier.new('pre')]
24
20
  end
25
21
 
26
22
  class P < NonControlElement
27
- TAGS = ['p']
23
+ TAGS = [ Identifier.new('p') ]
28
24
  end
29
25
 
30
26
  class Div < NonControlElement
31
- TAGS = ['div']
27
+ TAGS = [ Identifier.new('div')]
32
28
  end
33
29
 
34
30
  class Span < NonControlElement
35
- TAGS = ['span']
31
+ TAGS = [ Identifier.new('span') ]
36
32
  end
37
33
 
38
34
  class Li < NonControlElement
39
- TAGS = ['li']
35
+ TAGS = [ Identifier.new('li') ]
40
36
  end
41
37
 
42
38
  class Map < NonControlElement
43
- TAGS = ['map']
39
+ # double-check my DTD reading here! :)
40
+ ATTRIBUTES = BASE_ATTRIBUTES | [:id, :class, :style, :title, :name]
41
+ TAGS = [ Identifier.new('map') ]
44
42
  end
45
43
 
46
44
  class Area < NonControlElement
47
- TAGS = ['area']
45
+ # double-check my DTD reading here! :)
46
+ ATTRIBUTES = BASE_ATTRIBUTES | [:shape, :coords, :href, :nohref, :alt]
47
+ TAGS = [ Identifier.new('area') ]
48
48
  end
49
49
 
50
- end
50
+ end
@@ -2,7 +2,7 @@ module Celerity #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/spec/area_spec.rb CHANGED
@@ -1,79 +1,79 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
- describe "P" do
3
+ describe "Area" do
4
4
 
5
5
  before :all do
6
- @ie = IE.new
7
- add_spec_checker(@ie)
6
+ @browser = IE.new
7
+ add_spec_checker(@browser)
8
8
  end
9
9
 
10
10
  before :each do
11
- @ie.goto(TEST_HOST + "/images.html")
11
+ @browser.goto(TEST_HOST + "/images.html")
12
12
  end
13
13
 
14
14
  # Exists method
15
15
  describe "#exist?" do
16
- it "should return true if the 'area' exists" do
17
- @ie.area(:id, "NCE").should exist
18
- @ie.area(:id, /NCE/).should exist
19
- @ie.area(:name, "NCE").should exist
20
- @ie.area(:name, /NCE/).should exist
21
- @ie.area(:title, "Tables").should exist
22
- @ie.area(:title, /Tables/).should exist
23
- @ie.area(:url, "tables.html").should exist
24
- @ie.area(:url, /tables/).should exist
25
- @ie.area(:index, 1).should exist
26
- @ie.area(:xpath, "//area[@id='NCE']").should exist
16
+ it "should return true if the area exists" do
17
+ @browser.area(:id, "NCE").should exist
18
+ @browser.area(:id, /NCE/).should exist
19
+ @browser.area(:name, "NCE").should exist
20
+ @browser.area(:name, /NCE/).should exist
21
+ @browser.area(:title, "Tables").should exist
22
+ @browser.area(:title, /Tables/).should exist
23
+ @browser.area(:url, "tables.html").should exist
24
+ @browser.area(:url, /tables/).should exist
25
+ @browser.area(:index, 1).should exist
26
+ @browser.area(:xpath, "//area[@id='NCE']").should exist
27
27
  end
28
- it "should return false if the 'area' doesn't exist" do
29
- @ie.area(:id, "no_such_id").should_not exist
30
- @ie.area(:id, /no_such_id/).should_not exist
31
- @ie.area(:name, "no_such_id").should_not exist
32
- @ie.area(:name, /no_such_id/).should_not exist
33
- @ie.area(:title, "no_such_title").should_not exist
34
- @ie.area(:title, /no_such_title/).should_not exist
35
- @ie.area(:url, "no_such_href").should_not exist
36
- @ie.area(:url, /no_such_href/).should_not exist
37
- @ie.area(:index, 1337).should_not exist
38
- @ie.area(:xpath, "//area[@id='no_such_id']").should_not exist
28
+ it "should return false if the area doesn't exist" do
29
+ @browser.area(:id, "no_such_id").should_not exist
30
+ @browser.area(:id, /no_such_id/).should_not exist
31
+ @browser.area(:name, "no_such_id").should_not exist
32
+ @browser.area(:name, /no_such_id/).should_not exist
33
+ @browser.area(:title, "no_such_title").should_not exist
34
+ @browser.area(:title, /no_such_title/).should_not exist
35
+ @browser.area(:url, "no_such_href").should_not exist
36
+ @browser.area(:url, /no_such_href/).should_not exist
37
+ @browser.area(:index, 1337).should_not exist
38
+ @browser.area(:xpath, "//area[@id='no_such_id']").should_not exist
39
39
  end
40
- it "should raise ArgumentError when what argument is invalid" do
41
- lambda { @ie.area(:id, 3.14).exists? }.should raise_error(ArgumentError)
40
+ it "should raise ArgumentError when 'what' argument is invalid" do
41
+ lambda { @browser.area(:id, 3.14).exists? }.should raise_error(ArgumentError)
42
42
  end
43
- it "should raise MissingWayOfFindingObjectException when how argument is invalid" do
44
- lambda { @ie.area(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
43
+ it "should raise MissingWayOfFindingObjectException when 'how' argument is invalid" do
44
+ lambda { @browser.area(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
45
45
  end
46
46
  end
47
47
 
48
48
  # Attribute methods
49
49
  describe "#id" do
50
50
  it "should return the id attribute" do
51
- @ie.area(:index, 1).id.should == "NCE"
51
+ @browser.area(:index, 1).id.should == "NCE"
52
52
  end
53
53
  it "should return an empty string if the element exists and the attribute doesn't" do
54
- @ie.area(:index, 3).id.should == ''
54
+ @browser.area(:index, 3).id.should == ''
55
55
  end
56
- it "should raise UnknownObjectException if the p doesn't exist" do
57
- lambda { @ie.area(:id, "no_such_id").id }.should raise_error(UnknownObjectException)
58
- lambda { @ie.area(:index, 1337).id }.should raise_error(UnknownObjectException)
56
+ it "should raise UnknownObjectException if the area doesn't exist" do
57
+ lambda { @browser.area(:id, "no_such_id").id }.should raise_error(UnknownObjectException)
58
+ lambda { @browser.area(:index, 1337).id }.should raise_error(UnknownObjectException)
59
59
  end
60
60
  end
61
61
 
62
62
  describe "#name" do
63
63
  it "should return the name attribute" do
64
- @ie.area(:index, 1).name.should == "NCE"
64
+ @browser.area(:index, 1).name.should == "NCE"
65
65
  end
66
66
  it "should return an empty string if the element exists and the attribute doesn't" do
67
- @ie.area(:index, 3).name.should == ''
67
+ @browser.area(:index, 3).name.should == ''
68
68
  end
69
- it "should raise UnknownObjectException if the p doesn't exist" do
70
- lambda { @ie.area(:id, "no_such_id").name }.should raise_error(UnknownObjectException)
71
- lambda { @ie.area(:index, 1337).name }.should raise_error(UnknownObjectException)
69
+ it "should raise UnknownObjectException if the area doesn't exist" do
70
+ lambda { @browser.area(:id, "no_such_id").name }.should raise_error(UnknownObjectException)
71
+ lambda { @browser.area(:index, 1337).name }.should raise_error(UnknownObjectException)
72
72
  end
73
73
  end
74
74
 
75
75
  after :all do
76
- @ie.close
76
+ @browser.close
77
77
  end
78
78
 
79
79
  end
data/spec/areas_spec.rb CHANGED
@@ -3,38 +3,38 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
3
3
  describe "Areas" do
4
4
 
5
5
  before :all do
6
- @ie = IE.new
7
- add_spec_checker(@ie)
6
+ @browser = IE.new
7
+ add_spec_checker(@browser)
8
8
  end
9
9
 
10
10
  before :each do
11
- @ie.goto(TEST_HOST + "/images.html")
11
+ @browser.goto(TEST_HOST + "/images.html")
12
12
  end
13
13
 
14
14
  describe "#length" do
15
15
  it "should return the number of areas" do
16
- @ie.areas.length.should == 3
16
+ @browser.areas.length.should == 3
17
17
  end
18
18
  end
19
19
 
20
20
  describe "#[]" do
21
- it "should return the p at the given index" do
22
- @ie.areas[1].id.should == "NCE"
21
+ it "should return the area at the given index" do
22
+ @browser.areas[1].id.should == "NCE"
23
23
  end
24
24
  end
25
25
 
26
26
  describe "#each" do
27
27
  it "should iterate through areas correctly" do
28
- @ie.areas.each_with_index do |a, index|
29
- a.name.should == @ie.area(:index, index+1).name
30
- a.id.should == @ie.area(:index, index+1).id
31
- a.value.should == @ie.area(:index, index+1).value
28
+ @browser.areas.each_with_index do |a, index|
29
+ a.name.should == @browser.area(:index, index+1).name
30
+ a.id.should == @browser.area(:index, index+1).id
31
+ a.value.should == @browser.area(:index, index+1).value
32
32
  end
33
33
  end
34
34
  end
35
35
 
36
36
  after :all do
37
- @ie.close
37
+ @browser.close
38
38
  end
39
39
 
40
40
  end
data/spec/button_spec.rb CHANGED
@@ -3,169 +3,174 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
3
3
  describe "Button" do
4
4
 
5
5
  before :all do
6
- @ie = IE.new
7
- add_spec_checker(@ie)
6
+ @browser = IE.new
7
+ add_spec_checker(@browser)
8
8
  end
9
9
 
10
10
  before :each do
11
- @ie.goto(TEST_HOST + "/forms_with_input_elements.html")
11
+ @browser.goto(TEST_HOST + "/forms_with_input_elements.html")
12
12
  end
13
13
 
14
14
  # Exists method
15
15
  describe "#exists?" do
16
16
  it "should return true if the button exists" do
17
- @ie.button(:id, "new_user_submit").should exist
18
- @ie.button(:id, /new_user_submit/).should exist
19
- @ie.button(:name, "new_user_reset").should exist
20
- @ie.button(:name, /new_user_reset/).should exist
17
+ @browser.button(:id, "new_user_submit").should exist
18
+ @browser.button(:id, /new_user_submit/).should exist
19
+ @browser.button(:name, "new_user_reset").should exist
20
+ @browser.button(:name, /new_user_reset/).should exist
21
21
  # we need to figure out what :text and :value/:caption means on input type="button" and <button /> elements
22
- @ie.button(:value, "Button 2").should exist
23
- @ie.button(:value, /Button 2/).should exist
24
- @ie.button(:text, "Button 2").should exist
25
- @ie.button(:text, /Button 2/).should exist
26
- @ie.button(:class, "image").should exist
27
- @ie.button(:class, /image/).should exist
28
- @ie.button(:index, 1).should exist
29
- @ie.button(:xpath, "//input[@id='new_user_submit']").should exist
30
- end
22
+ # it should return the value attribute for <input> elements, and the inner text for <button> elements - Jari 2008-05-10
23
+ @browser.button(:value, "Button 2").should exist
24
+ @browser.button(:value, /Button 2/).should exist
25
+ @browser.button(:text, "Button 2").should exist
26
+ @browser.button(:text, /Button 2/).should exist
27
+ @browser.button(:class, "image").should exist
28
+ @browser.button(:class, /image/).should exist
29
+ @browser.button(:index, 1).should exist
30
+ @browser.button(:xpath, "//input[@id='new_user_submit']").should exist
31
+ end
32
+
31
33
  it "should return true if the button exists (how = :caption)" do
32
34
  # we need to figure out what :text and :value/:caption means on input type="button" and <button /> elements
33
- @ie.button(:caption, "Button 2").should exist
34
- @ie.button(:caption, /Button 2/).should exist
35
+ @browser.button(:caption, "Button 2").should exist
36
+ @browser.button(:caption, /Button 2/).should exist
35
37
  end
38
+
36
39
  it "should return true if the button exists (default how = :value)" do
37
- @ie.button("Submit").should exist
40
+ @browser.button("Submit").should exist
38
41
  end
42
+
39
43
  it "should return false if the button doesn't exist" do
40
- @ie.button(:id, "no_such_id").should_not exist
41
- @ie.button(:id, /no_such_id/).should_not exist
42
- @ie.button(:name, "no_such_name").should_not exist
43
- @ie.button(:name, /no_such_name/).should_not exist
44
+ @browser.button(:id, "no_such_id").should_not exist
45
+ @browser.button(:id, /no_such_id/).should_not exist
46
+ @browser.button(:name, "no_such_name").should_not exist
47
+ @browser.button(:name, /no_such_name/).should_not exist
44
48
  # we need to figure out what :text and :value/:caption means on input type="button" and <button /> elements
45
- @ie.button(:value, "no_such_value").should_not exist
46
- @ie.button(:value, /no_such_value/).should_not exist
47
- @ie.button(:text, "no_such_text").should_not exist
48
- @ie.button(:text, /no_such_text/).should_not exist
49
- @ie.button(:class, "no_such_class").should_not exist
50
- @ie.button(:class, /no_such_class/).should_not exist
51
- @ie.button(:index, 1337).should_not exist
52
- @ie.button(:xpath, "//input[@id='no_such_id']").should_not exist
49
+ @browser.button(:value, "no_such_value").should_not exist
50
+ @browser.button(:value, /no_such_value/).should_not exist
51
+ @browser.button(:text, "no_such_text").should_not exist
52
+ @browser.button(:text, /no_such_text/).should_not exist
53
+ @browser.button(:class, "no_such_class").should_not exist
54
+ @browser.button(:class, /no_such_class/).should_not exist
55
+ @browser.button(:index, 1337).should_not exist
56
+ @browser.button(:xpath, "//input[@id='no_such_id']").should_not exist
53
57
  end
54
- it "should raise ArgumentError when what argument is invalid" do
55
- lambda { @ie.button(:id, 3.14).exists? }.should raise_error(ArgumentError)
58
+ it "should raise ArgumentError when 'what' argument is invalid" do
59
+ lambda { @browser.button(:id, 3.14).exists? }.should raise_error(ArgumentError)
56
60
  end
57
- it "should raise MissingWayOfFindingObjectException when how argument is invalid" do
58
- lambda { @ie.button(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
61
+ it "should raise MissingWayOfFindingObjectException when 'how' argument is invalid" do
62
+ lambda { @browser.button(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
59
63
  end
60
64
  end
61
65
 
62
66
  # Attribute methods
63
67
  describe "#class_name" do
64
68
  it "should return the class name of the button" do
65
- @ie.button(:name, "new_user_image").class_name.should == "image"
69
+ @browser.button(:name, "new_user_image").class_name.should == "image"
66
70
  end
67
71
  it "should return an empty string if the button has no class name" do
68
- @ie.button(:name, "new_user_submit").class_name.should == ""
72
+ @browser.button(:name, "new_user_submit").class_name.should == ""
69
73
  end
70
74
  end
71
75
 
72
76
  describe "#id" do
73
77
  it "should return the id if the button exists" do
74
- @ie.button(:index, 1).id.should == 'new_user_submit'
75
- @ie.button(:index, 2).id.should == 'new_user_reset'
76
- @ie.button(:index, 3).id.should == 'new_user_button'
78
+ @browser.button(:index, 1).id.should == 'new_user_submit'
79
+ @browser.button(:index, 2).id.should == 'new_user_reset'
80
+ @browser.button(:index, 3).id.should == 'new_user_button'
77
81
  end
78
82
  it "should raise UnknownObjectException if button does not exist" do
79
- lambda { @ie.button(:index, 1337).id }.should raise_error(UnknownObjectException)
83
+ lambda { @browser.button(:index, 1337).id }.should raise_error(UnknownObjectException)
80
84
  end
81
85
  end
82
86
 
83
87
  describe "#name" do
84
88
  it "should return the name if button exists" do
85
- @ie.button(:index, 1).name.should == 'new_user_submit'
86
- @ie.button(:index, 2).name.should == 'new_user_reset'
87
- @ie.button(:index, 3).name.should == 'new_user_button'
89
+ @browser.button(:index, 1).name.should == 'new_user_submit'
90
+ @browser.button(:index, 2).name.should == 'new_user_reset'
91
+ @browser.button(:index, 3).name.should == 'new_user_button'
88
92
  end
89
93
  it "should raise UnknownObjectException if button does not exist" do
90
- lambda { @ie.button(:name, "no_such_name").name }.should raise_error(UnknownObjectException)
94
+ lambda { @browser.button(:name, "no_such_name").name }.should raise_error(UnknownObjectException)
91
95
  end
92
96
  end
93
97
 
94
98
  describe "#title" do
95
99
  it "should return the title of the button" do
96
- @ie.button(:index, 1).title.should == 'Submit the form'
100
+ @browser.button(:index, 1).title.should == 'Submit the form'
97
101
  end
98
102
  it "should return an empty string for button without title" do
99
- @ie.button(:index, 2).title.should == ''
103
+ @browser.button(:index, 2).title.should == ''
100
104
  end
101
105
  end
102
106
 
103
107
  describe "#type" do
104
108
  it "should return the type if button exists" do
105
- @ie.button(:index, 1).type.should == 'submit'
106
- @ie.button(:index, 2).type.should == 'reset'
107
- @ie.button(:index, 3).type.should == 'button'
109
+ @browser.button(:index, 1).type.should == 'submit'
110
+ @browser.button(:index, 2).type.should == 'reset'
111
+ @browser.button(:index, 3).type.should == 'button'
108
112
  end
109
113
  it "should raise UnknownObjectException if button does not exist" do
110
- lambda { @ie.button(:name, "no_such_name").type }.should raise_error(UnknownObjectException)
114
+ lambda { @browser.button(:name, "no_such_name").type }.should raise_error(UnknownObjectException)
111
115
  end
112
116
  end
113
117
 
114
118
  describe "#value" do
115
119
  it "should return the value if button exists" do
116
- @ie.button(:index, 1).value.should == 'Submit'
117
- @ie.button(:index, 2).value.should == 'Reset'
118
- @ie.button(:index, 3).value.should == 'Button'
120
+ @browser.button(:index, 1).value.should == 'Submit'
121
+ @browser.button(:index, 2).value.should == 'Reset'
122
+ @browser.button(:index, 3).value.should == 'Button'
119
123
  end
120
124
  it "should raise UnknownObjectException if button does not exist" do
121
- lambda { @ie.button(:name, "no_such_name").value }.should raise_error(UnknownObjectException)
125
+ lambda { @browser.button(:name, "no_such_name").value }.should raise_error(UnknownObjectException)
122
126
  end
123
127
  end
124
128
 
125
129
  # Access methods
126
130
  describe "#enabled?" do
127
131
  it "should return true if the button is enabled" do
128
- @ie.button(:name, 'new_user_submit').should be_enabled
132
+ @browser.button(:name, 'new_user_submit').should be_enabled
129
133
  end
130
134
  it "should return false if the button is disabled" do
131
- @ie.button(:name, 'new_user_submit_disabled').should_not be_enabled
135
+ @browser.button(:name, 'new_user_submit_disabled').should_not be_enabled
132
136
  end
133
137
  it "should raise UnknownObjectException if the button doesn't exist" do
134
- lambda { @ie.button(:name, "no_such_name").enabled? }.should raise_error(UnknownObjectException)
138
+ lambda { @browser.button(:name, "no_such_name").enabled? }.should raise_error(UnknownObjectException)
135
139
  end
136
140
  end
137
141
 
138
142
  describe "#disabled?" do
139
143
  it "should return false when button is enabled" do
140
- @ie.button(:name, 'new_user_submit').should_not be_disabled
144
+ @browser.button(:name, 'new_user_submit').should_not be_disabled
141
145
  end
142
146
  it "should return true when button is disabled" do
143
- @ie.button(:name, 'new_user_submit_disabled').should be_disabled
147
+ @browser.button(:name, 'new_user_submit_disabled').should be_disabled
144
148
  end
145
149
  it "should raise UnknownObjectException if button does not exist" do
146
- lambda { @ie.button(:name, "no_such_name").disabled? }.should raise_error(UnknownObjectException)
150
+ lambda { @browser.button(:name, "no_such_name").disabled? }.should raise_error(UnknownObjectException)
147
151
  end
148
152
  end
149
153
 
150
154
  # Manipulation methods
151
155
  describe "#click" do
152
156
  it "should click the button if it exists" do
153
- pending
157
+ @browser.button(:id, 'new_user_submit').click
158
+ @browser.text.should include("You posted the following content:")
154
159
  end
155
160
  it "should fire events" do
156
- @ie.button(:id, 'new_user_button').click
157
- @ie.button(:id, 'new_user_button').value.should == 'new_value_set_by_onclick_event'
161
+ @browser.button(:id, 'new_user_button').click
162
+ @browser.button(:id, 'new_user_button').value.should == 'new_value_set_by_onclick_event'
158
163
  end
159
164
  it "should raise UnknownObjectException when clicking a button that doesn't exist" do
160
- lambda { @ie.button(:value, "no_such_value").click }.should raise_error(UnknownObjectException)
161
- lambda { @ie.button(:id, "no_such_id").click }.should raise_error(UnknownObjectException)
165
+ lambda { @browser.button(:value, "no_such_value").click }.should raise_error(UnknownObjectException)
166
+ lambda { @browser.button(:id, "no_such_id").click }.should raise_error(UnknownObjectException)
162
167
  end
163
168
  it "should raise ObjectDisabledException when clicking a disabled button" do
164
- lambda { @ie.button(:value, "Disabled").click }.should raise_error(ObjectDisabledException)
169
+ lambda { @browser.button(:value, "Disabled").click }.should raise_error(ObjectDisabledException)
165
170
  end
166
171
  end
167
172
 
168
173
  after :all do
169
- @ie.close
174
+ @browser.close
170
175
  end
171
176
  end