commit 31bc976139658001f8112980238e80db20d953c7 Author: John Bintz Date: Mon Nov 26 11:36:43 2012 -0500 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d87d4be --- /dev/null +++ b/.gitignore @@ -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 diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..6291d29 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +# Specify your gem's dependencies in persistent_selenium.gemspec +gemspec diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..87b491e --- /dev/null +++ b/LICENSE @@ -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. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..8d8e45e --- /dev/null +++ b/README.md @@ -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 diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..f57ae68 --- /dev/null +++ b/Rakefile @@ -0,0 +1,2 @@ +#!/usr/bin/env rake +require "bundler/gem_tasks" diff --git a/bin/persistent_selenium b/bin/persistent_selenium new file mode 100755 index 0000000..a1bfd1d --- /dev/null +++ b/bin/persistent_selenium @@ -0,0 +1,7 @@ +#!/usr/bin/env ruby + +$: << File.expand_path('../../lib', __FILE__) + +require 'persistent_selenium/cli' + +PersistentSelenium::CLI.start diff --git a/lib/persistent_selenium.rb b/lib/persistent_selenium.rb new file mode 100644 index 0000000..a372a45 --- /dev/null +++ b/lib/persistent_selenium.rb @@ -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 diff --git a/lib/persistent_selenium/browser.rb b/lib/persistent_selenium/browser.rb new file mode 100644 index 0000000..e1e5699 --- /dev/null +++ b/lib/persistent_selenium/browser.rb @@ -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 + diff --git a/lib/persistent_selenium/cli.rb b/lib/persistent_selenium/cli.rb new file mode 100644 index 0000000..006141d --- /dev/null +++ b/lib/persistent_selenium/cli.rb @@ -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 + diff --git a/lib/persistent_selenium/driver.rb b/lib/persistent_selenium/driver.rb new file mode 100644 index 0000000..0395e90 --- /dev/null +++ b/lib/persistent_selenium/driver.rb @@ -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 + diff --git a/lib/persistent_selenium/version.rb b/lib/persistent_selenium/version.rb new file mode 100644 index 0000000..3fceaad --- /dev/null +++ b/lib/persistent_selenium/version.rb @@ -0,0 +1,3 @@ +module PersistentSelenium + VERSION = "0.0.1" +end diff --git a/persistent_selenium.gemspec b/persistent_selenium.gemspec new file mode 100644 index 0000000..ccacee4 --- /dev/null +++ b/persistent_selenium.gemspec @@ -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