capybara-webkit 0.6.1 → 0.7.0

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.
@@ -0,0 +1,7 @@
1
+ appraise "1.0" do
2
+ gem "capybara", "~> 1.0.0"
3
+ end
4
+
5
+ appraise "1.1" do
6
+ gem "capybara", "~> 1.1.0"
7
+ end
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
1
  source "http://rubygems.org"
2
- gem "rspec", '~> 2.6.0', :require => false
3
- gem "capybara"
4
- gem "sinatra", :require => false
5
- gem "mini_magick", :require => false
6
- gem 'rake'
2
+ gemspec
3
+ # gem "appraisal"
4
+ # gem "rspec", '~> 2.6.0', :require => false
5
+ # gem "capybara"
6
+ # gem "sinatra", :require => false
7
+ # gem "mini_magick", :require => false
8
+ # gem 'rake'
@@ -1,24 +1,33 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ capybara-webkit (0.7.0)
5
+ capybara (< 1.2, >= 1.0.0)
6
+
1
7
  GEM
2
8
  remote: http://rubygems.org/
3
9
  specs:
4
- capybara (1.0.0)
10
+ appraisal (0.3.8)
11
+ bundler
12
+ rake
13
+ capybara (1.1.1)
5
14
  mime-types (>= 1.16)
6
15
  nokogiri (>= 1.3.3)
7
16
  rack (>= 1.0.0)
8
17
  rack-test (>= 0.5.4)
9
- selenium-webdriver (~> 0.2.0)
18
+ selenium-webdriver (~> 2.0)
10
19
  xpath (~> 0.1.4)
11
- childprocess (0.1.9)
20
+ childprocess (0.2.2)
12
21
  ffi (~> 1.0.6)
13
22
  diff-lcs (1.1.2)
14
23
  ffi (1.0.9)
15
- json_pure (1.5.3)
24
+ json_pure (1.6.1)
16
25
  mime-types (1.16)
17
26
  mini_magick (3.2.1)
18
27
  subexec (~> 0.0.4)
19
28
  nokogiri (1.5.0)
20
- rack (1.3.0)
21
- rack-test (0.6.0)
29
+ rack (1.3.2)
30
+ rack-test (0.6.1)
22
31
  rack (>= 1.0)
23
32
  rake (0.9.2)
24
33
  rspec (2.6.0)
@@ -30,8 +39,8 @@ GEM
30
39
  diff-lcs (~> 1.1.2)
31
40
  rspec-mocks (2.6.0)
32
41
  rubyzip (0.9.4)
33
- selenium-webdriver (0.2.2)
34
- childprocess (>= 0.1.9)
42
+ selenium-webdriver (2.7.0)
43
+ childprocess (>= 0.2.1)
35
44
  ffi (>= 1.0.7)
36
45
  json_pure
37
46
  rubyzip
@@ -47,7 +56,8 @@ PLATFORMS
47
56
  ruby
48
57
 
49
58
  DEPENDENCIES
50
- capybara
59
+ appraisal
60
+ capybara-webkit!
51
61
  mini_magick
52
62
  rake
53
63
  rspec (~> 2.6.0)
data/README.md CHANGED
@@ -3,36 +3,13 @@ capybara-webkit
3
3
 
4
4
  A [capybara](https://github.com/jnicklas/capybara) driver that uses [WebKit](http://webkit.org) via [QtWebKit](http://doc.qt.nokia.com/4.7/qtwebkit.html).
5
5
 
6
- Dependent on Qt
7
- ---------------
6
+ Qt Dependency
7
+ -------------
8
8
 
9
- capybara-webkit depends on a WebKit implementation from Qt, a cross-platform development toolkit. You'll need to download the Qt libraries to build and install the gem.
10
-
11
- OS X Lion 10.7:
12
-
13
- Install Qt via [homebrew](http://mxcl.github.com/homebrew/)(can take more than an hour) using:
14
-
15
- brew install qt --build-from-source
16
-
17
- OS X < 10.7:
18
-
19
- [Download the non-debug Cocoa package](http://qt.nokia.com/downloads/qt-for-open-source-cpp-development-on-mac-os-x).
20
-
21
- Ubuntu:
22
-
23
- apt-get install libqt4-dev
24
-
25
- Fedora:
26
-
27
- yum install qt-webkit-devel
28
-
29
- Gentoo Linux:
30
-
31
- emerge x11-libs/qt-webkit
32
-
33
- Other Linux distributions:
34
-
35
- [Download this package](http://qt.nokia.com/downloads/linux-x11-cpp).
9
+ capybara-webkit depends on a WebKit implementation from Qt, a cross-platform
10
+ development toolkit. You'll need to download the Qt libraries to build and
11
+ install the gem. You can find instructions for downloading and installing QT on
12
+ the [capybara-webkit wiki](https://github.com/thoughtbot/capybara-webkit/wiki/Installing-QT)
36
13
 
37
14
  CI
38
15
  --
@@ -73,11 +50,9 @@ The names and logos for thoughtbot are trademarks of thoughtbot, inc.
73
50
  Notes
74
51
  -----
75
52
 
76
- This capybara WebKit driver will listen on port 8200, this may conflict
77
- with other services.
53
+ capybara-webkit will listen on port 8200. This may conflict with other services.
78
54
 
79
55
  License
80
56
  -------
81
57
 
82
- capybara-webkit is Copyright © 2011 thoughtbot, inc. It is free software, and may be redistributed under the terms specified in the LICENSE file.
83
-
58
+ capybara-webkit is Copyright (c) 2011 thoughtbot, inc. It is free software, and may be redistributed under the terms specified in the LICENSE file.
data/Rakefile CHANGED
@@ -3,6 +3,7 @@ require 'bundler/setup'
3
3
  require 'rspec/core/rake_task'
4
4
  require 'rake/gempackagetask'
5
5
  require 'capybara_webkit_builder'
6
+ require 'appraisal'
6
7
 
7
8
  desc "Generate a Makefile using qmake"
8
9
  file 'Makefile' do
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "capybara-webkit"
3
- s.version = "0.6.1"
3
+ s.version = "0.7.0"
4
4
  s.authors = ["thoughtbot", "Joe Ferris", "Jason Morrison", "Tristan Dunn",
5
5
  "Joshua Clayton", "Yuichi Tateno", "Aaron Gibralter",
6
6
  "Vasily Reys", "petrushka", "John Bintz", "Chad Pytel",
@@ -13,7 +13,12 @@ Gem::Specification.new do |s|
13
13
  s.require_path = "lib"
14
14
  s.rubygems_version = "1.3.5"
15
15
  s.summary = "Headless Webkit driver for Capybara"
16
- s.add_runtime_dependency "capybara", "~> 1.0.0"
16
+ s.add_runtime_dependency "capybara", [">= 1.0.0", "< 1.2"]
17
+ s.add_development_dependency "rspec", "~> 2.6.0"
18
+ s.add_development_dependency "sinatra"
19
+ s.add_development_dependency "mini_magick"
20
+ s.add_development_dependency "rake"
21
+ s.add_development_dependency "appraisal"
17
22
  s.extensions = "extconf.rb"
18
23
  end
19
24
 
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "capybara", "~> 1.0.0"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,65 @@
1
+ PATH
2
+ remote: /Users/jferris/Source/capybara-webkit
3
+ specs:
4
+ capybara-webkit (0.6.1)
5
+ capybara (< 1.2, >= 1.0.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ appraisal (0.3.8)
11
+ bundler
12
+ rake
13
+ capybara (1.0.1)
14
+ mime-types (>= 1.16)
15
+ nokogiri (>= 1.3.3)
16
+ rack (>= 1.0.0)
17
+ rack-test (>= 0.5.4)
18
+ selenium-webdriver (~> 2.0)
19
+ xpath (~> 0.1.4)
20
+ childprocess (0.2.2)
21
+ ffi (~> 1.0.6)
22
+ diff-lcs (1.1.3)
23
+ ffi (1.0.9)
24
+ json_pure (1.6.1)
25
+ mime-types (1.16)
26
+ mini_magick (3.3)
27
+ subexec (~> 0.1.0)
28
+ nokogiri (1.5.0)
29
+ rack (1.3.3)
30
+ rack-test (0.6.1)
31
+ rack (>= 1.0)
32
+ rake (0.9.2)
33
+ rspec (2.6.0)
34
+ rspec-core (~> 2.6.0)
35
+ rspec-expectations (~> 2.6.0)
36
+ rspec-mocks (~> 2.6.0)
37
+ rspec-core (2.6.4)
38
+ rspec-expectations (2.6.0)
39
+ diff-lcs (~> 1.1.2)
40
+ rspec-mocks (2.6.0)
41
+ rubyzip (0.9.4)
42
+ selenium-webdriver (2.7.0)
43
+ childprocess (>= 0.2.1)
44
+ ffi (>= 1.0.7)
45
+ json_pure
46
+ rubyzip
47
+ sinatra (1.2.6)
48
+ rack (~> 1.1)
49
+ tilt (< 2.0, >= 1.2.2)
50
+ subexec (0.1.0)
51
+ tilt (1.3.3)
52
+ xpath (0.1.4)
53
+ nokogiri (~> 1.3)
54
+
55
+ PLATFORMS
56
+ ruby
57
+
58
+ DEPENDENCIES
59
+ appraisal
60
+ capybara (~> 1.0.0)
61
+ capybara-webkit!
62
+ mini_magick
63
+ rake
64
+ rspec (~> 2.6.0)
65
+ sinatra
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "capybara", "~> 1.1.0"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,65 @@
1
+ PATH
2
+ remote: /Users/jferris/Source/capybara-webkit
3
+ specs:
4
+ capybara-webkit (0.6.1)
5
+ capybara (< 1.2, >= 1.0.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ appraisal (0.3.8)
11
+ bundler
12
+ rake
13
+ capybara (1.1.1)
14
+ mime-types (>= 1.16)
15
+ nokogiri (>= 1.3.3)
16
+ rack (>= 1.0.0)
17
+ rack-test (>= 0.5.4)
18
+ selenium-webdriver (~> 2.0)
19
+ xpath (~> 0.1.4)
20
+ childprocess (0.2.2)
21
+ ffi (~> 1.0.6)
22
+ diff-lcs (1.1.3)
23
+ ffi (1.0.9)
24
+ json_pure (1.6.1)
25
+ mime-types (1.16)
26
+ mini_magick (3.3)
27
+ subexec (~> 0.1.0)
28
+ nokogiri (1.5.0)
29
+ rack (1.3.3)
30
+ rack-test (0.6.1)
31
+ rack (>= 1.0)
32
+ rake (0.9.2)
33
+ rspec (2.6.0)
34
+ rspec-core (~> 2.6.0)
35
+ rspec-expectations (~> 2.6.0)
36
+ rspec-mocks (~> 2.6.0)
37
+ rspec-core (2.6.4)
38
+ rspec-expectations (2.6.0)
39
+ diff-lcs (~> 1.1.2)
40
+ rspec-mocks (2.6.0)
41
+ rubyzip (0.9.4)
42
+ selenium-webdriver (2.7.0)
43
+ childprocess (>= 0.2.1)
44
+ ffi (>= 1.0.7)
45
+ json_pure
46
+ rubyzip
47
+ sinatra (1.2.6)
48
+ rack (~> 1.1)
49
+ tilt (< 2.0, >= 1.2.2)
50
+ subexec (0.1.0)
51
+ tilt (1.3.3)
52
+ xpath (0.1.4)
53
+ nokogiri (~> 1.3)
54
+
55
+ PLATFORMS
56
+ ruby
57
+
58
+ DEPENDENCIES
59
+ appraisal
60
+ capybara (~> 1.1.0)
61
+ capybara-webkit!
62
+ mini_magick
63
+ rake
64
+ rspec (~> 2.6.0)
65
+ sinatra
@@ -1,11 +1 @@
1
- require "capybara"
2
- require "capybara/driver/webkit"
3
-
4
- Capybara.register_driver :webkit do |app|
5
- Capybara::Driver::Webkit.new(app)
6
- end
7
-
8
- Capybara.register_driver :webkit_debug do |app|
9
- browser = Capybara::Driver::Webkit::Browser.new(:socket_class => Capybara::Driver::Webkit::SocketDebugger)
10
- Capybara::Driver::Webkit.new(app, :browser => browser)
11
- end
1
+ require "capybara/webkit"
@@ -10,6 +10,9 @@ class Capybara::Driver::Webkit
10
10
  class WebkitNoResponseError < StandardError
11
11
  end
12
12
 
13
+ class NodeNotAttachedError < Capybara::ElementNotFound
14
+ end
15
+
13
16
  attr_reader :browser
14
17
 
15
18
  def initialize(app, options={})
@@ -86,6 +86,18 @@ class Capybara::Driver::Webkit
86
86
  command "Render", path, width, height
87
87
  end
88
88
 
89
+ def set_cookie(cookie)
90
+ command "SetCookie", cookie
91
+ end
92
+
93
+ def clear_cookies
94
+ command "ClearCookies"
95
+ end
96
+
97
+ def get_cookies
98
+ command("GetCookies").lines.map{ |line| line.strip }.select{ |line| !line.empty? }
99
+ end
100
+
89
101
  private
90
102
 
91
103
  def start_server
@@ -1,7 +1,10 @@
1
1
  class Capybara::Driver::Webkit
2
2
  class Node < Capybara::Driver::Node
3
+ NBSP = "\xC2\xA0"
4
+ NBSP.force_encoding("UTF-8") if NBSP.respond_to?(:force_encoding)
5
+
3
6
  def text
4
- invoke "text"
7
+ invoke("text").gsub(NBSP, ' ').gsub(/\s+/u, ' ').strip
5
8
  end
6
9
 
7
10
  def [](name)
@@ -85,7 +88,23 @@ class Capybara::Driver::Webkit
85
88
  end
86
89
 
87
90
  def invoke(name, *args)
88
- browser.command "Node", name, native, *args
91
+ if allow_unattached_nodes? || attached?
92
+ browser.command "Node", name, native, *args
93
+ else
94
+ raise Capybara::Driver::Webkit::NodeNotAttachedError
95
+ end
96
+ end
97
+
98
+ def allow_unattached_nodes?
99
+ !automatic_reload?
100
+ end
101
+
102
+ def automatic_reload?
103
+ Capybara.respond_to?(:automatic_reload) && Capybara.automatic_reload
104
+ end
105
+
106
+ def attached?
107
+ browser.command("Node", "isAttached", native) == "true"
89
108
  end
90
109
 
91
110
  def browser
@@ -0,0 +1,11 @@
1
+ require "capybara"
2
+ require "capybara/driver/webkit"
3
+
4
+ Capybara.register_driver :webkit do |app|
5
+ Capybara::Driver::Webkit.new(app)
6
+ end
7
+
8
+ Capybara.register_driver :webkit_debug do |app|
9
+ browser = Capybara::Driver::Webkit::Browser.new(:socket_class => Capybara::Driver::Webkit::SocketDebugger)
10
+ Capybara::Driver::Webkit.new(app, :browser => browser)
11
+ end
@@ -104,6 +104,50 @@ describe Capybara::Driver::Webkit do
104
104
  end
105
105
  end
106
106
 
107
+ context "redirect app" do
108
+ before(:all) do
109
+ @app = lambda do |env|
110
+ if env['PATH_INFO'] == '/target'
111
+ content_type = "<p>#{env['CONTENT_TYPE']}</p>"
112
+ [200, {"Content-Type" => "text/html", "Content-Length" => content_type.length.to_s}, [content_type]]
113
+ elsif env['PATH_INFO'] == '/form'
114
+ body = <<-HTML
115
+ <html>
116
+ <body>
117
+ <form action="/redirect" method="POST" enctype="multipart/form-data">
118
+ <input name="submit" type="submit" />
119
+ </form>
120
+ </body>
121
+ </html>
122
+ HTML
123
+ [200, {"Content-Type" => "text/html", "Content-Length" => body.length.to_s}, [body]]
124
+ else
125
+ [301, {"Location" => "/target"}, [""]]
126
+ end
127
+ end
128
+ end
129
+
130
+ it "should redirect without content type" do
131
+ subject.visit("/form")
132
+ subject.find("//input").first.click
133
+ subject.find("//p").first.text.should == ""
134
+ end
135
+ end
136
+
137
+ context "css app" do
138
+ before(:all) do
139
+ body = "css"
140
+ @app = lambda do |env|
141
+ [200, {"Content-Type" => "text/css", "Content-Length" => body.length.to_s}, [body]]
142
+ end
143
+ end
144
+
145
+ it "renders unsupported content types gracefully" do
146
+ subject.visit("/")
147
+ subject.body.should =~ /css/
148
+ end
149
+ end
150
+
107
151
  context "hello app" do
108
152
  before(:all) do
109
153
  @app = lambda do |env|
@@ -115,6 +159,7 @@ describe Capybara::Driver::Webkit do
115
159
  </style>
116
160
  </head>
117
161
  <body>
162
+ <div class='normalize'>Spaces&nbsp;not&nbsp;normalized&nbsp;</div>
118
163
  <div id="display_none">
119
164
  <div id="invisible">Can't see me</div>
120
165
  </div>
@@ -132,6 +177,13 @@ describe Capybara::Driver::Webkit do
132
177
  end
133
178
  end
134
179
 
180
+ it "handles anchor tags" do
181
+ subject.visit("#test")
182
+ subject.find("//*[contains(., 'hello')]").should_not be_empty
183
+ subject.visit("#test")
184
+ subject.find("//*[contains(., 'hello')]").should_not be_empty
185
+ end
186
+
135
187
  it "finds content after loading a URL" do
136
188
  subject.find("//*[contains(., 'hello')]").should_not be_empty
137
189
  end
@@ -158,6 +210,10 @@ describe Capybara::Driver::Webkit do
158
210
  subject.find("//p").first.text.should == "hello"
159
211
  end
160
212
 
213
+ it "normalizes a node's text" do
214
+ subject.find("//div[contains(@class, 'normalize')]").first.text.should == "Spaces not normalized"
215
+ end
216
+
161
217
  it "returns the current URL" do
162
218
  port = subject.instance_variable_get("@rack_server").port
163
219
  subject.current_url.should == "http://127.0.0.1:#{port}/hello/world?success=true"
@@ -835,6 +891,60 @@ describe Capybara::Driver::Webkit do
835
891
  end
836
892
  end
837
893
 
894
+ context "cookie-based app" do
895
+ before(:all) do
896
+ @cookie = 'cookie=abc; domain=127.0.0.1; path=/'
897
+ @app = lambda do |env|
898
+ request = ::Rack::Request.new(env)
899
+
900
+ body = <<-HTML
901
+ <html><body>
902
+ <p id="cookie">#{request.cookies["cookie"] || ""}</p>
903
+ </body></html>
904
+ HTML
905
+ [200,
906
+ { 'Content-Type' => 'text/html; charset=UTF-8',
907
+ 'Content-Length' => body.length.to_s,
908
+ 'Set-Cookie' => @cookie,
909
+ },
910
+ [body]]
911
+ end
912
+ end
913
+
914
+ def echoed_cookie
915
+ subject.find('id("cookie")').first.text
916
+ end
917
+
918
+ it "remembers the cookie on second visit" do
919
+ echoed_cookie.should == ""
920
+ subject.visit "/"
921
+ echoed_cookie.should == "abc"
922
+ end
923
+
924
+ it "uses a custom cookie" do
925
+ subject.browser.set_cookie @cookie
926
+ subject.visit "/"
927
+ echoed_cookie.should == "abc"
928
+ end
929
+
930
+ it "clears cookies" do
931
+ subject.browser.clear_cookies
932
+ subject.visit "/"
933
+ echoed_cookie.should == ""
934
+ end
935
+
936
+ it "allows enumeration of cookies" do
937
+ cookies = subject.browser.get_cookies
938
+
939
+ cookies.size.should == 1
940
+
941
+ cookie = Hash[cookies[0].split(/\s*;\s*/).map { |x| x.split("=", 2) }]
942
+ cookie["cookie"].should == "abc"
943
+ cookie["domain"].should include "127.0.0.1"
944
+ cookie["path"].should == "/"
945
+ end
946
+ end
947
+
838
948
  context "with socket debugger" do
839
949
  let(:socket_debugger_class){ Capybara::Driver::Webkit::SocketDebugger }
840
950
  let(:browser_with_debugger){
@@ -871,4 +981,36 @@ describe Capybara::Driver::Webkit do
871
981
  driver_with_debugger.find("//*[@id='parent']")
872
982
  end
873
983
  end
984
+
985
+ context "remove node app" do
986
+ before(:all) do
987
+ @app = lambda do |env|
988
+ body = <<-HTML
989
+ <html>
990
+ <div id="parent">
991
+ <p id="removeMe">Hello</p>
992
+ </div>
993
+ </html>
994
+ HTML
995
+ [200,
996
+ { 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
997
+ [body]]
998
+ end
999
+ end
1000
+
1001
+ before { set_automatic_reload false }
1002
+ after { set_automatic_reload true }
1003
+
1004
+ def set_automatic_reload(value)
1005
+ if Capybara.respond_to?(:automatic_reload)
1006
+ Capybara.automatic_reload = value
1007
+ end
1008
+ end
1009
+
1010
+ it "allows removed nodes when reloading is disabled" do
1011
+ node = subject.find("//p[@id='removeMe']").first
1012
+ subject.evaluate_script("document.getElementById('parent').innerHTML = 'Magic'")
1013
+ node.text.should == 'Hello'
1014
+ end
1015
+ end
874
1016
  end