Skip to content

Instantly share code, notes, and snippets.

@huangzhichong
Created July 17, 2012 10:06
Show Gist options
  • Save huangzhichong/3128534 to your computer and use it in GitHub Desktop.
Save huangzhichong/3128534 to your computer and use it in GitHub Desktop.
setup Selenium-Rspec automation framework with this sample script
def write(text="")
puts text
end
def say(message, subitem=false)
write "#{subitem ? " ->" : "--"} #{message}"
end
def say_custom(tag, text)
say "\033[1m\033[36m" + tag.to_s.rjust(10) + "\033[0m" + " #{text}"
end
def say_recipe(name)
say "\033[1m\033[36m" + "recipe".rjust(10) + "\033[0m" + " Running #{name} recipe..."
end
def say_wizard(text)
say_custom(@current_recipe || 'wizrd', text)
end
def ask(text, color=nil)
say("#{text} ", color)
gets.strip
end
def ask_wizard(question)
ask "\033[1m\033[30m\033[46m" + (@current_recipe || "prompt").rjust(10) + "\033[0m\033[36m" + " #{question}\033[0m"
end
def yes_wizard?(question)
answer = ask_wizard(question + " \033[33m(y/n)\033[0m")
case answer.downcase
when "yes", 'y'
true
when "no", 'n'
false
else
yes_wizard?(question)
end
end
def no_wizard?(question)
!yes_wizard?(question)
end
def multiple_choice(question, choices)
say_custom('question', question)
values = {}
choices.each_with_index do |choice, i|
values[(i+1).to_s] = choice[1]
say_custom (i+1).to_s + ')', choice[0]
end
answer = ask_wizard("Enter your selection:") while !values.keys.include?(answer)
values[answer]
end
say_wizard "Before start, please make sure,
1. you have ruby-1.9.2-p290 installed
2. you have SVN command line tool installed
3. you have DEVKit and ruby gem Bundler installed"
if yes_wizard? "Are you ready to start ?"
say_wizard "This helps you to setup a selenium automation very quick"
config = {}
# ----------Get SVN information
say_wizard "You will be asked for SVN information"
config["SVNPath"] = ask_wizard("what is your SVN path? ")
config["SVNUserName"] = ask_wizard("what is your SVN username? ")
config["SVNPassword"] = ask_wizard("what is your SVN password? ")
config["SVNPrefix"] = ask_wizard("any prefix in SVN comments? ")
config["root"] = ask_wizard "Enter the full path to put this framework: "
config["ProjectName"] = ask_wizard "Enter the project name: "
# ----------Build folder in local machine and push to SVN server
say "Adding project #{config['ProjectName']} under #{config['root']}"
say_wizard "creating folder..."
system "cd #{config['root']}; mkdir #{config['ProjectName']}"
say_wizard "adding folder to SVN..."
system "cd #{config['root']}; svn import #{config['ProjectName']} #{config['SVNPath']}/#{config['ProjectName']} -m '#{config['SVNPrefix']} Adding new folder into SVN' --username #{config['SVNUserName']} --password #{config['SVNPassword']}"
say_wizard "checkouting folder..."
system "cd #{config['root']}; svn co #{config['SVNPath']}/#{config['ProjectName']} --username #{config['SVNUserName']} --password #{config['SVNPassword']}"
# ----------Add reference to shared common folder
say_wizard "Add reference to shared common folder"
system "cd #{config['root']}/#{config['ProjectName']}; svn propset svn:externals 'common https://fndsvn.dev.activenetwork.com/foundation/QA%20Automation/Common/Selenium-Rspec/common/' . --username #{config['SVNUserName']} --password #{config['SVNPassword']}; svn up"
# ----------Add folder for libs and workflows
say_wizard "Add folder for libs and workflows"
system "cd #{config['root']}/#{config['ProjectName']}; mkdir libs workflows"
# ----------Add Gemfile
say_wizard "Add Gemfile, the required gem packages are defined inside this file"
system "cd #{config['root']}/#{config['ProjectName']}; touch Gemfile; curl -fsSL https://raw.github.com/gist/3127509/33e4fde5a2823aa0db5bd12e942168cce6dd0b38/Gemfile >> Gemfile"
# ----------Add main.rb
say_wizard "Add main.rb, this is the main enterance to run your scripts"
system "cd #{config['root']}/#{config['ProjectName']}/workflows; touch main.rb; curl -fsSL https://raw.github.com/gist/3127500/a6f033374c9c4327757fc7614899dadfa54e4d14/main.rb >> main.rb"
say_wizard "Add demo scripts and libs"
system "cd #{config['root']}/#{config['ProjectName']};mkdir libs/Demo;curl https://raw.github.com/gist/3128238/92af40c87042bab49a4f73723bf3d98187d9645c/BingHome.rb >> libs/Demo/BingHome.rb"
system "cd #{config['root']}/#{config['ProjectName']};mkdir workflows/Demo;curl -fsSL https://raw.github.com/gist/3128200/ba7e94603a933a827f4b5d3e18850a8081266cd0/config.yml >> workflows/Demo/config.yml"
system "cd #{config['root']}/#{config['ProjectName']};curl -fsSL https://raw.github.com/gist/3128194/3e1e543cb6d04bc6b6bfaec8a601833cc8ee3d43/automation_script.rb >> workflows/Demo/automation_script.rb"
say_wizard "Run bundler to install required gems"
system "cd #{config['root']}/#{config['ProjectName']};bundle install"
say_wizard "Done."
say_custom "Run your demo script with the command -- \033[33mruby main.rb Demo 123 firefox INT\033[0m","Tips"
say_custom "You need to get into the folder \033[33m#{config['root']}/#{config['ProjectName']}/workflows/\033[0m firstly","Tips"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment