watir-webdriver 0.5.0 → 0.5.1

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.
@@ -9,6 +9,7 @@ require 'watir-webdriver/window'
9
9
  require 'watir-webdriver/has_window'
10
10
  require 'watir-webdriver/atoms'
11
11
  require 'watir-webdriver/container'
12
+ require 'watir-webdriver/cookies'
12
13
  require 'watir-webdriver/locators/element_locator'
13
14
  require 'watir-webdriver/locators/button_locator'
14
15
  require 'watir-webdriver/locators/text_field_locator'
@@ -88,9 +88,14 @@ module Watir
88
88
  alias_method :quit, :close # TODO: close vs quit
89
89
 
90
90
  def clear_cookies
91
+ warn 'Browser#clear_cookies is deprecated and replaced by Browser#cookies (i.e. browser.cookies.clear)'
91
92
  @driver.manage.delete_all_cookies
92
93
  end
93
94
 
95
+ def cookies
96
+ @cookies ||= Cookies.new driver.manage
97
+ end
98
+
94
99
  def text
95
100
  @driver.find_element(:tag_name, "body").text
96
101
  end
@@ -0,0 +1,40 @@
1
+ module Watir
2
+ class Cookies
3
+ def initialize(control)
4
+ @control = control
5
+ end
6
+
7
+ def to_a
8
+ @control.all_cookies.each do |e|
9
+ e[:expires] = to_time(e[:expires]) if e[:expires]
10
+ end
11
+ end
12
+
13
+ def add(name, value, opts = {})
14
+ @control.add_cookie :name => name,
15
+ :value => value,
16
+ :secure => opts[:secure],
17
+ :path => opts[:path],
18
+ :expires => opts[:expires]
19
+ end
20
+
21
+ def delete(name)
22
+ @control.delete_cookie(name)
23
+ end
24
+
25
+ def clear
26
+ @control.delete_all_cookies
27
+ end
28
+
29
+ private
30
+
31
+ def to_time(dt)
32
+ if dt.respond_to?(:to_time)
33
+ dt.to_time
34
+ else
35
+ Time.local t.year, t.month, t.day, t.hour, t.min, t.sec
36
+ end
37
+ end
38
+ end
39
+ end
40
+
@@ -1,3 +1,3 @@
1
1
  module Watir
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -1,32 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Watir
3
3
  module XpathSupport
4
- include Selenium
5
-
6
- #
7
- # Find the first element matching the given XPath
8
- #
9
-
10
- def element_by_xpath(xpath)
11
- warn 'element_by_xpath is deprecated and replaced by .element(:xpath, ...)'
12
-
13
- e = wd.find_element(:xpath, xpath)
14
- Watir.element_class_for(e.tag_name.downcase).new(self, :element => e)
15
- rescue WebDriver::Error::NoSuchElementError
16
- Element.new(self, :xpath => xpath)
17
- end
18
-
19
- #
20
- # Find all elements matching the given XPath
21
- #
22
-
23
- def elements_by_xpath(xpath)
24
- warn 'elements_by_xpath is deprecated and replaced by .elements(:xpath, ...)'
25
-
26
- wd.find_elements(:xpath, xpath).map do |e|
27
- Watir.element_class_for(e.tag_name.downcase).new(self, :element => e)
28
- end
29
- end
30
4
 
31
5
  def self.escape(value)
32
6
  if value.include? "'"
@@ -38,5 +12,6 @@ module Watir
38
12
  "'#{value}'"
39
13
  end
40
14
  end
15
+
41
16
  end # XpathSupport
42
17
  end # Watir
data/spec/alert_spec.rb CHANGED
@@ -3,7 +3,7 @@ require "watir-webdriver/extensions/alerts"
3
3
 
4
4
  describe "AlertHelper" do
5
5
  before do
6
- browser.goto("file://" + File.expand_path("html/alerts.html", File.dirname(__FILE__)))
6
+ browser.goto WatirSpec.url_for("alerts.html", :needs_server => true)
7
7
  end
8
8
 
9
9
  it "handles an alert()" do
data/spec/browser_spec.rb CHANGED
@@ -21,7 +21,7 @@ describe Watir::Browser do
21
21
  end
22
22
 
23
23
  describe "#execute_script" do
24
- before { browser.goto(WatirSpec.files + "/definition_lists.html") }
24
+ before { browser.goto WatirSpec.url_for("definition_lists.html") }
25
25
 
26
26
  it "wraps elements as Watir objects" do
27
27
  returned = browser.execute_script("return document.body")
@@ -49,14 +49,14 @@ describe Watir::Browser do
49
49
 
50
50
  describe "#send_key{,s}" do
51
51
  it "sends keystrokes to the active element" do
52
- browser.goto WatirSpec.files + "/forms_with_input_elements.html"
52
+ browser.goto WatirSpec.url_for "forms_with_input_elements.html"
53
53
 
54
54
  browser.send_keys "hello"
55
55
  browser.text_field(:id => "new_user_first_name").value.should == "hello"
56
56
  end
57
57
 
58
58
  it "sends keys to a frame" do
59
- browser.goto WatirSpec.files + "/frames.html"
59
+ browser.goto WatirSpec.url_for "frames.html"
60
60
  tf = browser.frame.text_field(:id => "senderElement")
61
61
  tf.clear
62
62
 
@@ -68,7 +68,7 @@ describe Watir::Browser do
68
68
 
69
69
  it "raises an error when trying to interact with a closed browser" do
70
70
  b = WatirSpec.new_browser
71
- b.goto(WatirSpec.files + "/definition_lists.html")
71
+ b.goto WatirSpec.url_for "definition_lists.html"
72
72
  b.close
73
73
 
74
74
  lambda { b.dl(:id => "experience-list").id }.should raise_error(Error, "browser was closed")
data/spec/click_spec.rb CHANGED
@@ -3,7 +3,7 @@ require File.expand_path('../watirspec/spec_helper', __FILE__)
3
3
  describe Watir::Element do
4
4
  describe "#click" do
5
5
  before {
6
- browser.goto('file://' + File.expand_path('../html/clicks.html', __FILE__))
6
+ browser.goto WatirSpec.url_for('clicks.html', :needs_server => true)
7
7
  }
8
8
 
9
9
  let(:clicker) { browser.element(:id => "click-logger") }
data/spec/element_spec.rb CHANGED
@@ -4,7 +4,7 @@ describe Watir::Element do
4
4
 
5
5
  describe '#present?' do
6
6
  before do
7
- browser.goto('file://' + File.expand_path('html/wait.html', File.dirname(__FILE__)))
7
+ browser.goto(WatirSpec.url_for("wait.html", :needs_server => true))
8
8
  end
9
9
 
10
10
  it 'returns true if the element exists and is visible' do
@@ -32,7 +32,7 @@ describe Watir::Element do
32
32
 
33
33
  describe "#exists?" do
34
34
  it "should not propagate ObsoleteElementErrors" do
35
- browser.goto 'file://' + File.expand_path('../html/removed_element.html', __FILE__)
35
+ browser.goto WatirSpec.url_for('removed_element.html', :needs_server => true)
36
36
 
37
37
  button = browser.button(:id => "remove-button")
38
38
  element = browser.div(:id => "text")
@@ -46,7 +46,7 @@ describe Watir::Element do
46
46
  describe "#hover" do
47
47
  not_compliant_on [:webdriver, :firefox, :synthesized_events], [:webdriver, :ie] do
48
48
  it "should hover over the element" do
49
- browser.goto 'file://' + File.expand_path('../html/hover.html', __FILE__)
49
+ browser.goto WatirSpec.url_for('hover.html', :needs_server => true)
50
50
  link = browser.a
51
51
 
52
52
  link.style("font-size").should == "10px"
@@ -9,6 +9,9 @@ class ImplementationConfig
9
9
  set_webdriver
10
10
  set_browser_args
11
11
  set_guard_proc
12
+ add_html_routes
13
+
14
+ WatirSpec.always_use_server = mobile?
12
15
  end
13
16
 
14
17
  private
@@ -29,6 +32,10 @@ class ImplementationConfig
29
32
  end
30
33
  end
31
34
 
35
+ def mobile?
36
+ [:android, :iphone].include? browser
37
+ end
38
+
32
39
  def set_guard_proc
33
40
  matching_guards = [
34
41
  :webdriver, # guard only applies to webdriver
@@ -77,6 +84,13 @@ class ImplementationConfig
77
84
  @imp.browser_args = [:chrome, opts]
78
85
  end
79
86
 
87
+ def add_html_routes
88
+ glob = File.expand_path("../html/*.html", __FILE__)
89
+ Dir[glob].each do |path|
90
+ WatirSpec::Server.get("/#{File.basename path}") { File.read(path) }
91
+ end
92
+ end
93
+
80
94
  def browser
81
95
  @browser ||= (ENV['WATIR_WEBDRIVER_BROWSER'] || :firefox).to_sym
82
96
  end
data/spec/input_spec.rb CHANGED
@@ -3,7 +3,7 @@ require File.expand_path('watirspec/spec_helper', File.dirname(__FILE__))
3
3
  describe Watir::Input do
4
4
 
5
5
  before do
6
- browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
6
+ browser.goto WatirSpec.url_for("forms_with_input_elements.html")
7
7
  end
8
8
 
9
9
  describe "#to_subtype" do
@@ -3,7 +3,7 @@ require File.expand_path('watirspec/spec_helper', File.dirname(__FILE__))
3
3
  describe Watir::Browser do
4
4
 
5
5
  before do
6
- browser.goto("file://" + File.expand_path("../html/special_chars.html", __FILE__))
6
+ browser.goto WatirSpec.url_for("special_chars.html", :needs_server => true)
7
7
  end
8
8
 
9
9
  it "finds elements with single quotes" do
data/spec/wait_spec.rb CHANGED
@@ -41,7 +41,7 @@ end
41
41
  describe Watir::Element do
42
42
 
43
43
  before do
44
- browser.goto("file://" + File.expand_path("html/wait.html", File.dirname(__FILE__)))
44
+ browser.goto WatirSpec.url_for("wait.html", :needs_server => true)
45
45
  end
46
46
 
47
47
  describe "#when_present" do
@@ -38,5 +38,15 @@ Please note that watir-webdriver 0.5.0 brings some backwards incompatible change
38
38
  * Finding elements by :class now matches partial class attributes.
39
39
  [ https://github.com/watir/watir-webdriver/issues/36 ]
40
40
 
41
+ Additionally, watir-webdriver 0.5.1 removes the following deprecated methods:
42
+
43
+ * element_by_xpath : replaced by .element(:xpath, '...')
44
+ * elements_by_xpath : replaced by .elements(:xpath, '...')
45
+
46
+ And deprecates the following methods:
47
+
48
+ * Browser#clear_cookies - replaced by Browser#cookies API
49
+ [ https://github.com/watir/watir-webdriver/issues/24 ]
50
+
41
51
  MSG
42
52
  end
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: 11
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 0
10
- version: 0.5.0
9
+ - 1
10
+ version: 0.5.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jari Bakken
@@ -188,6 +188,7 @@ files:
188
188
  - lib/watir-webdriver/browser.rb
189
189
  - lib/watir-webdriver/cell_container.rb
190
190
  - lib/watir-webdriver/container.rb
191
+ - lib/watir-webdriver/cookies.rb
191
192
  - lib/watir-webdriver/element_collection.rb
192
193
  - lib/watir-webdriver/elements/button.rb
193
194
  - lib/watir-webdriver/elements/checkbox.rb
@@ -265,6 +266,16 @@ post_install_message: |+
265
266
  * Finding elements by :class now matches partial class attributes.
266
267
  [ https://github.com/watir/watir-webdriver/issues/36 ]
267
268
 
269
+ Additionally, watir-webdriver 0.5.1 removes the following deprecated methods:
270
+
271
+ * element_by_xpath : replaced by .element(:xpath, '...')
272
+ * elements_by_xpath : replaced by .elements(:xpath, '...')
273
+
274
+ And deprecates the following methods:
275
+
276
+ * Browser#clear_cookies - replaced by Browser#cookies API
277
+ [ https://github.com/watir/watir-webdriver/issues/24 ]
278
+
268
279
  rdoc_options: []
269
280
 
270
281
  require_paths: