public
Description: Official Ruby client API for Selenium Remote Control (bare bone client driver)
Homepage: http://rubyforge.org/projects/selenium-client/
Clone URL: git://github.com/ph7/selenium-client.git
selenium-client / Rakefile
100644 245 lines (209 sloc) 8.575 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# Rakefile for Selenium Ruby Client -*- ruby -*-
 
$:.unshift 'lib'
 
require 'rake/clean'
require 'rake/testtask'
require 'rake/packagetask'
require 'rake/gempackagetask'
require 'rake/rdoctask'
 
require 'rubygems'
gem "rspec", "1.2.8"
require 'spec/rake/spectask'
require 'selenium/rake/tasks'
 
CLEAN.include("COMMENTS")
CLEAN.include('lib/selenium/client/generated_driver.rb', '**/*.log', "target", "pkg", "test/integration/reporting/dummy_project/target")
 
if ENV["SELENIUM_RC_JAR"]
# User override
SELENIUM_RC_JAR = ENV["SELENIUM_RC_JAR"]
elsif not Dir[File.dirname(__FILE__) + "/../../selenium-server/target/selenium-server-*-standalone.jar"].empty?
# We are part of the global Selenium RC Build
SELENIUM_RC_JAR = Dir[File.dirname(__FILE__) + "/../../selenium-server/target/selenium-server-*-standalone.jar"].first
else
# Bundled version
SELENIUM_RC_JAR = Dir[File.dirname(__FILE__) + "/vendor/selenium-remote-control/selenium-server-*.jar"].first
end
 
raise "Invalid Selenium RC jar : '#{SELENIUM_RC_JAR}" unless File.exists?(SELENIUM_RC_JAR)
  
task :default => :"test:unit"
 
desc "Start a Selenium remote control, run all integration tests and stop the remote control"
task :'ci:integration' => [ :clean, :'test:unit' ] do
  Rake::Task[:"selenium:rc:stop"].execute [] rescue nil
  begin
    Rake::Task[:"sample_app:restart"].execute []
    Rake::Task[:"selenium:rc:start"].execute []
    Rake::Task[:"test:integration"].execute []
    Rake::Task[:"examples"].execute []
  ensure
    Rake::Task[:"selenium:rc:stop"].execute []
    Rake::Task[:"sample_app:restart"].execute []
  end
end
 
file "target/iedoc.xml" do
  has_unzip = system "unzip -v"
  if has_unzip
    sh "unzip -uj '#{SELENIUM_RC_JAR}' core/iedoc.xml -d target"
  else # Windows support assumes Java is installed
    sh "jar xvf \"#{SELENIUM_RC_JAR}\" core/iedoc.xml"
    FileUtils.mkdir_p "target"
    FileUtils.mv "core/iedoc.xml", "target/iedoc.xml"
    FileUtils.rmdir "core"
  end
end
 
desc "Generate driver from iedoc.xml"
file "lib/selenium/client/generated_driver.rb" => [ "target/iedoc.xml" ] do
  sh "ant generate-sources"
end
 
desc "Run unit tests"
Rake::TestTask.new(:'test:unit') do |t|
  t.test_files = FileList['test/unit/**/*_tests.rb']
  t.warning = true
end
task :"test:unit" => "lib/selenium/client/generated_driver.rb"
 
Selenium::Rake::RemoteControlStartTask.new do |rc|
  rc.port = 4444
  rc.timeout_in_seconds = 3 * 60
  rc.background = true
  rc.wait_until_up_and_running = true
  rc.jar_file = SELENIUM_RC_JAR
  rc.additional_args << "-singleWindow"
end
 
Selenium::Rake::RemoteControlStopTask.new do |rc|
  rc.host = "localhost"
  rc.port = 4444
  rc.timeout_in_seconds = 3 * 60
  rc.wait_until_stopped = true
end
 
desc "Restart Selenium Remote Control"
task :'selenium:rc:restart' do
  Rake::Task[:"selenium:rc:stop"].execute [] rescue nil
  Rake::Task[:"selenium:rc:start"].execute []
end
 
desc "Run all integration tests"
Spec::Rake::SpecTask.new("test:integration") do |t|
    t.spec_files = FileList['test/integration/**/*_spec.rb'] - FileList['test/integration/**/dummy_project/*_spec.rb']
    t.spec_opts << '--color'
    t.spec_opts << "--require 'lib/selenium/rspec/reporting/selenium_test_report_formatter'"
    t.spec_opts << "--format=Selenium::RSpec::SeleniumTestReportFormatter:./target/integration_tests_report.html"
    t.spec_opts << "--format=progress"
end
task :"test:integration" => ["lib/selenium/client/generated_driver.rb"]
 
begin
  gem "deep_test", ">=1.2.1"
  require "deep_test/rake_tasks"
 
  desc "Run all integration tests in parallel"
  Spec::Rake::SpecTask.new("test:integration:parallel") do |t|
      t.spec_files = FileList['test/integration/**/*.rb']
      t.spec_opts << '--color'
      t.spec_opts << "--require 'lib/selenium/rspec/reporting/selenium_test_report_formatter'"
      t.spec_opts << "--format=Selenium::RSpec::SeleniumTestReportFormatter:./target/integration_tests_report.html"
      t.spec_opts << "--format=progress"
      t.deep_test :number_of_workers => 5,
                  :timeout_in_seconds => 180
  end
rescue Exception
  puts "Could not find DeepTest, disable parallel run"
end
 
desc "Run API integration tests"
Spec::Rake::SpecTask.new("test:integration:api") do |t|
    t.spec_files = FileList['test/integration/api/**/*_spec.rb']
    t.spec_opts << '--color'
    t.spec_opts << "--require 'lib/selenium/rspec/reporting/selenium_test_report_formatter'"
    t.spec_opts << "--format=Selenium::RSpec::SeleniumTestReportFormatter:./target/api_integration_tests_report.html"
    t.spec_opts << "--format=progress"
end
 
desc "Run API integration tests"
Spec::Rake::SpecTask.new("test:integration:smoke") do |t|
    t.spec_files = FileList['test/integration/smoke/**/*backward*.rb']
    t.spec_opts << '--color'
    t.spec_opts << "--require 'lib/selenium/rspec/reporting/selenium_test_report_formatter'"
    t.spec_opts << "--format=Selenium::RSpec::SeleniumTestReportFormatter:./target/smoke_tests_report.html"
    t.spec_opts << "--format=progress"
end
 
desc "Run Test::Unit example"
Rake::TestTask.new("examples:testunit" ) do |t|
  t.test_files = FileList['examples/testunit/**/*_test.rb']
  t.warning = true
end
 
desc "Run RSpec examples"
Spec::Rake::SpecTask.new("examples:rspec") do |t|
    t.spec_files = FileList['examples/rspec/**/*_spec.rb']
    t.spec_opts << '--color'
    t.spec_opts << "--require 'lib/selenium/rspec/reporting/selenium_test_report_formatter'"
    t.spec_opts << "--format=Selenium::RSpec::SeleniumTestReportFormatter:./target/smoke_tests_report.html"
    t.spec_opts << "--format=progress"
end
 
desc "Run script example"
task :'examples:script' do
  sh "ruby examples/script/*.rb"
end
 
desc "Run all examples"
task :'examples' => [:'examples:rspec', :'examples:testunit', :'examples:script']
 
desc "Run tests that are part of Selenium RC maven build (When Selenium Client is part of Selenium RC Workspace)."
task :'test:maven_build' do |t|
  Rake::Task[:"test:unit"].invoke
  if (ENV['HEADLESS_TEST_MODE'] || "").downcase == "true"
    puts "Headless test mode detected"
  else
    Rake::Task[:"test:integration"].invoke
  end
end
 
desc "Run tests in parallel"
Spec::Rake::SpecTask.new("test:parallel") do |t|
    t.spec_files = FileList['test/integration/*_spec.rb']
    t.spec_opts << '--color'
    t.spec_opts << "--require 'lib/selenium/rspec/reporting/selenium_test_report_formatter'"
    t.spec_opts << "--format=Selenium::RSpec::SeleniumTestReportFormatter:./target/report.html"
    t.spec_opts << "--format=progress"
end
 
desc "Launch Sample App"
task :'sample_app:start' do
  Nautilus::Shell.new.run \
      "\"#{File.expand_path(File.dirname(__FILE__) + '/test/integration/sample-app/sample_app.rb')}\"",
      :background => true
  TCPSocket.wait_for_service :host => "localhost", :port => 4567
end
 
desc "Stop Sample App"
task :'sample_app:stop' do
  Net::HTTP.get("localhost", '/shutdown', 4567)
end
 
desc "Restart Sample App"
task :'sample_app:restart' do
  Rake::Task[:"sample_app:stop"].execute([]) rescue nil
  Rake::Task[:"sample_app:start"].execute []
end
 
 
specification = Gem::Specification.new do |s|
  s.name = "selenium-client"
  s.summary = "Official Ruby Client for Selenium RC."
  s.version = "1.2.17"
  s.author = "OpenQA"
  s.email = 'selenium-client@rubyforge.org'
  s.homepage = "http://selenium-client.rubyforge.com"
  s.rubyforge_project = 'selenium-client'
  s.platform = Gem::Platform::RUBY
  s.files = FileList['lib/**/*.rb'] + FileList['examples/**/*.rb']
  s.require_path = "lib"
  s.extensions = []
  s.rdoc_options << '--title' << 'Selenium Client' << '--main' << 'README' << '--line-numbers'
  s.has_rdoc = true
  s.extra_rdoc_files = ['README.markdown']
s.test_file = "test/all_unit_tests.rb"
end
 
Rake::GemPackageTask.new(specification) do |package|
  package.need_zip = false
  package.need_tar = false
end
 
desc "Build the RubyGem"
task :gem => "lib/selenium/client/generated_driver.rb"
 
desc "Generate documentation"
Rake::RDocTask.new("rdoc") do |rdoc|
  rdoc.title = "Selenium Client"
  rdoc.main = "README"
  rdoc.rdoc_dir = "doc"
  rdoc.rdoc_files.include('README.markdown')
  rdoc.rdoc_files.include('lib/**/*.rb')
  rdoc.rdoc_files.include('doc/**/*.rdoc')
  rdoc.options << '--line-numbers' << '--inline-source'
end
 
desc "Publish RDoc on Rubyforge website"
task :'rdoc:publish' => :rdoc do
  sh "scp -r doc/* #{ENV['USER']}@rubyforge.org:/var/www/gforge-projects/selenium-client"
end
 
task :package => [ :'test:unit' ]