2010-03-02 15:15:32 +00:00
|
|
|
=begin
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
Run the acceptance tests, and summarize their output.
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
Parameters:
|
2010-03-02 21:41:50 +00:00
|
|
|
-- the root directory for the tests. Probably something ending in
|
2010-03-02 15:15:32 +00:00
|
|
|
vivoweb/utilities/acceptance-tests/suites
|
|
|
|
-- the directory for the output.
|
2010-03-02 21:41:50 +00:00
|
|
|
-- the path to the user extensions script.
|
2010-03-02 15:15:32 +00:00
|
|
|
-- the directory of the Firefox profile template.
|
|
|
|
-- the URL of the web site under test.
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
2010-03-02 21:41:50 +00:00
|
|
|
What are we doing?
|
|
|
|
-- Test the parameters.
|
|
|
|
-- Does each directory exist? Is it readable? writeable?
|
|
|
|
-- Does the URL produce a response?
|
|
|
|
-- Does user-extensions.js exist?
|
2010-03-02 15:15:32 +00:00
|
|
|
-- For each subdirectory in the suites folder:
|
2010-03-02 21:41:50 +00:00
|
|
|
-- Run the reset process, whatever that is.
|
|
|
|
-- Stop tomcat, reset MySql database, start tomcat
|
|
|
|
-- Find the Suite.html
|
2010-03-02 15:15:32 +00:00
|
|
|
-- If none, throw warning into the log and continue.
|
|
|
|
-- Run the suite, sending the output to a file named after the subdirectory
|
|
|
|
-- If failure, throw error into the log and continue.
|
|
|
|
-- Create a summary output file.
|
|
|
|
result: passed | failed -- "and" of all suites.
|
|
|
|
total time: seconds -- capture the time before and after.
|
|
|
|
number of tests: -- sum from all suites.
|
|
|
|
number of passing tests: -- sum from all suites.
|
|
|
|
number of failing tests: -- sum from all suites.
|
2010-03-02 21:41:50 +00:00
|
|
|
|
2010-03-02 15:15:32 +00:00
|
|
|
Table of links to the suite output files.
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
=end
|
2010-03-02 21:41:50 +00:00
|
|
|
require 'open-uri'
|
2010-03-11 19:00:32 +00:00
|
|
|
require 'date'
|
2010-03-08 22:21:13 +00:00
|
|
|
require File.expand_path('database_cleanser', File.dirname(File.expand_path(__FILE__)))
|
|
|
|
require File.expand_path('property_file_reader', File.dirname(File.expand_path(__FILE__)))
|
2010-03-11 19:00:32 +00:00
|
|
|
require File.expand_path('output_manager', File.dirname(File.expand_path(__FILE__)))
|
2010-03-02 15:15:32 +00:00
|
|
|
|
2010-03-02 21:41:50 +00:00
|
|
|
=begin
|
2010-03-02 15:15:32 +00:00
|
|
|
<h1>Test suite results </h1>
|
|
|
|
<table>
|
|
|
|
<tr><td>result:</td><td>passed</td></tr>
|
|
|
|
<tr><td>totalTime:</td><td>12</td></tr>
|
|
|
|
<tr><td>numTestTotal:</td><td>6</td></tr>
|
|
|
|
<tr><td>numTestPasses:</td><td>6</td></tr>
|
|
|
|
<tr><td>numTestFailures:</td><td>0</td></tr>
|
|
|
|
<tr><td>numCommandPasses:</td><td>71</td></tr>
|
|
|
|
<tr><td>numCommandFailures:</td><td>0</td></tr>
|
|
|
|
<tr><td>numCommandErrors:</td><td>0</td></tr>
|
|
|
|
<tr><td>Selenium Version:</td><td>2.0</td></tr>
|
|
|
|
<tr><td>Selenium Revision:</td><td>a1</td></tr>
|
|
|
|
<tr><td>
|
|
|
|
<table id="suiteTable" class="selenium" border="1" cellpadding="1" cellspacing="1"><tbody>
|
|
|
|
<tr class="title status_passed"><td><b>Test Suite</b></td></tr>
|
|
|
|
<tr class=" status_passed"><td><a href="#testresult0">Create New User</a></td></tr>
|
|
|
|
<tr class=" status_passed"><td><a href="#testresult1">First Time Login</a></td></tr>
|
|
|
|
<tr class=" status_passed"><td><a href="#testresult2">Try New Password</a></td></tr>
|
|
|
|
<tr class=" status_passed"><td><a href="#testresult3">Edit User Info</a></td></tr>
|
|
|
|
<tr class=" status_passed"><td><a href="#testresult4">Confirm Edited Info</a></td></tr>
|
|
|
|
<tr class=" status_passed"><td><a href="#testresult5">Delete New User</a></td></tr>
|
|
|
|
</tbody></table>
|
|
|
|
</td><td> </td></tr>
|
2010-03-02 21:41:50 +00:00
|
|
|
</table>
|
|
|
|
=end
|
|
|
|
|
|
|
|
class AcceptanceRunner
|
|
|
|
# ------------------------------------------------------------------------------------
|
|
|
|
private
|
|
|
|
# ------------------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Confirm that the parameters are reasonable. They point to valid files, directories,
|
|
|
|
# and URL.
|
|
|
|
#
|
|
|
|
def sanity_checks_on_parameters()
|
2010-03-08 22:21:13 +00:00
|
|
|
raise("Properties file must contain a value for 'website_url'") if @website_url == nil
|
|
|
|
raise("Properties file must contain a value for 'test_root_directory'") if @test_root_directory == nil
|
|
|
|
raise("Properties file must contain a value for 'user_extensions_path'") if @user_extensions_path == nil
|
|
|
|
raise("Properties file must contain a value for 'firefox_profile_template_path'") if @firefox_profile_template_path == nil
|
|
|
|
raise("Properties file must contain a value for 'suite_timeout_limit'") if @suite_timeout_limit == nil
|
|
|
|
raise("Properties file must contain a value for 'selenium_jar_path'") if @selenium_jar_path == nil
|
|
|
|
|
2010-03-02 21:41:50 +00:00
|
|
|
confirm_is_readable_directory(@test_root_directory, "Test root directory")
|
2010-03-04 16:55:45 +00:00
|
|
|
if get_sub_directories(@test_root_directory).empty?
|
2010-03-02 21:41:50 +00:00
|
|
|
raise "Test root directory '#{@test_root_directory}' has no sub-directories."
|
|
|
|
end
|
|
|
|
|
|
|
|
if File.basename(@user_extensions_path) != "user-extensions.js"
|
|
|
|
raise "User extensions file must be named 'user-extensions.js', not '#{File.basename(@user_extensions_path)}'"
|
|
|
|
end
|
|
|
|
confirm_is_readable_file(@user_extensions_path, "User extensions file")
|
|
|
|
|
|
|
|
confirm_is_readable_directory(@firefox_profile_template_path, "Firefox profile template")
|
|
|
|
|
|
|
|
begin
|
|
|
|
open(@website_url) {|f|}
|
|
|
|
rescue Exception
|
|
|
|
raise "Unable to connect to web-site at '#{@website_url}'"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Does this path point to an existing, readable directory?
|
|
|
|
#
|
|
|
|
def confirm_is_readable_directory(path, label)
|
|
|
|
confirm_is_readable(path, label)
|
|
|
|
if !File.directory?(path)
|
|
|
|
raise "#{label} '#{path}' is not a directory."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Does this path point to an existing, readable file?
|
|
|
|
#
|
|
|
|
def confirm_is_readable_file(path, label)
|
|
|
|
confirm_is_readable(path, label)
|
|
|
|
if !File.file?(path)
|
2010-03-15 20:23:04 +00:00
|
|
|
raise "#{label} '#{path}' is not a file."
|
2010-03-02 21:41:50 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Does this path point to something that exists and is readable?
|
|
|
|
#
|
|
|
|
def confirm_is_readable(path, label)
|
|
|
|
if !File.exist?(path)
|
|
|
|
raise "#{label} '#{path}' does not exist."
|
|
|
|
end
|
|
|
|
if !File.readable?(path)
|
|
|
|
raise "#{label} '#{path}' is not readable."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-03-04 16:55:45 +00:00
|
|
|
# Get an array of paths to all of the sub-directories in this directory.
|
2010-03-02 21:41:50 +00:00
|
|
|
#
|
2010-03-04 16:55:45 +00:00
|
|
|
def get_sub_directories(directory_path)
|
|
|
|
subs = []
|
2010-03-02 21:41:50 +00:00
|
|
|
Dir.foreach(directory_path) do |filename|
|
|
|
|
if filename[0,1] != '.'
|
|
|
|
path = File.expand_path(filename, directory_path)
|
2010-03-04 16:55:45 +00:00
|
|
|
subs << path if File.directory?(path)
|
2010-03-02 21:41:50 +00:00
|
|
|
end
|
|
|
|
end
|
2010-03-04 16:55:45 +00:00
|
|
|
return subs
|
2010-03-02 21:41:50 +00:00
|
|
|
end
|
|
|
|
|
2010-03-04 16:55:45 +00:00
|
|
|
# For each directory under the test root, cleanse the data model and run
|
|
|
|
# the test suite.
|
|
|
|
#
|
2010-03-02 21:41:50 +00:00
|
|
|
def run_all_suites()
|
2010-03-11 19:00:32 +00:00
|
|
|
time_stamp("Start time")
|
2010-03-04 16:55:45 +00:00
|
|
|
get_sub_directories(@test_root_directory).each do |suite_path|
|
2010-03-08 22:21:13 +00:00
|
|
|
suite_file_path = File.expand_path("Suite.html", suite_path)
|
|
|
|
if File.exist?(suite_file_path)
|
2010-03-15 20:23:04 +00:00
|
|
|
cleanse_data_model()
|
2010-03-08 22:21:13 +00:00
|
|
|
run_test_suite(suite_file_path)
|
2010-03-11 19:00:32 +00:00
|
|
|
else
|
|
|
|
log_warn("No suite file found in #{suite_path}")
|
2010-03-08 22:21:13 +00:00
|
|
|
end
|
2010-03-04 16:55:45 +00:00
|
|
|
end
|
2010-03-11 19:00:32 +00:00
|
|
|
time_stamp("End time")
|
2010-03-04 16:55:45 +00:00
|
|
|
end
|
2010-03-08 22:21:13 +00:00
|
|
|
|
|
|
|
# Before each suite, call the cleanser.
|
2010-03-04 16:55:45 +00:00
|
|
|
def cleanse_data_model()
|
2010-03-08 22:21:13 +00:00
|
|
|
@database_cleanser.cleanse()
|
2010-03-04 16:55:45 +00:00
|
|
|
end
|
2010-03-08 22:21:13 +00:00
|
|
|
|
|
|
|
def run_test_suite(suite_file_path)
|
|
|
|
suite_name = File.basename(File.dirname(suite_file_path))
|
2010-03-11 19:00:32 +00:00
|
|
|
log_info("Running suite #{suite_name}")
|
|
|
|
output_file = @output_manager.output_filename(suite_name)
|
2010-03-08 22:21:13 +00:00
|
|
|
|
|
|
|
args = []
|
|
|
|
args << "-jar" << @selenium_jar_path
|
|
|
|
args << "-singleWindow"
|
|
|
|
args << "-timeout" << @suite_timeout_limit.to_s
|
|
|
|
args << "-userExtensions" << @user_extensions_path
|
|
|
|
args << "-firefoxProfileTemplate" << @firefox_profile_template_path
|
|
|
|
args << "-htmlSuite" << "*firefox" << @website_url << suite_file_path << output_file
|
|
|
|
|
2010-03-15 20:23:04 +00:00
|
|
|
result = system("java", *args)
|
|
|
|
raise("Can't find the 'java' command!") if result == nil
|
|
|
|
if $?.exitstatus != 0
|
|
|
|
log_warn("Suite failed: '#{suite_name}, return code was #{$?.exitstatus}")
|
|
|
|
end
|
2010-03-02 21:41:50 +00:00
|
|
|
end
|
|
|
|
|
2010-03-11 19:00:32 +00:00
|
|
|
def time_stamp(label)
|
|
|
|
log_info("#{label}: #{DateTime.now.strftime('%Y/%m/%d %H:%M:%S')}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def log_info(message)
|
|
|
|
@output_manager.log("INFO ", message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def log_warn(message)
|
|
|
|
@output_manager.log("WARN ", message)
|
2010-03-02 21:41:50 +00:00
|
|
|
end
|
|
|
|
|
2010-03-08 22:21:13 +00:00
|
|
|
def log_error(message)
|
2010-03-11 19:00:32 +00:00
|
|
|
@output_manager.log("ERROR", message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_summary_html()
|
|
|
|
@output_manager.summarize()
|
2010-03-08 22:21:13 +00:00
|
|
|
end
|
|
|
|
|
2010-03-02 21:41:50 +00:00
|
|
|
# ------------------------------------------------------------------------------------
|
|
|
|
public
|
|
|
|
# ------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Set up and get ready to process.
|
|
|
|
#
|
2010-03-08 22:21:13 +00:00
|
|
|
def initialize(properties)
|
|
|
|
@website_url = properties['website_url']
|
|
|
|
@test_root_directory = properties['test_root_directory']
|
|
|
|
@user_extensions_path = properties['user_extensions_path']
|
|
|
|
@firefox_profile_template_path = properties['firefox_profile_template_path']
|
|
|
|
@suite_timeout_limit = properties['suite_timeout_limit'].to_i
|
|
|
|
@selenium_jar_path = properties['selenium_jar_path']
|
|
|
|
|
2010-03-02 21:41:50 +00:00
|
|
|
sanity_checks_on_parameters()
|
2010-03-08 22:21:13 +00:00
|
|
|
|
|
|
|
@database_cleanser = DatabaseCleanser.new(properties)
|
2010-03-11 19:00:32 +00:00
|
|
|
@output_manager = OutputManager.new(properties)
|
2010-03-08 22:21:13 +00:00
|
|
|
|
2010-03-02 21:41:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Run all of the test suites and produce an output summary page.
|
|
|
|
def run
|
|
|
|
run_all_suites()
|
|
|
|
create_summary_html()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-03-08 22:21:13 +00:00
|
|
|
#
|
|
|
|
#
|
|
|
|
# ------------------------------------------------------------------------------------
|
|
|
|
# Standalone calling.
|
|
|
|
# ------------------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
if ARGV.length == 0
|
|
|
|
raise("No arguments - usage is: ruby run_acceptance_test.rb <properties_file>")
|
|
|
|
end
|
|
|
|
if !File.file?(ARGV[0])
|
|
|
|
raise "File does not exist: '#{ARGV[0]}'."
|
|
|
|
end
|
2010-03-02 21:41:50 +00:00
|
|
|
|
2010-03-08 22:21:13 +00:00
|
|
|
properties = PropertyFileReader.read(ARGV[0])
|
2010-03-02 21:41:50 +00:00
|
|
|
|
2010-03-08 22:21:13 +00:00
|
|
|
ar = AcceptanceRunner.new(properties)
|
|
|
|
ar.run()
|