watir-webdriver 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -71,21 +71,21 @@ module Watir
71
71
  def define_string_attribute(mname, aname)
72
72
  define_method mname do
73
73
  assert_exists
74
- rescue_no_match { @element.attribute(aname).to_s }
74
+ @element.attribute(aname).to_s
75
75
  end
76
76
  end
77
77
 
78
78
  def define_boolean_attribute(mname, aname)
79
79
  define_method mname do
80
80
  assert_exists
81
- rescue_no_match(false) { !!@element.attribute(aname) }
81
+ !!@element.attribute(aname)
82
82
  end
83
83
  end
84
84
 
85
85
  def define_int_attribute(mname, aname)
86
86
  define_method mname do
87
87
  assert_exists
88
- rescue_no_match(-1) { @element.attribute(aname).to_i }
88
+ @element.attribute(aname).to_i
89
89
  end
90
90
  end
91
91
 
@@ -225,12 +225,16 @@ module Watir
225
225
 
226
226
  def value
227
227
  assert_exists
228
- rescue_no_match { @element.value || "" }
228
+
229
+ begin
230
+ @element.value
231
+ rescue WebDriver::Error::ElementNotEnabledError
232
+ ""
233
+ end
229
234
  end
230
235
 
231
236
  def attribute_value(attribute_name)
232
237
  assert_exists
233
- # should rescue?
234
238
  @element.attribute attribute_name
235
239
  end
236
240
 
@@ -291,7 +295,7 @@ module Watir
291
295
  assert_exists
292
296
  @element.style property
293
297
  else
294
- rescue_no_match { attribute_value "style" } || ''
298
+ attribute_value "style" || ''
295
299
  end
296
300
  end
297
301
 
@@ -338,12 +342,6 @@ module Watir
338
342
  raise ObjectReadOnlyException if respond_to?(:readonly?) && readonly?
339
343
  end
340
344
 
341
- def rescue_no_match(returned = "", &blk)
342
- yield
343
- rescue WebDriver::Error::ElementNotEnabledError
344
- returned
345
- end
346
-
347
345
  def extract_selector(selectors)
348
346
  case selectors.size
349
347
  when 2
@@ -17,7 +17,7 @@ module Watir
17
17
 
18
18
  def type
19
19
  assert_exists
20
- value = rescue_no_match { @element.attribute("type").to_s }
20
+ value = @element.attribute("type").to_s
21
21
 
22
22
  # we return 'text' if the type is invalid
23
23
  # not sure if we really should do this
@@ -4,16 +4,16 @@ module Watir
4
4
  include Watir::Exception
5
5
  include Selenium
6
6
 
7
- WD_FINDERS = [
8
- :class,
9
- :class_name,
7
+ WD_FINDERS = [
8
+ :class,
9
+ :class_name,
10
10
  :css,
11
- :id,
11
+ :id,
12
12
  :link,
13
- :link_text,
14
- :name,
15
- :partial_link_text,
16
- :tag_name,
13
+ :link_text,
14
+ :name,
15
+ :partial_link_text,
16
+ :tag_name,
17
17
  :xpath
18
18
  ]
19
19
 
@@ -124,6 +124,14 @@ module Watir
124
124
 
125
125
  def wd_find_by_regexp_selector(selector, method = :find)
126
126
  rx_selector = delete_regexps_from(selector)
127
+
128
+ if rx_selector.has_key?(:label) && should_use_label_element?
129
+ label_exp = rx_selector.delete(:label)
130
+ label = @wd.find_elements(:tag_name, 'label').find { |e| matches_selector?({:text => label_exp}, e) } || return
131
+
132
+ selector[:id] = label.attribute(:for)
133
+ end
134
+
127
135
  xpath = build_xpath(selector) || raise("internal error: unable to build xpath from #{@selector.inspect}")
128
136
 
129
137
  elements = @wd.find_elements(:xpath, xpath)
@@ -202,7 +210,7 @@ module Watir
202
210
  end
203
211
 
204
212
  def assert_valid_as_attribute(attribute)
205
- if @valid_attributes && !@valid_attributes.include?(attribute)
213
+ unless valid_attribute? attribute
206
214
  raise MissingWayOfFindingObjectException, "invalid attribute: #{attribute.inspect}"
207
215
  end
208
216
  end
@@ -227,6 +235,14 @@ module Watir
227
235
  tag_name === element.tag_name
228
236
  end
229
237
 
238
+ def valid_attribute?(attribute)
239
+ @valid_attributes && @valid_attributes.include?(attribute)
240
+ end
241
+
242
+ def should_use_label_element?
243
+ @selector[:tag_name] != "option"
244
+ end
245
+
230
246
  def build_xpath(selectors)
231
247
  return if selectors.values.any? { |e| e.kind_of? Regexp }
232
248
 
@@ -260,7 +276,12 @@ module Watir
260
276
  end
261
277
 
262
278
  def equal_pair(key, value)
263
- "#{lhs_for(key)}='#{value}'"
279
+ # we assume :label means a corresponding label element, not the attribute
280
+ if key == :label && should_use_label_element?
281
+ "@id=//label[normalize-space()='#{value}']/@for"
282
+ else
283
+ "#{lhs_for(key)}='#{value}'"
284
+ end
264
285
  end
265
286
 
266
287
  def lhs_for(key)
@@ -32,9 +32,9 @@ module Watir
32
32
  end
33
33
 
34
34
  def lhs_for(key)
35
- if @building == :input && [:text, :label].include?(key)
35
+ if @building == :input && key == :text
36
36
  "@value"
37
- elsif @building == :textarea && [:value, :label].include?(key)
37
+ elsif @building == :textarea && :value == :key
38
38
  "text()"
39
39
  else
40
40
  super
@@ -122,7 +122,7 @@ describe "Image" do
122
122
  end
123
123
 
124
124
  # File methods
125
- bug "WTR-347", :watir do
125
+ not_compliant_on :watir, :webdriver do # "WTR-347"
126
126
  describe "#file_created_date" do
127
127
  it "returns the date the image was created as reported by the file system" do
128
128
  browser.goto(WatirSpec.host + "/images.html")
@@ -134,7 +134,7 @@ describe "Image" do
134
134
  end
135
135
 
136
136
 
137
- bug "WTR-346", :watir do
137
+ not_compliant_on :watir, :webdriver do # WTR-346
138
138
  describe "#file_size" do
139
139
  it "returns the file size of the image if the image exists" do
140
140
  browser.image(:id, 'square').file_size.should == File.size("#{WatirSpec.files}/images/square.jpg".sub("file://", ''))
@@ -172,7 +172,7 @@ describe "Image" do
172
172
 
173
173
  # Other
174
174
 
175
- not_compliant_on(:webdriver) {
175
+ not_compliant_on :webdriver do
176
176
  describe "#loaded?" do
177
177
  it "returns true if the image has been loaded" do
178
178
  browser.image(:title, 'Circle').should be_loaded
@@ -191,20 +191,20 @@ describe "Image" do
191
191
  lambda { browser.image(:index, 1337).loaded? }.should raise_error(UnknownObjectException)
192
192
  end
193
193
  end
194
+ end
194
195
 
195
- bug "WTR-336", :watir do
196
- describe "#save" do
197
- it "saves the image to a file" do
198
- file = "#{File.expand_path Dir.pwd}/sample.img.dat"
199
- begin
200
- browser.image(:index, 1).save(file)
201
- File.exist?(file).should be_true
202
- ensure
203
- File.delete(file) if File.exist?(file)
204
- end
196
+ not_compliant_on :watir, :webdriver do # WTR-336
197
+ describe "#save" do
198
+ it "saves the image to a file" do
199
+ file = "#{File.expand_path Dir.pwd}/sample.img.dat"
200
+ begin
201
+ browser.image(:index, 1).save(file)
202
+ File.exist?(file).should be_true
203
+ ensure
204
+ File.delete(file) if File.exist?(file)
205
205
  end
206
206
  end
207
207
  end
208
- }
208
+ end
209
209
 
210
210
  end
@@ -91,14 +91,12 @@ describe "Option" do
91
91
  describe "#select" do
92
92
  bug "WTR-367", :watir do
93
93
  it "selects the chosen option (page context)" do
94
- browser.select_list(:name, "new_user_country").clear
95
94
  browser.option(:text, "Denmark").select
96
95
  browser.select_list(:name, "new_user_country").selected_options.should == ["Denmark"]
97
96
  end
98
97
  end
99
98
 
100
99
  it "selects the chosen option (select_list context)" do
101
- browser.select_list(:name, "new_user_country").clear
102
100
  browser.select_list(:name, "new_user_country").option(:text, "Denmark").select
103
101
  browser.select_list(:name, "new_user_country").selected_options.should == ["Denmark"]
104
102
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{watir-webdriver}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jari Bakken"]
12
- s.date = %q{2010-07-21}
12
+ s.date = %q{2010-07-22}
13
13
  s.description = %q{WebDriver-backed Watir}
14
14
  s.email = %q{jari.bakken@gmail.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watir-webdriver
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jari Bakken
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-21 00:00:00 +02:00
18
+ date: 2010-07-22 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency