watir-webdriver 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -7,3 +7,4 @@ coverage
7
7
  rdoc
8
8
  .yardoc
9
9
  Gemfile.lock
10
+ .rvmrc
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gem "simplecov", ">= 0.3.5", :platform => :ruby_19
4
+ gem "ruby-debug19", :platform => :ruby_19
4
5
 
5
6
  # Specify your gem's dependencies in watir-webdriver.gemspec
6
7
  gemspec
@@ -120,7 +120,7 @@ module Watir
120
120
  end
121
121
 
122
122
  def execute_script(script, *args)
123
- args.map! { |e| e.kind_of?(Watir::Element) ? e.element : e }
123
+ args.map! { |e| e.kind_of?(Watir::Element) ? e.wd : e }
124
124
  returned = @driver.execute_script(script, *args)
125
125
 
126
126
  wrap_elements_in(returned)
@@ -190,7 +190,7 @@ module Watir
190
190
  end
191
191
 
192
192
  def wrap_element(element)
193
- Watir.element_class_for(element.tag_name).new(self, :element => element)
193
+ Watir.element_class_for(element.tag_name.downcase).new(self, :element => element)
194
194
  end
195
195
 
196
196
  end # Browser
@@ -41,7 +41,6 @@ module Watir
41
41
  # @return [Watir::Element] Returns an instance of a Watir::Element subclass
42
42
  #
43
43
 
44
-
45
44
  def [](idx)
46
45
  to_a[idx] || element_class.new(@parent, :index => idx)
47
46
  end
@@ -23,13 +23,16 @@ module Watir
23
23
 
24
24
  def text
25
25
  assert_exists
26
- case @element.tag_name
26
+
27
+ tn = @element.tag_name.downcase
28
+
29
+ case tn
27
30
  when 'input'
28
31
  @element.attribute(:value)
29
32
  when 'button'
30
33
  @element.text
31
34
  else
32
- raise Exception::Error, "unknown tag name for button: #{@element.tag_name}"
35
+ raise Exception::Error, "unknown tag name for button: #{tn}"
33
36
  end
34
37
  end
35
38
 
@@ -47,7 +47,7 @@ module Watir
47
47
  return false unless other.kind_of? self.class
48
48
 
49
49
  assert_exists
50
- @element == other.element
50
+ @element == other.wd
51
51
  end
52
52
  alias_method :eql?, :==
53
53
 
@@ -62,7 +62,7 @@ module Watir
62
62
 
63
63
  def tag_name
64
64
  assert_exists
65
- @element.tag_name
65
+ @element.tag_name.downcase
66
66
  end
67
67
 
68
68
  def click
@@ -102,7 +102,7 @@ module Watir
102
102
 
103
103
  begin
104
104
  @element.value || ''
105
- rescue WebDriver::Error::ElementNotEnabledError
105
+ rescue WebDriver::Error::InvalidElementStateError
106
106
  ""
107
107
  end
108
108
  end
@@ -145,19 +145,26 @@ module Watir
145
145
  e = driver.execute_script "return arguments[0].parentNode", @element
146
146
 
147
147
  if e.kind_of?(WebDriver::Element)
148
- Watir.element_class_for(e.tag_name).new(@parent, :element => e)
148
+ Watir.element_class_for(e.tag_name.downcase).new(@parent, :element => e)
149
149
  end
150
150
  end
151
151
 
152
+ #
153
+ # @api private
154
+ #
155
+
152
156
  def driver
153
157
  @parent.driver
154
158
  end
155
159
 
156
- def element
160
+ #
161
+ # @api private
162
+ #
163
+
164
+ def wd
157
165
  assert_exists
158
166
  @element
159
167
  end
160
- alias_method :wd, :element # ensures duck typing with Browser
161
168
 
162
169
  #
163
170
  # Returns true if this element is visible on the page
@@ -183,7 +190,7 @@ module Watir
183
190
  assert_exists
184
191
  @element.style property
185
192
  else
186
- attribute_value("style") || ''
193
+ attribute_value("style").to_s.strip
187
194
  end
188
195
  end
189
196
 
@@ -200,8 +207,8 @@ module Watir
200
207
  #
201
208
 
202
209
  def to_subtype
203
- elem = element()
204
- tag_name = elem.tag_name
210
+ elem = wd()
211
+ tag_name = elem.tag_name.downcase
205
212
 
206
213
  klass = nil
207
214
 
@@ -71,7 +71,7 @@ module Watir
71
71
  end
72
72
 
73
73
  def ==(other)
74
- @element == other.element
74
+ @element == other.wd
75
75
  end
76
76
  alias_method :eql?, :==
77
77
 
@@ -82,7 +82,7 @@ module Watir
82
82
 
83
83
  protected
84
84
 
85
- def element
85
+ def wd
86
86
  @element
87
87
  end
88
88
 
@@ -50,10 +50,11 @@ module Watir
50
50
 
51
51
  def matches_selector?(element, rx_selector)
52
52
  rx_selector = rx_selector.dup
53
+ tag_name = element.tag_name.downcase
53
54
 
54
55
  [:value, :caption].each do |key|
55
56
  if rx_selector.has_key?(key)
56
- correct_key = element.tag_name == 'button' ? :text : :value
57
+ correct_key = tag_name == 'button' ? :text : :value
57
58
  rx_selector[correct_key] = rx_selector.delete(key)
58
59
  end
59
60
  end
@@ -61,12 +62,12 @@ module Watir
61
62
  super
62
63
  end
63
64
 
64
- def tag_name_matches?(element, _)
65
- !!(/^(input|button)$/ === element.tag_name)
65
+ def tag_name_matches?(tag_name, _)
66
+ !!(/^(input|button)$/ === tag_name)
66
67
  end
67
68
 
68
69
  def validate_element(element)
69
- return if element.tag_name == "input" && !Button::VALID_TYPES.include?(element.attribute(:type))
70
+ return if element.tag_name.downcase == "input" && !Button::VALID_TYPES.include?(element.attribute(:type))
70
71
  super
71
72
  end
72
73
 
@@ -16,7 +16,7 @@ module Watir
16
16
  selectors.delete(:tag_name) || raise("internal error: no tag_name?!")
17
17
 
18
18
  expressions = %w[./tr]
19
- unless %w[tbody tfoot thead].include?(@wd.tag_name)
19
+ unless %w[tbody tfoot thead].include?(@wd.tag_name.downcase)
20
20
  expressions += %w[./tbody/tr ./thead/tr ./tfoot/tr]
21
21
  end
22
22
 
@@ -168,7 +168,7 @@ module Watir
168
168
  when :text
169
169
  element.text
170
170
  when :tag_name
171
- element.tag_name
171
+ element.tag_name.downcase
172
172
  when :href
173
173
  (href = element.attribute(:href)) && href.strip
174
174
  else
@@ -239,7 +239,7 @@ module Watir
239
239
  return unless selector.empty? # multiple attributes
240
240
 
241
241
  element = @wd.find_element(:id, id)
242
- return if tag_name && !tag_name_matches?(element, tag_name)
242
+ return if tag_name && !tag_name_matches?(element.tag_name.downcase, tag_name)
243
243
 
244
244
  element
245
245
  rescue WebDriver::Error::NoSuchElementError => wde
@@ -250,8 +250,8 @@ module Watir
250
250
  @wd.find_elements(:xpath => ".//*")
251
251
  end
252
252
 
253
- def tag_name_matches?(element, tag_name)
254
- tag_name === element.tag_name
253
+ def tag_name_matches?(element_tag_name, tag_name)
254
+ tag_name === element_tag_name
255
255
  end
256
256
 
257
257
  def valid_attribute?(attribute)
@@ -317,9 +317,11 @@ module Watir
317
317
 
318
318
  def validate_element(element)
319
319
  tn = @selector[:tag_name]
320
- return if tn && !tag_name_matches?(element, tn)
320
+ element_tag_name = element.tag_name.downcase
321
321
 
322
- if element.tag_name == 'input'
322
+ return if tn && !tag_name_matches?(element_tag_name, tn)
323
+
324
+ if element_tag_name == 'input'
323
325
  return if @selector[:type] && @selector[:type] != element.attribute(:type)
324
326
  end
325
327
 
@@ -46,9 +46,11 @@ module Watir
46
46
  def matches_selector?(element, rx_selector)
47
47
  rx_selector = rx_selector.dup
48
48
 
49
+ tag_name = element.tag_name.downcase
50
+
49
51
  [:text, :value, :label].each do |key|
50
52
  if rx_selector.has_key?(key)
51
- correct_key = element.tag_name == 'input' ? :value : :text
53
+ correct_key = tag_name == 'input' ? :value : :text
52
54
  rx_selector[correct_key] = rx_selector.delete(key)
53
55
  end
54
56
  end
@@ -58,8 +60,8 @@ module Watir
58
60
 
59
61
  VALID_TEXT_FIELD_TAGS = %w[input textarea]
60
62
 
61
- def tag_name_matches?(element, _)
62
- VALID_TEXT_FIELD_TAGS.include?(element.tag_name)
63
+ def tag_name_matches?(tag_name, _)
64
+ VALID_TEXT_FIELD_TAGS.include?(tag_name)
63
65
  end
64
66
  end # TextFieldLocator
65
67
  end # Watir
@@ -1,3 +1,3 @@
1
1
  module Watir
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -9,7 +9,7 @@ module Watir
9
9
 
10
10
  def element_by_xpath(xpath)
11
11
  e = wd.find_element(:xpath, xpath)
12
- Watir.element_class_for(e.tag_name).new(self, :element => e)
12
+ Watir.element_class_for(e.tag_name.downcase).new(self, :element => e)
13
13
  rescue WebDriver::Error::NoSuchElementError
14
14
  Element.new(self, :xpath => xpath)
15
15
  end
@@ -20,7 +20,7 @@ module Watir
20
20
 
21
21
  def elements_by_xpath(xpath)
22
22
  wd.find_elements(:xpath, xpath).map do |e|
23
- Watir.element_class_for(e.tag_name).new(self, :element => e)
23
+ Watir.element_class_for(e.tag_name.downcase).new(self, :element => e)
24
24
  end
25
25
  end
26
26
 
data/spec/browser_spec.rb CHANGED
@@ -66,7 +66,7 @@ describe Watir::Browser do
66
66
  end
67
67
  end
68
68
 
69
- bug "http://github.com/jarib/watirspec/issues/issue/8", [:webdriver, :ie], [:webdriver, :chrome] do
69
+ not_compliant_on [:webdriver, :chrome] do
70
70
  it "raises an error when trying to interact with a closed browser" do
71
71
  b = WatirSpec.new_browser
72
72
  b.goto(WatirSpec.files + "/definition_lists.html")
@@ -108,7 +108,7 @@ describe Watir::Browser do
108
108
  end
109
109
 
110
110
  describe "#ready_state" do
111
- it "gets the documents readyState property" do
111
+ it "gets the document's readyState property" do
112
112
  browser.should_receive(:execute_script).with('return document.readyState')
113
113
  browser.ready_state
114
114
  end
data/spec/element_spec.rb CHANGED
@@ -5,8 +5,8 @@ describe Watir::Element do
5
5
  describe "#send_keys" do
6
6
  it "sends keystrokes to the element" do
7
7
  browser.goto("file://" + File.expand_path("html/keylogger.html", File.dirname(__FILE__)))
8
- browser.div(:id, 'receiver').send_keys("hello world")
9
- browser.div(:id, 'output').ps.size.should == 11
8
+ browser.element(:id, 'receiver').send_keys("hello world")
9
+ browser.element(:id, 'output').ps.size.should == 11
10
10
  end
11
11
  end
12
12
 
@@ -9,7 +9,7 @@
9
9
  </script>
10
10
  </head>
11
11
  <body>
12
- <div id="receiver" onkeypress="log(this)">Receiver</div>
12
+ <input type="text" id="receiver" onkeydown="log(this)">
13
13
  <div id="output"></div>
14
14
  </body>
15
15
  </html>
@@ -8,6 +8,12 @@ WatirSpec.implementation do |imp|
8
8
  imp.browser_class = Watir::Browser
9
9
  imp.browser_args = [browser]
10
10
 
11
+ case browser
12
+ when :chromedriver
13
+ # assumes the chromedriver server is running on the default port
14
+ imp.browser_args = [:remote, {:url => "http://localhost:9515"}]
15
+ end
16
+
11
17
  imp.guard_proc = lambda { |args|
12
18
  args.any? { |arg| arg == name || arg == [name, browser] }
13
19
  }
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_dependency "selenium-webdriver", '>= 0.1.2'
22
+ s.add_dependency "selenium-webdriver", '>= 0.1.4'
23
23
 
24
24
  s.add_development_dependency "rspec", "~> 2.3.0"
25
25
  s.add_development_dependency "yard", "~> 0.6"
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: watir-webdriver
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.0
5
+ version: 0.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jari Bakken
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-08 00:00:00 +01:00
13
+ date: 2011-03-21 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -21,7 +21,7 @@ dependencies:
21
21
  requirements:
22
22
  - - ">="
23
23
  - !ruby/object:Gem::Version
24
- version: 0.1.2
24
+ version: 0.1.4
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
27
  - !ruby/object:Gem::Dependency
@@ -138,7 +138,6 @@ files:
138
138
  - lib/watir-webdriver/extensions/alerts.rb
139
139
  - lib/watir-webdriver/extensions/nokogiri.rb
140
140
  - lib/watir-webdriver/extensions/performance.rb
141
- - lib/watir-webdriver/extensions/wait.rb
142
141
  - lib/watir-webdriver/html.rb
143
142
  - lib/watir-webdriver/html/generator.rb
144
143
  - lib/watir-webdriver/html/idl_sorter.rb
@@ -197,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
196
  requirements: []
198
197
 
199
198
  rubyforge_project: watir-webdriver
200
- rubygems_version: 1.5.0
199
+ rubygems_version: 1.5.2
201
200
  signing_key:
202
201
  specification_version: 3
203
202
  summary: Watir on WebDriver
@@ -1 +0,0 @@
1
- warn "wait helpers are now loaded by default, please remove require of 'watir-webdriver/extensions/wait'"