selenium-proxy 0.0.1

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,4 @@
1
+ === 0.0.1 2010-09-25
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
@@ -0,0 +1,16 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ bin/selenium-proxy-start-server
7
+ lib/selenium-proxy-start-server/cli.rb
8
+ lib/selenium-proxy.rb
9
+ script/console
10
+ script/destroy
11
+ script/generate
12
+ spec/selenium-proxy-start-server_cli_spec.rb
13
+ spec/selenium-proxy_spec.rb
14
+ spec/spec.opts
15
+ spec/spec_helper.rb
16
+ tasks/rspec.rake
@@ -0,0 +1,3 @@
1
+
2
+ For more information on selenium-proxy, see https://rubygems.org/gems/selenium-proxy
3
+
@@ -0,0 +1,58 @@
1
+ = selenium-proxy
2
+
3
+ * http://github.com/usualoma/selenium-proxy
4
+
5
+ == DESCRIPTION:
6
+
7
+ A DRB server program and client libraries for Selenium.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * Reuse a created browser.
12
+
13
+ == SYNOPSIS:
14
+
15
+ $ selenium-proxy-start-server
16
+
17
+ $ cat > selenium-proxy-test.rb <<__RUBY__
18
+ require 'rubygems'
19
+ require 'selenium-proxy'
20
+
21
+ browser = SeleniumProxy::Server.browser :url => 'http://localhost/'
22
+ browser.open '/'
23
+ puts browser.get_html_source
24
+ __RUBY__
25
+
26
+ $ ruby < selenium-proxy-test.rb # A new browser will be created.
27
+ $ ruby < selenium-proxy-test.rb # A browser made above will be reused.
28
+
29
+ == REQUIREMENTS:
30
+
31
+ * Selenium
32
+
33
+ == INSTALL:
34
+
35
+ * sudo gem install selenium-proxy
36
+
37
+ == LICENSE:
38
+
39
+ Copyright (c) 2010 Taku AMANO
40
+
41
+ Permission is hereby granted, free of charge, to any person obtaining
42
+ a copy of this software and associated documentation files (the
43
+ 'Software'), to deal in the Software without restriction, including
44
+ without limitation the rights to use, copy, modify, merge, publish,
45
+ distribute, sublicense, and/or sell copies of the Software, and to
46
+ permit persons to whom the Software is furnished to do so, subject to
47
+ the following conditions:
48
+
49
+ The above copyright notice and this permission notice shall be
50
+ included in all copies or substantial portions of the Software.
51
+
52
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
53
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
54
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
55
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
56
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
57
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
58
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,27 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/selenium-proxy'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'selenium-proxy' do
14
+ self.developer 'Taku AMANO', 'taku@toi-planning.net'
15
+ self.post_install_message = 'PostInstall.txt'
16
+ self.rubyforge_name = self.name
17
+ self.extra_deps = [
18
+ ['Selenium', '>= 0']
19
+ ]
20
+ end
21
+
22
+ require 'newgem/tasks'
23
+ Dir['tasks/**/*.rake'].each { |t| load t }
24
+
25
+ # TODO - want other tests/tasks run by default? Add them to the list
26
+ # remove_task :default
27
+ # task :default => [:spec, :features]
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created by Taku AMANO on 2010-9-25.
4
+ # Copyright (c) 2010. All rights reserved.
5
+
6
+ require 'rubygems'
7
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/selenium-proxy")
8
+ require "selenium-proxy-start-server/cli"
9
+
10
+ SeleniumProxyStartServer::CLI.execute(STDOUT, ARGV)
@@ -0,0 +1,36 @@
1
+ require 'optparse'
2
+
3
+ module SeleniumProxyStartServer
4
+ class CLI
5
+ def self.execute(stdout, arguments=[], &block)
6
+
7
+ options = { }
8
+ mandatory_options = %w( )
9
+
10
+ parser = OptionParser.new do |opts|
11
+ opts.banner = <<-BANNER.gsub(/^ /,'')
12
+ Usage: #{File.basename($0)} [options]
13
+
14
+ Options are:
15
+ BANNER
16
+ opts.separator ""
17
+ opts.on("-d", "--drb-uri URI", String,
18
+ "URI passed to DRb.start_service",
19
+ "Default: " + SeleniumProxy::Server.default_drb_uri
20
+ ) { |arg| options[:drb_uri] = arg }
21
+ opts.on("-h", "--help",
22
+ "Show this help message.") { stdout.puts opts; exit }
23
+ opts.parse!(arguments)
24
+
25
+ if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }
26
+ stdout.puts opts; exit
27
+ end
28
+ end
29
+
30
+ SeleniumProxy::Server.start_service(options) do
31
+ block.call stdout if block
32
+ end
33
+ SeleniumProxy::Server.thread.join if SeleniumProxy::Server.thread
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,100 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'selenium'
5
+ require 'drb/drb'
6
+
7
+ module SeleniumProxy
8
+ VERSION = '0.0.1'
9
+
10
+ class Browser
11
+ def initialize(opts = {})
12
+ @drb = opts[:drb]
13
+ @browser = opts[:browser]
14
+ @options = opts[:options]
15
+ end
16
+
17
+ def method_missing(name, *args)
18
+ if @browser
19
+ @browser.send name, *args
20
+ else
21
+ @drb.browser_call @options, name, *args
22
+ end
23
+ end
24
+ end
25
+
26
+ class Server
27
+ attr_accessor :stream, :current_browser
28
+
29
+ @@default_browser = '*chrome'
30
+ @@default_drb_uri = 'druby://localhost:12445'
31
+ @@default_serenium_host = 'localhost'
32
+ @@default_serenium_port = 4444
33
+
34
+ def self.browser(opts = {}, &block)
35
+ drb, browser = nil, nil
36
+ begin
37
+ drb = DRbObject.new_with_uri(self.drb_uri(opts))
38
+ rescue DRb::DRbConnError => e
39
+ browser = self.new(StringIO.new).browser(opts)
40
+ end
41
+
42
+ Browser.new({
43
+ :drb => drb,
44
+ :browser => browser,
45
+ :options => opts,
46
+ })
47
+ end
48
+
49
+ def self.default_drb_uri
50
+ @@default_drb_uri
51
+ end
52
+
53
+ def self.drb_uri(opts = {})
54
+ opts[:drb_uri] || ENV['SELENIUM_PROXY_DRB_URI'] || self.default_drb_uri
55
+ end
56
+
57
+ def self.start_service(opts = {}, &block)
58
+ DRb.start_service(self.drb_uri(opts), self.new)
59
+ yield if block
60
+ end
61
+
62
+ def self.stop_service(&block)
63
+ DRb.stop_service
64
+ end
65
+
66
+ def self.thread
67
+ DRb.thread
68
+ end
69
+
70
+ def initialize(stream = $stdout)
71
+ @stream = stream
72
+ @current_browser = @@default_browser
73
+ @current_url = nil
74
+ @browsers = {}
75
+ end
76
+
77
+ def browser_call(opts, name, *args)
78
+ self.browser(opts).send name, *args
79
+ end
80
+
81
+ def browser(opts = {})
82
+ opts[:type] = @current_browser = opts[:type] || @current_browser
83
+ opts[:url] = @current_url = opts[:url] || @current_url
84
+ @browsers[@current_url.to_s + @current_browser.to_s] ||= new_browser(opts)
85
+ end
86
+
87
+ def new_browser(opts = {})
88
+ browser = Selenium::SeleniumDriver.new(
89
+ opts[:serenium_host] || ENV['SELENIUM_PROXY_SERENIUM_HOST'] || @@default_serenium_host,
90
+ opts[:serenium_port] || ENV['SELENIUM_PROXY_SERENIUM_PORT'] || @@default_serenium_port,
91
+ opts[:type],
92
+ opts[:url],
93
+ opts[:serenium_timeout] || ENV['SELENIUM_PROXY_SERENIUM_TIMEOUT'] || nil
94
+ )
95
+ browser.start
96
+ browser
97
+ end
98
+
99
+ end
100
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/selenium-proxy.rb'}"
9
+ puts "Loading selenium-proxy gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'selenium-proxy-start-server/cli'
3
+
4
+ describe SeleniumProxyStartServer::CLI, "execute" do
5
+ before(:each) do
6
+ @stdout_io = StringIO.new
7
+ SeleniumProxyStartServer::CLI.execute(@stdout_io, []) do |stdout|
8
+ stdout.puts 'successfully executed'
9
+ SeleniumProxy::Server.stop_service
10
+ end
11
+ @stdout_io.rewind
12
+ @stdout = @stdout_io.read
13
+ end
14
+
15
+ it "should print default output" do
16
+ @stdout.should match "successfully executed\n"
17
+ end
18
+ end
@@ -0,0 +1,85 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ require 'webrick'
4
+
5
+ describe SeleniumProxy do
6
+
7
+ before :all do
8
+ @access_log = StringIO.new
9
+ @server_thread = Thread.new do
10
+ @server = WEBrick::HTTPServer.new({
11
+ :BindAddress => '127.0.0.1',
12
+ :Logger => WEBrick::Log.new(@access_log),
13
+ :AccessLog => [[@access_log, WEBrick::AccessLog::COMBINED_LOG_FORMAT]],
14
+ :Port => 11111,
15
+ })
16
+ @server.mount_proc '/' do |req, res|
17
+ res.body = <<-HTML
18
+ <html>
19
+ <head>
20
+ </head>
21
+ <body>
22
+ content
23
+ </body>
24
+ </html>
25
+ HTML
26
+ end
27
+ @server.start
28
+ end
29
+ end
30
+
31
+ after :all do
32
+ @server.shutdown if @server
33
+ @server_thread.exit
34
+ @server_thread.join
35
+ end
36
+
37
+ before :each do
38
+ SeleniumProxy::Server.start_service
39
+ end
40
+
41
+ after :each do
42
+ begin
43
+ @browser.close
44
+ @browser.stop
45
+ rescue => e
46
+ #
47
+ end
48
+ SeleniumProxy::Server.stop_service
49
+ end
50
+
51
+ browsers = ['*chrome', '*googlechrome', '*iexplore']
52
+ #browsers << '*safari'
53
+ #browsers << '*opera'
54
+
55
+ browsers.each do |type|
56
+ describe type do
57
+ it "create" do
58
+ begin
59
+ @browser = SeleniumProxy::Server.browser({
60
+ :type => type,
61
+ :url => 'http://localhost:11111/',
62
+ })
63
+ @browser.should be_instance_of SeleniumProxy::Browser
64
+ rescue SeleniumCommandError => e
65
+ #
66
+ end
67
+ end
68
+
69
+ it "open" do
70
+ begin
71
+ @browser = SeleniumProxy::Server.browser({
72
+ :type => type,
73
+ :url => 'http://localhost:11111/',
74
+ })
75
+ @browser.open '/'
76
+ rescue SeleniumCommandError => e
77
+ #
78
+ else
79
+ @browser.get_html_source.should match /content/
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ end
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,12 @@
1
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
2
+
3
+ begin
4
+ require 'spec'
5
+ rescue LoadError
6
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
7
+ gem 'rspec'
8
+ require 'spec'
9
+ end
10
+
11
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
12
+ require 'selenium-proxy'
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: selenium-proxy
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Taku AMANO
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-28 00:00:00 +09:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: Selenium
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rubyforge
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 7
44
+ segments:
45
+ - 2
46
+ - 0
47
+ - 4
48
+ version: 2.0.4
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: hoe
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 21
60
+ segments:
61
+ - 2
62
+ - 6
63
+ - 1
64
+ version: 2.6.1
65
+ type: :development
66
+ version_requirements: *id003
67
+ description: A DRB server program and client libraries for Selenium.
68
+ email:
69
+ - taku@toi-planning.net
70
+ executables:
71
+ - selenium-proxy-start-server
72
+ extensions: []
73
+
74
+ extra_rdoc_files:
75
+ - History.txt
76
+ - Manifest.txt
77
+ - PostInstall.txt
78
+ files:
79
+ - History.txt
80
+ - Manifest.txt
81
+ - PostInstall.txt
82
+ - README.rdoc
83
+ - Rakefile
84
+ - bin/selenium-proxy-start-server
85
+ - lib/selenium-proxy-start-server/cli.rb
86
+ - lib/selenium-proxy.rb
87
+ - script/console
88
+ - script/destroy
89
+ - script/generate
90
+ - spec/selenium-proxy-start-server_cli_spec.rb
91
+ - spec/selenium-proxy_spec.rb
92
+ - spec/spec.opts
93
+ - spec/spec_helper.rb
94
+ - tasks/rspec.rake
95
+ has_rdoc: true
96
+ homepage: http://github.com/usualoma/selenium-proxy
97
+ licenses: []
98
+
99
+ post_install_message: PostInstall.txt
100
+ rdoc_options:
101
+ - --main
102
+ - README.rdoc
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ hash: 3
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ hash: 3
120
+ segments:
121
+ - 0
122
+ version: "0"
123
+ requirements: []
124
+
125
+ rubyforge_project: selenium-proxy
126
+ rubygems_version: 1.3.7
127
+ signing_key:
128
+ specification_version: 3
129
+ summary: A DRB server program and client libraries for Selenium.
130
+ test_files: []
131
+