initial commit

This commit is contained in:
John Bintz 2012-11-26 11:36:43 -05:00
commit 31bc976139
12 changed files with 191 additions and 0 deletions

17
.gitignore vendored Normal file
View File

@ -0,0 +1,17 @@
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp

4
Gemfile Normal file
View File

@ -0,0 +1,4 @@
source 'https://rubygems.org'
# Specify your gem's dependencies in persistent_selenium.gemspec
gemspec

22
LICENSE Normal file
View File

@ -0,0 +1,22 @@
Copyright (c) 2012 John Bintz
MIT License
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

29
README.md Normal file
View File

@ -0,0 +1,29 @@
# PersistentSelenium
TODO: Write a gem description
## Installation
Add this line to your application's Gemfile:
gem 'persistent_selenium'
And then execute:
$ bundle
Or install it yourself as:
$ gem install persistent_selenium
## Usage
TODO: Write usage instructions here
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

2
Rakefile Normal file
View File

@ -0,0 +1,2 @@
#!/usr/bin/env rake
require "bundler/gem_tasks"

7
bin/persistent_selenium Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env ruby
$: << File.expand_path('../../lib', __FILE__)
require 'persistent_selenium/cli'
PersistentSelenium::CLI.start

View File

@ -0,0 +1,23 @@
require "persistent_selenium/version"
module PersistentSelenium
class << self
attr_writer :port, :browser
def port
@port ||= 9854
end
def browser
@browser ||= :firefox
end
def url
"druby://localhost:#{port}"
end
def configure
yield self
end
end
end

View File

@ -0,0 +1,27 @@
require 'capybara'
require 'capybara/selenium/driver'
module PersistentSelenium
class Browser < Capybara::Selenium::Driver
def initialize(browser_type)
@browser_type = browser_type
end
def browser
@browser ||= Selenium::WebDriver.for(@browser_type)
end
def visit(path)
if !path[/^http/]
path = @app_host + path
end
browser.navigate.to(path)
end
def set_app_host(host)
@app_host = host
end
end
end

View File

@ -0,0 +1,25 @@
require 'thor'
require 'persistent_selenium'
module PersistentSelenium
class CLI < Thor
desc "start", "Start the server"
def start
require 'persistent_selenium/browser'
require 'drb'
port = ENV['PORT'] || PersistentSelenium.port
browser = ENV['BROWSER'] || PersistentSelenium.browser
puts "Starting persistent_selenium on #{port} with #{browser}"
browser = Browser.new(browser)
browser.browser
DRb.start_service PersistentSelenium.url, browser
DRb.thread.join
end
end
end

View File

@ -0,0 +1,15 @@
require 'persistent_selenium'
Capybara.register_driver :drb do |app|
require 'drb'
DRb.start_service
browser = DRbObject.new nil, PersistentSelenium.url
server = Capybara::Server.new(app)
server.boot
browser.set_app_host(Capybara.app_host)
browser
end

View File

@ -0,0 +1,3 @@
module PersistentSelenium
VERSION = "0.0.1"
end

View File

@ -0,0 +1,17 @@
# -*- encoding: utf-8 -*-
require File.expand_path('../lib/persistent_selenium/version', __FILE__)
Gem::Specification.new do |gem|
gem.authors = ["John Bintz"]
gem.email = ["john@coswellproductions.com"]
gem.description = %q{TODO: Write a gem description}
gem.summary = %q{TODO: Write a gem summary}
gem.homepage = ""
gem.files = `git ls-files`.split($\)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.name = "persistent_selenium"
gem.require_paths = ["lib"]
gem.version = PersistentSelenium::VERSION
end