Created
July 17, 2012 06:03
-
-
Save huangzhichong/3127500 to your computer and use it in GitHub Desktop.
main enter point for my Selenium-Rspec automation framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
require 'rspec' | |
require 'rspec/expectations' | |
require 'selenium-webdriver' | |
# ruby main.rb "Camps AUI BVT 1" "firefox" "INT" "9527" | |
# handle the arguments. | |
$plan_name=ARGV.shift.dup | |
$round_id= ARGV.shift.dup | |
$browser=ARGV.shift.dup | |
$env=ARGV.shift.dup | |
$as_debug_flag = false | |
if $plan_name.nil? or $browser.nil? or $env.nil? or $round_id.nil? | |
puts "$plan_name,$browser,$env can't be empty." | |
puts 'Eg1: ruby main.rb "Camps AUI BVT 1" "9527" "firefox" "LOCAL" -debug' | |
puts 'Eg2: ruby main.rb "Camps AUI BVT 1" "9527" "ie" "LOCAL"' | |
exit(1) | |
end | |
if ARGV.include?('-debug') then | |
ARGV.delete '-debug' | |
ARGV.push '-fd' | |
$as_debug_flag = true | |
else | |
result_path = $plan_name + Time.now.strftime("%Y%m%d-%H-%M-%S") | |
ARGV.push '-fh' | |
ARGV.push '-o' | |
ARGV.push "../output/test_results/#{result_path}.htm" | |
puts "You can find test result in: ../output/test_results/#{result_path}.htm" | |
end | |
Dir.mkdir "#{File.dirname(__FILE__)}/../output" if not File.exist? "#{File.dirname(__FILE__)}/../output" | |
path = File.join(File.dirname(__FILE__),"..","output","screenshots") | |
Dir.mkdir path if not File.exist? path | |
path = File.join(File.dirname(__FILE__),"..","output","test_results") | |
Dir.mkdir path if not File.exist? path | |
#load all the common functions | |
Dir[File.dirname(__FILE__) + '/../common/*.rb'].each do |file| | |
require file if file!="./"<<__FILE__ | |
end | |
#load all the libraries under ../libs | |
Dir.glob("#{File.dirname(__FILE__)}/../libs/*/**/*.rb").each do |f| | |
require f | |
end | |
#get the paramaters from config.yml for each test plan into $paremeters | |
$paremeters=YAML.load(File.open("#{File.dirname(__FILE__)}/#{$plan_name}/config.yml")) | |
#get project/marquee config from ../common/config.yml | |
CONFIG=YAML.load(File.open("#{File.dirname(__FILE__)}/../common/config.yml")) | |
$url_string = "#{CONFIG["marquee_server"]}status/update" | |
#init the parameters used for marquee | |
$errormessage="" | |
$result="Passed" | |
$errormessage="" | |
$screenshot="" | |
$error_log="" | |
#$service=MARQUEE::get_service_info("#{CONFIG['service_info']}",$env) | |
$service="FndWebServerCamps##Debug" | |
#$sqlserver_env_util = SqlserverUtil.new $env | |
if $browser.nil? || $env.nil? | |
puts "ERROR------------- browser or env should not be nil." | |
puts "browser: #{$browser}" | |
puts "environment: #{$env}" | |
exit 1 | |
else | |
puts "begin running with the configuration..." | |
puts "browser: #{$browser}" | |
puts "environment: #{$env}" | |
puts "marquee round_id: #{$round_id}" | |
puts "marquee url: #{$url_string}" | |
puts "plan name: #{$plan_name}" | |
end | |
describe $plan_name do | |
before(:all){ | |
$service = MARQUEE::get_service_info('FndWebserverCamps##CampsSessionManagementService##FndWebserverCui',$env) | |
puts $service | |
Common::start_browser | |
} | |
after(:all){ | |
MARQUEE::update_script_state $round_id,$plan_name,"End",$service | |
$driver.quit | |
} | |
before(:each){$errormessage= ""} | |
after(:each){ | |
example.result! | |
} | |
Dir[File.dirname(__FILE__) + "/#{$plan_name}/*.rb"].each {|file| require file} | |
$paremeters['actions'].split(',').each {|m| send m.to_sym} | |
end | |
require 'rspec/autorun' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment