capybara-selenium 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e13f900df3097a79309945f402301af811a14400
4
- data.tar.gz: 354127460453b5f0c61bc32709c49d6d0219c2cf
3
+ metadata.gz: e7b1e32af7160025a7ba412bf91e82e7db92c5b0
4
+ data.tar.gz: 23460a046866acf85a8485c2f496c2038d0730dd
5
5
  SHA512:
6
- metadata.gz: ecd1f78aee31e15e06142aebf6f08542e0e97ce8d7fdc0bf978f8523502da3e5de33e771d9285f00c94ae695664dc6cecb33a139152df3d387f2731939ea2b63
7
- data.tar.gz: 97aca416c3e2e84f63c75e8202f10730b67580a897cacc08711a8fc5345203d6e64097060aa751f1d1a9888d172c2fc2523eb53d30d5adfbe5c95aa864cadee8
6
+ metadata.gz: a6a5849c6b568f26632895a671746f0db3a7b9666750ed8bccf2a4bba8c4b892e1d883f9ea8db6322ab4da9046b2070b2569b03b076db8ede9a15948677bac45
7
+ data.tar.gz: d681950100ef0fa127ab6bdf8939da450d051bb4bc25b27a0e190749d13c7da23e92901a44d954af8a476ab62a01fba9cd2bb82945d348ab8adeff53c412dd9c
@@ -0,0 +1,4 @@
1
+ ## 0.0.2
2
+
3
+ * Complete refactoring for easy modular extension
4
+ * New application and selenium server configuration through configure methods
data/README.md CHANGED
@@ -32,40 +32,53 @@ Supported applications:
32
32
  - [X] Modular sinatra apps (through config.ru)
33
33
  - [ ] Rails apps
34
34
 
35
+ #### Option 1: Using a block in constructor call (Recommended)
36
+
35
37
  ```ruby
36
38
  # 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)
39
+ CapybaraSelenium::Configurator.new do
40
+ rack_app_server.configure do |config|
41
+ config.host = ENV['CI_APP_SERVER_HOST'] || 'localhost'
42
+ config.port = ENV['CI_APP_SERVER_PORT'] || 8080
43
+ config.config_ru_path = File.expand_path(
44
+ File.join(__FILE__, '../web_app/config.ru'))
45
45
  end
46
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)
47
+ remote_selenium_server.configure do |config|
48
+ config.server_url = ENV['CI_SELENIUM_SERVER_URL'] ||
49
+ 'http://127.0.0.1:4444/wd/hub'
50
+ config.capabilities = { browser_name: browser_name }
55
51
  end
52
+ end
53
+ ```
54
+
55
+ #### Option 2: Using instance methods
56
56
 
57
+ ```ruby
58
+ # features/support/continous_integration.rb
59
+ module ContinousIntegration
57
60
  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
61
+ @configurator = CapybaraSelenium::Configurator.new
62
+ configure_rack_app_server
63
+ configure_selenium_server(browser_name)
64
+ @configurator.apply
65
+ end
66
+
67
+ def configure_rack_app_server
68
+ @configurator.rack_app_server.configure do |config|
69
+ config.host = ENV['CI_APP_SERVER_HOST'] || 'localhost'
70
+ config.port = ENV['CI_APP_SERVER_PORT'] || 8080
71
+ config.config_ru_path = File.expand_path(
72
+ File.join(__FILE__, '../web_app/config.ru'))
73
+ end
65
74
  end
66
75
 
67
- def config_ru_path
68
- File.expand_path(File.join(__FILE__, '../dummy_app/config.ru'))
76
+ def configure_selenium_server(browser_name)
77
+ @configurator.remote_selenium_server.configure do |config|
78
+ config.server_url = ENV['CI_SELENIUM_SERVER_URL'] ||
79
+ 'http://127.0.0.1:4444/wd/hub'
80
+ config.capabilities = { browser_name: browser_name }
81
+ end
69
82
  end
70
83
  end
71
84
 
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ['david.saenz.tagarro@gmail.com']
11
11
  spec.summary = %q{Dead-simple way to make Capybara and Selenium play together }
12
12
  spec.description = %q{}
13
- spec.homepage = ''
13
+ spec.homepage = 'https://github.com/dsaenztagarro/capybara-selenium'
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -1,6 +1,9 @@
1
- require 'capybara_selenium/version'
2
- require 'capybara_selenium/app_server'
3
- require 'capybara_selenium/selenium_server'
1
+ require_relative 'capybara_selenium/version'
2
+ require_relative 'capybara_selenium/server/configurator'
3
+ require_relative 'capybara_selenium/app_server/configurator'
4
+ require_relative 'capybara_selenium/app_server/configuration'
5
+ require_relative 'capybara_selenium/selenium_server/configurator'
6
+ require_relative 'capybara_selenium/selenium_server/configuration'
4
7
 
5
8
  require 'active_support/inflector'
6
9
 
@@ -8,32 +11,47 @@ require 'active_support/inflector'
8
11
  module CapybaraSelenium
9
12
  # Class for configuring capybara and selenium in order to instance the
10
13
  # desired driver.
11
- class GlobalConfigurator
14
+ class Configurator
12
15
  include AppServer
13
16
  include SeleniumServer
17
+ attr_reader :driver
14
18
 
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
+ def initialize(&block)
20
+ define_singleton_method(:dispatch, block) if block_given?
19
21
  end
20
22
 
21
- def driver
23
+ def apply
22
24
  @app_server.apply
23
- @selenium_server.apply
25
+ @driver = @selenium_server.apply
26
+ end
27
+
28
+ def method_missing(method, *args, &block)
29
+ if method =~ /(.*)_app_server/
30
+ @app_server ||= configurator :app_server, $1
31
+ elsif method =~ /(.*)_selenium_server/
32
+ @selenium_server ||= configurator :selenium_server, $1
33
+ else
34
+ raise
35
+ end
24
36
  end
25
37
 
26
38
  private
27
39
 
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]
40
+ def configurator(server_type, configurator_type, &block)
41
+ klass = self.class
42
+ server_module = klass.classify(server_type)
43
+ configurator_klass = klass.classify(configurator_type)
44
+ "CapybaraSelenium::#{server_module}::#{configurator_klass}Configurator"
45
+ .constantize.new(configuration(server_module, configurator_klass))
46
+ end
47
+
48
+ def configuration(server_module, klass)
49
+ "CapybaraSelenium::#{server_module}::#{klass}Configuration"
50
+ .constantize.new
31
51
  end
32
52
 
33
- def configurator_for(*args)
34
- configurator_type = args.shift
35
- opts = args.first[configurator_type]
36
- send "#{configurator_type}_configurator", opts
53
+ def self.classify(type)
54
+ ActiveSupport::Inflector.classify(type)
37
55
  end
38
56
  end
39
57
  end
@@ -0,0 +1,11 @@
1
+ module CapybaraSelenium
2
+ module AppServer
3
+ class BaseConfiguration
4
+ attr_accessor :host, :port
5
+ end
6
+
7
+ class RackConfiguration < BaseConfiguration
8
+ attr_accessor :config_ru_path
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ module CapybaraSelenium
2
+ module AppServer
3
+ class BaseConfigurator < Server::Configurator
4
+ def apply
5
+ Capybara.server_host = host
6
+ Capybara.server_port = port
7
+ Capybara.app_host = "http://#{host}:#{port}"
8
+ end
9
+ end
10
+
11
+ # Class responsible for applying to Capybara the configuration of a Rack
12
+ # Web Application
13
+ class RackConfigurator < BaseConfigurator
14
+ def apply
15
+ super
16
+ fail 'Invalid config.ru file path' unless File.exist? config_ru_path
17
+ Capybara.app = Rack::Builder.parse_file(config_ru_path).first
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ module CapybaraSelenium
2
+ module SeleniumServer
3
+ class BaseConfiguration
4
+ attr_accessor :capabilities
5
+ end
6
+
7
+ class RemoteConfiguration < BaseConfiguration
8
+ attr_accessor :server_url
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,36 @@
1
+ module CapybaraSelenium
2
+ module SeleniumServer
3
+ class BaseConfigurator < Server::Configurator
4
+ private
5
+
6
+ def caps(key)
7
+ capabilities[key]
8
+ end
9
+ end
10
+
11
+ class RemoteConfigurator < BaseConfigurator
12
+ def apply
13
+ Capybara.current_driver = driver_name
14
+ Capybara.javascript_driver = driver_name
15
+ Capybara.register_driver(driver_name) do |app|
16
+ Capybara::Selenium::Driver.new(
17
+ app,
18
+ browser: :remote,
19
+ url: server_url,
20
+ desired_capabilities: desired_capabilities)
21
+ end
22
+ end
23
+
24
+ def driver_name
25
+ "#{caps(:browser_name)}_#{caps(:version)}_#{caps(:platform)}"
26
+ end
27
+
28
+ # @return [] The desired capabilities for the browser
29
+ def desired_capabilities
30
+ return @desired_capabilities if @desired_capabilities
31
+ @desired_capabilities = Selenium::WebDriver::Remote::Capabilities
32
+ .send(caps(:browser_name))
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,34 @@
1
+ module CapybaraSelenium
2
+ module Server
3
+ class Configurator
4
+ def initialize(configuration)
5
+ @configuration = configuration
6
+ end
7
+
8
+ def configure(&block)
9
+ @configuration = create_configuration
10
+ block.call @configuration
11
+ end
12
+
13
+ def method_missing(method)
14
+ if @configuration.respond_to? method
15
+ return @configuration.send(method)
16
+ else
17
+ raise
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def create_configuration
24
+ *modules, klass = self.class.to_s.split('::')
25
+ "#{modules.join('::')}::#{type_of(klass)}Configuration"
26
+ .constantize.new
27
+ end
28
+
29
+ def type_of(klass)
30
+ /^(?<type>(.*))Configurator/.match(klass)[:type]
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,3 +1,3 @@
1
1
  module CapybaraSelenium
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-selenium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Saenz Tagarro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-13 00:00:00.000000000 Z
11
+ date: 2014-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -174,16 +174,20 @@ files:
174
174
  - ".gitignore"
175
175
  - ".ruby-gemset"
176
176
  - ".ruby-version"
177
+ - CHANGELOG.md
177
178
  - Gemfile
178
179
  - LICENSE.txt
179
180
  - README.md
180
181
  - Rakefile
181
182
  - capybara_selenium.gemspec
182
183
  - lib/capybara_selenium.rb
183
- - lib/capybara_selenium/app_server.rb
184
- - lib/capybara_selenium/selenium_server.rb
184
+ - lib/capybara_selenium/app_server/configuration.rb
185
+ - lib/capybara_selenium/app_server/configurator.rb
186
+ - lib/capybara_selenium/selenium_server/configuration.rb
187
+ - lib/capybara_selenium/selenium_server/configurator.rb
188
+ - lib/capybara_selenium/server/configurator.rb
185
189
  - lib/capybara_selenium/version.rb
186
- homepage: ''
190
+ homepage: https://github.com/dsaenztagarro/capybara-selenium
187
191
  licenses:
188
192
  - MIT
189
193
  metadata: {}
@@ -203,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
207
  version: '0'
204
208
  requirements: []
205
209
  rubyforge_project:
206
- rubygems_version: 2.2.2
210
+ rubygems_version: 2.4.3
207
211
  signing_key:
208
212
  specification_version: 4
209
213
  summary: Dead-simple way to make Capybara and Selenium play together
@@ -1,42 +0,0 @@
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
@@ -1,71 +0,0 @@
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