selenium 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES ADDED
@@ -0,0 +1,7 @@
1
+
2
+ = Selenium Server Gem Changelog
3
+
4
+ == Version 0.1.1
5
+
6
+ * Initial release.
7
+
data/README ADDED
@@ -0,0 +1,12 @@
1
+ = Selenium -- Gem wrapper for selenium server
2
+
3
+ = Installing Selenium
4
+
5
+ == Installing Selenium
6
+ $ gem install selenium
7
+
8
+ == Usage
9
+
10
+ selenium install - installs selenium
11
+ selenium - runs the selenium server
12
+
@@ -0,0 +1,70 @@
1
+ # Rakefile for selenium
2
+
3
+ task :default => :gemspec
4
+
5
+ begin
6
+ require 'bundler'
7
+
8
+ begin
9
+ require 'jeweler'
10
+
11
+ Jeweler::Tasks.new do |gemspec|
12
+ gemspec.name = "selenium"
13
+ gemspec.summary = "Gem wrapper for selenium server (Summary)."
14
+ gemspec.description = "Gem wrapper for selenium server."
15
+ gemspec.email = "alexander.shvets@gmail.com"
16
+ gemspec.homepage = "http://github.com/shvets/selenium"
17
+ gemspec.authors = ["Alexander Shvets"]
18
+ gemspec.files = FileList["CHANGES", "selenium.gemspec", "Rakefile", "README", "VERSION",
19
+ "lib/**/*", "bin/**/*"]
20
+
21
+ gemspec.executables = ['selenium']
22
+ gemspec.requirements = ["none"]
23
+ gemspec.bindir = "bin"
24
+
25
+ gemspec.add_bundler_dependencies
26
+
27
+ gemspec.post_install_message = <<-TEXT
28
+
29
+ -------------------------------------------------------------------------------
30
+
31
+ Please now run:
32
+
33
+ $ selenium install
34
+
35
+ NB. This will download jars that Redcar needs to run from the internet.
36
+ It will put them into ~/.selenium/assets.
37
+
38
+ -------------------------------------------------------------------------------
39
+ TEXT
40
+
41
+ end
42
+ rescue LoadError
43
+ puts "Jeweler not available. Install it s with: [sudo] gem install jeweler"
44
+ end
45
+ rescue LoadError
46
+ puts "Bundler not available. Install it s with: [sudo] gem install bundler"
47
+ end
48
+
49
+ desc "Release the gem"
50
+ task :"release:gem" do
51
+ %x(
52
+ rake gemspec
53
+ rake build
54
+ rake install
55
+ git add .
56
+ )
57
+ puts "Commit message:"
58
+ message = STDIN.gets
59
+
60
+ version = "#{File.open(File::dirname(__FILE__) + "/VERSION").readlines().first}"
61
+
62
+ %x(
63
+ git commit -m "#{message}"
64
+
65
+ git push origin master
66
+
67
+ gem push pkg/selenium-#{version}.gem
68
+ )
69
+ end
70
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File::join(File::dirname(File::dirname(__FILE__)), "lib"))
4
+
5
+ require 'rubygems' unless RUBY_VERSION =~ /1.9.*/
6
+ require 'selenium'
7
+
8
+ class SeleniumStarter
9
+
10
+ USAGE= <<-TEXT
11
+ Usage:
12
+ selenium help - this help
13
+ selenium install - installs selenium
14
+ selenium - runs the selenium server
15
+ TEXT
16
+
17
+ def initialize
18
+ @selenium = Selenium.new
19
+ end
20
+
21
+ def run
22
+ install_dir = ENV['HOME'] + "/.selenium/assets"
23
+ verion = "2.0a7"
24
+ source = "http://selenium.googlecode.com/files/selenium-server-#{verion}.zip"
25
+ target = install_dir + "/selenium-server-#{verion}.zip"
26
+ jar_file = install_dir + "/selenium-#{verion}/selenium-server-standalone-#{verion}.jar"
27
+
28
+ case ARGV.shift
29
+ when /(-v)|(--version)/ then
30
+ puts "Version: #{File.open(File::dirname(__FILE__) + "/../VERSION").readlines().first}"
31
+ when 'install' then
32
+ @selenium.install source, target
33
+ when 'help' then
34
+ puts USAGE and return
35
+ else
36
+ @selenium.run jar_file
37
+ end
38
+ end
39
+ end
40
+
41
+ SeleniumStarter.new.run
@@ -0,0 +1,6 @@
1
+ @ECHO OFF
2
+ IF NOT "%~f0" == "~f0" GOTO :WinNT
3
+ @"ruby.exe" "C:/Ruby/ruby-1.9.1/bin/selenium" %1 %2 %3 %4 %5 %6 %7 %8 %9
4
+ GOTO :EOF
5
+ :WinNT
6
+ @"ruby.exe" "%~dpn0" %*
@@ -0,0 +1,17 @@
1
+ require 'rubygems' unless RUBY_VERSION =~ /1.9.*/
2
+
3
+ $:.unshift(File.dirname(__FILE__)) unless
4
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
5
+
6
+ require 'fileutils'
7
+ require 'net/http'
8
+
9
+ if RUBY_PLATFORM =~ /windows/
10
+ require "zip/zipfilesystem"
11
+ else
12
+ require 'zip/zip'
13
+ end
14
+
15
+ require 'selenium/selenium'
16
+ require 'selenium/runner'
17
+ require 'selenium/jvm_options_probe'
@@ -0,0 +1,33 @@
1
+ require "open3"
2
+
3
+ class JvmOptionsProbe
4
+
5
+ def initialize
6
+ @d32 = @d64 = @client = false
7
+
8
+ if RUBY_PLATFORM =~ /windows/
9
+ @help = `java -h`
10
+ @d32 = (@help == `java -d32`) ? true : false
11
+ @d64 = (@help == `java -d64`) ? true : false
12
+ @client = (@help == `java -client`) ? true : false
13
+ else
14
+ @help = Open3.popen3("java -h")[2].readlines
15
+ @d32 = (@help == Open3.popen3("java -d32")[2].readlines) ? true : false
16
+ @d64 = (@help == Open3.popen3("java -d64")[2].readlines) ? true : false
17
+ @client = (@help == Open3.popen3("java -client")[2].readlines) ? true : false
18
+ end
19
+ end
20
+
21
+ def can_use_d32?
22
+ @d32
23
+ end
24
+
25
+ def can_use_d64?
26
+ @d64
27
+ end
28
+
29
+ def can_use_client?
30
+ @client
31
+ end
32
+ end
33
+
@@ -0,0 +1,122 @@
1
+
2
+ class Runner
3
+ def run jar_file
4
+ @jar_file = jar_file
5
+
6
+ # forking = ARGV.include?("--fork") and ARGV.first != "install"
7
+ # no_runner = ARGV.include?("--no-sub-jruby")
8
+ # jruby = Config::CONFIG["RUBY_INSTALL_NAME"] == "jruby"
9
+ # osx = !(RUBY_PLATFORM =~/(windows|linux)/)
10
+ # begin
11
+ # if forking and not jruby
12
+ # # jRuby doesn't support fork() because of the runtime stuff...
13
+ # forking = false
14
+ # puts 'Forking failed, attempting to start anyway...' if (pid = fork) == -1
15
+ # exit unless pid.nil? # kill the parent process
16
+ #
17
+ # if pid.nil?
18
+ # # reopen the standard pipes to nothingness
19
+ # # STDIN.reopen Redcar.null_device
20
+ # # STDOUT.reopen Redcar.null_device, 'a'
21
+ # STDERR.reopen STDOUT
22
+ # end
23
+ # elsif forking and SPOON_AVAILABLE and ::Spoon.supported?
24
+ # # so we need to try something different...
25
+ #
26
+ # forking = false
27
+ # construct_command do |command|
28
+ # command.push('--silent')
29
+ # ::Spoon.spawnp(*command)
30
+ # end
31
+ # exit 0
32
+ # elsif forking
33
+ # raise NotImplementedError, "Something weird has happened. Please contact us."
34
+ # end
35
+ # rescue NotImplementedError
36
+ # puts $!.class.name + ": " + $!.message
37
+ # puts "Forking isn't supported on this system. Sorry."
38
+ # puts "Starting normally..."
39
+ # end
40
+ #
41
+ # return if no_runner
42
+ # return if jruby and not osx
43
+
44
+ construct_command do |command|
45
+ exec(command.join(" "))
46
+ end
47
+
48
+ end
49
+
50
+ # Trade in this Ruby instance for a JRuby instance, loading in a
51
+ # starter script and passing it some arguments.
52
+ # If --jruby is passed, use the installed version of jruby, instead of
53
+ # our vendored jarred one (useful for gems).
54
+ def construct_command(args="")
55
+ bin = File.expand_path(File.join(File.dirname(__FILE__), %w{.. .. bin selenium}))
56
+ # jruby_complete = File.expand_path(File.join(Redcar.asset_dir, "jruby-complete-1.5.3.jar"))
57
+ # unless File.exist?(jruby_complete)
58
+ # puts "\nCan't find jruby jar at #{jruby_complete}, did you run 'redcar install' ?"
59
+ # exit 1
60
+ # end
61
+ ENV['RUBYOPT'] = nil # disable other native args
62
+
63
+ # Windows XP updates
64
+
65
+ # if RUBY_PLATFORM =~ /window/
66
+ # bin = "\"#{bin}\""
67
+ # jruby_complete = "\"#{jruby_complete}\""
68
+ # end
69
+
70
+ # unfortuanately, ruby doesn't support [a, *b, c]
71
+ command = ["java"]
72
+ command.push(*java_args)
73
+ command.push("-Xmx500m", "-Xss1024k")
74
+ command.push("-jar", @jar_file)
75
+ #command.push("-Djruby.memory.max=500m", "-Djruby.stack.max=1024k", "-cp", jruby_complete, "org.jruby.Main")
76
+
77
+ command.push "--debug" if debug_mode?
78
+ # command.push(bin)
79
+ # command.push(*cleaned_args)
80
+ # command.push("--no-sub-jruby", "--ignore-stdin")
81
+ command.push(*args)
82
+
83
+ puts command.join(' ')
84
+ yield command
85
+ end
86
+
87
+ # def cleaned_args
88
+ # # We should never pass --fork to a subprocess
89
+ # result = ARGV.find_all {|arg| arg != '--fork'}.map do |arg|
90
+ # if arg =~ /--(.+)=(.+)/
91
+ # "--" + $1 + "=\"" + $2 + "\""
92
+ # else
93
+ # arg
94
+ # end
95
+ # end
96
+ # result.delete("install")
97
+ # result
98
+ # end
99
+
100
+ def debug_mode?
101
+ ARGV.include?("--debug")
102
+ end
103
+
104
+ def java_args
105
+ str = []
106
+ if Config::CONFIG["host_os"] =~ /darwin/
107
+ str.push "-XstartOnFirstThread"
108
+ end
109
+
110
+ # if ARGV.include?("--load-timings")
111
+ # str.push "-Djruby.debug.loadService.timing=true"
112
+ # end
113
+
114
+ jvm_options_probe = JvmOptionsProbe.new
115
+
116
+ str.push "-d32" if jvm_options_probe.can_use_d32?
117
+ str.push "-client" if jvm_options_probe.can_use_client?
118
+
119
+ str
120
+ end
121
+ end
122
+
@@ -0,0 +1,53 @@
1
+ class Selenium
2
+ def download_file_to(uri, destination_file)
3
+ connection = Net::HTTP
4
+
5
+ print " downloading #{uri}... "; $stdout.flush
6
+ temporary_target = destination_file + ".part"
7
+ FileUtils.mkdir_p(File.dirname(destination_file))
8
+ File.open(temporary_target, "wb") do |write_out|
9
+ write_out.print connection.get(URI.parse(uri))
10
+ end
11
+
12
+ if File.open(temporary_target).read(200) =~ /Access Denied/
13
+ puts "\n\n*** Error downloading #{uri}, got Access Denied from S3."
14
+ FileUtils.rm_rf(temporary_target)
15
+ exit
16
+ end
17
+
18
+ FileUtils.cp(temporary_target, destination_file)
19
+ FileUtils.rm_rf(temporary_target)
20
+ puts "done!"
21
+ end
22
+
23
+ # unzip a .zip file into the directory it is located
24
+ def unzip_file(path)
25
+ print "unzipping #{path}..."; $stdout.flush
26
+ source = File.expand_path(path)
27
+ Dir.chdir(File.dirname(source)) do
28
+ Zip::ZipFile.open(source) do |zipfile|
29
+ zipfile.entries.each do |entry|
30
+ FileUtils.mkdir_p(File.dirname(entry.name))
31
+ begin
32
+ entry.extract
33
+ rescue Zip::ZipDestinationFileExistsError
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ def install source, destination
41
+ download_file_to(source, destination)
42
+
43
+ unzip_file(destination) if destination =~ /\.zip$/
44
+ end
45
+
46
+ def run jar_file
47
+ runner = Runner.new
48
+
49
+ runner.run jar_file
50
+ end
51
+ end
52
+
53
+
@@ -0,0 +1,68 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{selenium}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Alexander Shvets"]
12
+ s.date = %q{2010-11-08}
13
+ s.default_executable = %q{selenium}
14
+ s.description = %q{Gem wrapper for selenium server.}
15
+ s.email = %q{alexander.shvets@gmail.com}
16
+ s.executables = ["selenium"]
17
+ s.extra_rdoc_files = [
18
+ "README"
19
+ ]
20
+ s.files = [
21
+ "CHANGES",
22
+ "README",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "bin/selenium",
26
+ "bin/selenium.bat",
27
+ "lib/selenium.rb",
28
+ "lib/selenium/jvm_options_probe.rb",
29
+ "lib/selenium/runner.rb",
30
+ "lib/selenium/selenium.rb",
31
+ "selenium.gemspec"
32
+ ]
33
+ s.homepage = %q{http://github.com/shvets/selenium}
34
+ s.post_install_message = %q{
35
+ -------------------------------------------------------------------------------
36
+
37
+ Please now run:
38
+
39
+ $ selenium install
40
+
41
+ NB. This will download jars that Redcar needs to run from the internet.
42
+ It will put them into ~/.selenium/assets.
43
+
44
+ -------------------------------------------------------------------------------
45
+ }
46
+ s.rdoc_options = ["--charset=UTF-8"]
47
+ s.require_paths = ["lib"]
48
+ s.requirements = ["none"]
49
+ s.rubygems_version = %q{1.3.7}
50
+ s.summary = %q{Gem wrapper for selenium server (Summary).}
51
+
52
+ if s.respond_to? :specification_version then
53
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
54
+ s.specification_version = 3
55
+
56
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
+ s.add_runtime_dependency(%q<jeweler>, [">= 0"])
58
+ s.add_runtime_dependency(%q<rubyzip>, [">= 0"])
59
+ else
60
+ s.add_dependency(%q<jeweler>, [">= 0"])
61
+ s.add_dependency(%q<rubyzip>, [">= 0"])
62
+ end
63
+ else
64
+ s.add_dependency(%q<jeweler>, [">= 0"])
65
+ s.add_dependency(%q<rubyzip>, [">= 0"])
66
+ end
67
+ end
68
+
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: selenium
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
+ - Alexander Shvets
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-08 00:00:00 -05:00
19
+ default_executable: selenium
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :runtime
23
+ prerelease: false
24
+ name: jeweler
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ type: :runtime
37
+ prerelease: false
38
+ name: rubyzip
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ requirement: *id002
49
+ description: Gem wrapper for selenium server.
50
+ email: alexander.shvets@gmail.com
51
+ executables:
52
+ - selenium
53
+ extensions: []
54
+
55
+ extra_rdoc_files:
56
+ - README
57
+ files:
58
+ - CHANGES
59
+ - README
60
+ - Rakefile
61
+ - VERSION
62
+ - bin/selenium
63
+ - bin/selenium.bat
64
+ - lib/selenium.rb
65
+ - lib/selenium/jvm_options_probe.rb
66
+ - lib/selenium/runner.rb
67
+ - lib/selenium/selenium.rb
68
+ - selenium.gemspec
69
+ has_rdoc: true
70
+ homepage: http://github.com/shvets/selenium
71
+ licenses: []
72
+
73
+ post_install_message: |
74
+
75
+ -------------------------------------------------------------------------------
76
+
77
+ Please now run:
78
+
79
+ $ selenium install
80
+
81
+ NB. This will download jars that Redcar needs to run from the internet.
82
+ It will put them into ~/.selenium/assets.
83
+
84
+ -------------------------------------------------------------------------------
85
+
86
+ rdoc_options:
87
+ - --charset=UTF-8
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ requirements:
109
+ - none
110
+ rubyforge_project:
111
+ rubygems_version: 1.3.7
112
+ signing_key:
113
+ specification_version: 3
114
+ summary: Gem wrapper for selenium server (Summary).
115
+ test_files: []
116
+