Skip to content

Commit

Permalink
[webui-testsuite] implement command options
Browse files Browse the repository at this point in the history
to avoid the mess I created last night, it's better not having to touch
the code but just use a non-default command line.

Now I can use:
  ./run_acceptance_tests.rb -p 3000 -s  spider_anonymously

and will see the firefox crawling my local webui
  • Loading branch information
coolo committed Mar 27, 2012
1 parent ffd01c8 commit 360ad5e
Showing 1 changed file with 49 additions and 21 deletions.
70 changes: 49 additions & 21 deletions src/webui-testsuite/run_acceptance_tests.rb
Expand Up @@ -3,6 +3,7 @@
require 'headless'
require 'colored'
require 'net/http'
require 'optparse'

#$DEBUG = 1;

Expand Down Expand Up @@ -77,32 +78,56 @@ def distribute(*args)
frontend.join if frontend
end

PORT=3199
DEFAULT_PORT=3199
port=nil

if true
frontend = Thread.new do
puts "Starting test webui at port #{PORT} ..."
webui_out = IO.popen("cd ../webui; exec ./script/server -e test -p #{PORT} 2>&1")
puts "Webui started with PID: #{webui_out.pid}"
begin
Process.setpgid webui_out.pid, 0
rescue Errno::EACCES
# what to do?
puts "Could not set group to root"
options = {
:port => DEFAULT_PORT,
:headless => true
}

limitto = OptionParser.new do |opts|
opts.banner = "Usage: run_acceptance_test.rb [-h] [-p PORT] [limit_to....]"

opts.on('-p', '--port PORT', 'Use webui on this port (start our own if default or 3199)') do |p|
options[:port] = p.to_i
end

opts.on('-s', '--show', 'Show the browser instead of running headless') do
options[:headless] = false
end

opts.on( '-h', '--help', 'Display this screen' ) do
puts opts
exit 0
end
while webui_out
end.parse!

if options[:port] == DEFAULT_PORT
frontend = Thread.new do
puts "Starting test webui at port #{options[:port]} ..."
webui_out = IO.popen("cd ../webui; exec ./script/server -e test -p #{options[:port]} 2>&1")
puts "Webui started with PID: #{webui_out.pid}"
begin
line = webui_out.gets
rescue IOError
break
Process.setpgid webui_out.pid, 0
rescue Errno::EACCES
# what to do?
puts "Could not set group to root"
end
while webui_out
begin
line = webui_out.gets
rescue IOError
break
end
end
end
end

while true
puts "Waiting for Webui to serve requests..."
begin
Net::HTTP.start("localhost", PORT) do |http|
Net::HTTP.start("localhost", options[:port]) do |http|
http.open_timeout = 15
http.read_timeout = 15
# we need to ask for something that is available without login _and_ starts api and backend too
Expand All @@ -125,10 +150,9 @@ def distribute(*args)
end
break
end
end

puts "Webui ready"
$data[:url] = "http://localhost:#{PORT}"
$data[:url] = "http://localhost:#{options[:port]}"
$data[:asserts_timeout] = 5
$data[:actions_timeout] = 5

Expand Down Expand Up @@ -241,11 +265,15 @@ def distribute(*args)
"remove_user_real_name",
"real_name_stays_changed",
"edit_project_user_add_all_roles"]
#TestRunner.set_limitto ["spider_anonymously"]
if limitto
TestRunner.set_limitto limitto
end

# Run the test
display = Headless.new
display.start if display
if options[:headless]
display = Headless.new
display.start
end
driver = WebDriver.for :firefox #, :remote , "http://localhost:5910'
#driver.manage.timeouts.implicit_wait = 3 # seconds
$page = WebPage.new driver
Expand Down

0 comments on commit 360ad5e

Please sign in to comment.