capybara-selenium 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e13f900df3097a79309945f402301af811a14400
4
+ data.tar.gz: 354127460453b5f0c61bc32709c49d6d0219c2cf
5
+ SHA512:
6
+ metadata.gz: ecd1f78aee31e15e06142aebf6f08542e0e97ce8d7fdc0bf978f8523502da3e5de33e771d9285f00c94ae695664dc6cecb33a139152df3d387f2731939ea2b63
7
+ data.tar.gz: 97aca416c3e2e84f63c75e8202f10730b67580a897cacc08711a8fc5345203d6e64097060aa751f1d1a9888d172c2fc2523eb53d30d5adfbe5c95aa864cadee8
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ capybara_selenium
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capybara_selenium.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 David Saenz Tagarro
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ [![Gem Version](https://badge.fury.io/rb/capybara-selenium.svg)](http://badge.fury.io/rb/capybara-selenium)
2
+ [![Code Climate](https://codeclimate.com/github/dsaenztagarro/capybara-selenium/badges/gpa.svg)](https://codeclimate.com/github/dsaenztagarro/capybara-selenium)
3
+ [![Dependency Status](https://gemnasium.com/dsaenztagarro/capybara-selenium.svg)](https://gemnasium.com/dsaenztagarro/capybara-selenium)
4
+
5
+ # CapybaraSelenium
6
+
7
+ Dead-simple way to make Capybara and Selenium play together
8
+
9
+ ## Roadmap
10
+
11
+ CapybaraSelenium is on its way towards 1.0.0. Please refer to
12
+ [issues](https://github.com/dsaenztagarro/capybara-selenium/issues) for details.
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ gem 'capybara-selenium'
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install capybara-selenium
27
+
28
+ ## Usage
29
+
30
+ Supported applications:
31
+
32
+ - [X] Modular sinatra apps (through config.ru)
33
+ - [ ] Rails apps
34
+
35
+ ```ruby
36
+ # features/support/continous_integration.rb
37
+ module ContinousIntegration
38
+ def app_server(opts = {})
39
+ {
40
+ host: ENV['CI_APP_SERVER_HOST'] || 'localhost',
41
+ port: ENV['CI_APP_SERVER_PORT'] || 8080,
42
+ type: :rack,
43
+ config_ru_path: ENV['CI_APP_SERVER_CONFIG_RU'] || config_ru_path
44
+ }.merge(opts)
45
+ end
46
+
47
+ def selenium_server(opts = {})
48
+ {
49
+ type: :remote,
50
+ url: ENV['CI_SELENIUM_SERVER_URL'] || 'http://127.0.0.1:4444/wd/hub',
51
+ capabilities: {
52
+ browser_name: :firefox
53
+ }
54
+ }.merge(opts)
55
+ end
56
+
57
+ def driver_for(browser_name)
58
+ CapybaraSelenium::GlobalConfigurator.new(
59
+ app_server: app_server,
60
+ selenium_server: selenium_server.merge(
61
+ capabilities: {
62
+ browser_name: browser_name
63
+ })
64
+ ).driver
65
+ end
66
+
67
+ def config_ru_path
68
+ File.expand_path(File.join(__FILE__, '../dummy_app/config.ru'))
69
+ end
70
+ end
71
+
72
+ World(ContinousIntegration)
73
+ ```
74
+
75
+ ## Contributing
76
+
77
+ 1. Fork it ( https://github.com/dsaenztagarro/capybara_selenium/fork )
78
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
79
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
80
+ 4. Push to the branch (`git push origin my-new-feature`)
81
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rubocop/rake_task'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RuboCop::RakeTask.new do |task|
6
+ task.requires << 'rubocop-rspec'
7
+ end
8
+
9
+ RSpec::Core::RakeTask.new :specs do |task|
10
+ task.pattern = Dir['spec/**/*_spec.rb']
11
+ end
12
+
13
+ task default: ['specs']
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capybara_selenium/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'capybara-selenium'
8
+ spec.version = CapybaraSelenium::VERSION
9
+ spec.authors = ['David Saenz Tagarro']
10
+ spec.email = ['david.saenz.tagarro@gmail.com']
11
+ spec.summary = %q{Dead-simple way to make Capybara and Selenium play together }
12
+ spec.description = %q{}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'capybara'
22
+ spec.add_runtime_dependency 'selenium-webdriver'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.6'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'rspec'
27
+ spec.add_development_dependency 'codeclimate-test-reporter'
28
+ spec.add_development_dependency 'simplecov'
29
+ spec.add_development_dependency 'coveralls'
30
+ spec.add_development_dependency 'rubocop'
31
+ spec.add_development_dependency 'reek'
32
+ spec.add_development_dependency 'cane'
33
+ end
@@ -0,0 +1,39 @@
1
+ require 'capybara_selenium/version'
2
+ require 'capybara_selenium/app_server'
3
+ require 'capybara_selenium/selenium_server'
4
+
5
+ require 'active_support/inflector'
6
+
7
+ # Helpers for initializing selenium drivers
8
+ module CapybaraSelenium
9
+ # Class for configuring capybara and selenium in order to instance the
10
+ # desired driver.
11
+ class GlobalConfigurator
12
+ include AppServer
13
+ include SeleniumServer
14
+
15
+ def initialize(opts = {})
16
+ check_options(opts)
17
+ @app_server = configurator_for :app_server, opts
18
+ @selenium_server = configurator_for :selenium_server, opts
19
+ end
20
+
21
+ def driver
22
+ @app_server.apply
23
+ @selenium_server.apply
24
+ end
25
+
26
+ private
27
+
28
+ def check_options(opts)
29
+ fail 'App Server config missing' unless opts[:app_server]
30
+ fail 'Selenium Server config missing' unless opts[:selenium_server]
31
+ end
32
+
33
+ def configurator_for(*args)
34
+ configurator_type = args.shift
35
+ opts = args.first[configurator_type]
36
+ send "#{configurator_type}_configurator", opts
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,42 @@
1
+ module CapybaraSelenium
2
+ # Responsible for generating an application server object that applies the
3
+ # configuration needed
4
+ module AppServer
5
+ # Base Class for applying to Capybara the configuration of an App Server
6
+ class BaseConfigurator
7
+ attr_accessor :server_host, :server_port, :app_type
8
+
9
+ def initialize(opts = {})
10
+ @server_host = opts[:host] || 'localhost'
11
+ @server_port = opts[:port] || 5000
12
+ @app_type = opts[:type] || :rack
13
+ @opts = opts
14
+ end
15
+
16
+ def apply
17
+ Capybara.server_host = @server_host
18
+ Capybara.server_port = @server_port
19
+ Capybara.app_host = "http://#{@server_host}:#{@server_port}"
20
+ end
21
+ end
22
+
23
+ # Class responsible for applying to Capybara the configuration of a Rack
24
+ # Web Application
25
+ class RackAppConfigurator < BaseConfigurator
26
+ def apply
27
+ super
28
+ path = @opts[:config_ru_path]
29
+ fail 'Invalid config.ru file path' unless File.exist? path
30
+ # require 'pry'
31
+ # binding.pry
32
+ Capybara.app = Rack::Builder.parse_file(path).first
33
+ end
34
+ end
35
+
36
+ def app_server_configurator(opts)
37
+ ('CapybaraSelenium::AppServer::' \
38
+ "#{ActiveSupport::Inflector.classify(opts[:type])}AppConfigurator")
39
+ .constantize.new(opts)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,71 @@
1
+ module CapybaraSelenium
2
+ # Module for applying to Capybara configuration for Selenium Server
3
+ module SeleniumServer
4
+ # Class for applying to Capybara configuration for Selenium Server
5
+ class BaseConfigurator
6
+ attr_accessor :browser_name
7
+
8
+ def initialize(opts = {})
9
+ @browser_name = opts[:capabilities][:browser_name] || 'firefox'
10
+ @capabilities = opts[:capabilities] || {}
11
+ end
12
+
13
+ private
14
+
15
+ # @return [] The desired capabilities for the browser
16
+ def desired_capabilities
17
+ return @desired_capabilities if @desired_capabilities
18
+ @desired_capabilities = Selenium::WebDriver::Remote::Capabilities
19
+ .send(browser_name)
20
+ # @capabilities.keys.each do |key|
21
+ # @desired_capabilities.send "#{key}=", @capabilities[key]
22
+ # end
23
+ end
24
+
25
+ def default_capabilities
26
+ {
27
+ version: 'ANY',
28
+ platform: 'ANY'
29
+ }
30
+ end
31
+
32
+ def method_missing(method)
33
+ capability = desired_capabilities[method]
34
+ return capability if capability
35
+ fail
36
+ end
37
+ end
38
+
39
+ # Applies Capybara specific configuration for selenium remote server
40
+ class SeleniumRemoteConfigurator < BaseConfigurator
41
+ attr_accessor :server_url
42
+
43
+ def initialize(opts)
44
+ super
45
+ @server_url = opts[:server_url] || 'http://127.0.0.1:4444/wd/hub'
46
+ end
47
+
48
+ def apply
49
+ Capybara.current_driver = driver_name
50
+ Capybara.javascript_driver = driver_name
51
+ Capybara.register_driver(driver_name) do |app|
52
+ Capybara::Selenium::Driver.new(
53
+ app,
54
+ browser: :remote,
55
+ url: server_url,
56
+ desired_capabilities: desired_capabilities)
57
+ end
58
+ end
59
+
60
+ def driver_name
61
+ "#{browser_name}_#{version}_#{platform}"
62
+ end
63
+ end
64
+
65
+ def selenium_server_configurator(opts)
66
+ ('CapybaraSelenium::SeleniumServer::' \
67
+ "Selenium#{ActiveSupport::Inflector.classify(opts[:type])}Configurator")
68
+ .constantize.new(opts)
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,3 @@
1
+ module CapybaraSelenium
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,210 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capybara-selenium
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - David Saenz Tagarro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capybara
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: selenium-webdriver
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: codeclimate-test-reporter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: reek
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: cane
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: ''
168
+ email:
169
+ - david.saenz.tagarro@gmail.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".gitignore"
175
+ - ".ruby-gemset"
176
+ - ".ruby-version"
177
+ - Gemfile
178
+ - LICENSE.txt
179
+ - README.md
180
+ - Rakefile
181
+ - capybara_selenium.gemspec
182
+ - lib/capybara_selenium.rb
183
+ - lib/capybara_selenium/app_server.rb
184
+ - lib/capybara_selenium/selenium_server.rb
185
+ - lib/capybara_selenium/version.rb
186
+ homepage: ''
187
+ licenses:
188
+ - MIT
189
+ metadata: {}
190
+ post_install_message:
191
+ rdoc_options: []
192
+ require_paths:
193
+ - lib
194
+ required_ruby_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ required_rubygems_version: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - ">="
202
+ - !ruby/object:Gem::Version
203
+ version: '0'
204
+ requirements: []
205
+ rubyforge_project:
206
+ rubygems_version: 2.2.2
207
+ signing_key:
208
+ specification_version: 4
209
+ summary: Dead-simple way to make Capybara and Selenium play together
210
+ test_files: []