Skip to content

Instantly share code, notes, and snippets.

@MagePsycho
Last active August 29, 2015 14:24
Show Gist options
  • Save MagePsycho/d3b13bea24e4d5c5ea1a to your computer and use it in GitHub Desktop.
Save MagePsycho/d3b13bea24e4d5c5ea1a to your computer and use it in GitHub Desktop.
Wrap in a function
#################################
# FUNCTIONS
#################################
def checkError(page)
if page.search('.msg_error').length > 0
puts "[ERROR]"
page.search('.msg_error li').each do |li|
puts li.text.strip
end
#`killall mysqld`
#`mysql.server start`
exit
end
end
def checkResult(page)
puts "[RESULT]"
#puts result_page.body
page.search('.msg_success li').each do |li|
puts li.text.strip
end
end
def checkNotice(page)
puts "[NOTICE]"
page.search('.msg-note').each do |note|
puts note.text.strip
end
if page.search('.msg-note').length > 0
puts "See log for more details"
end
end
#################################
# SCRIPT CODE
#################################
# ...
puts "Submitting db repair form..."
result_page = form.submit(form.button_with(:id => "button-continue"))
# Check if there is an error
checkError(result_page)
# Continue if there is not an error
# Check if it further requires submission
if result_page.search('button#button-continue').length > 0
checkNotice(result_page)
# Another form found?
puts "Submitting again..."
form = result_page.forms.first
result_page = form.submit(form.button_with(:id => "button-continue"))
checkResult(result_page)
checkNotice(result_page)
else
checkResult(result_page)
checkNotice(result_page)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment