Skip to content

Instantly share code, notes, and snippets.

@allenluce-zz
Created July 31, 2012 22:18
Show Gist options
  • Save allenluce-zz/3221149 to your computer and use it in GitHub Desktop.
Save allenluce-zz/3221149 to your computer and use it in GitHub Desktop.
require "mechanize"
require "benchmark"
story = "my-cow-ate-my-homework"
env = :staging
urls = {
:staging => 'http://hcd-connect-staging.herokuapp.com/stories/',
:devel => 'http://127.0.0.1:6544/stories/'
}
baseurl = urls[env]
comment = File.open('source.txt').readlines.sample
puts "Posting: #{comment[0,80]}..."
def timeIt(comment, &code)
retValue = nil
time = Benchmark.realtime do
retValue = code.call
end
puts "#{comment}: %.2fms" % (time*1000)
retValue
end
timeIt 'Total run time' do
a = Mechanize.new
a.get("#{baseurl}#{story}/") do |page|
login_page = timeIt "Receive login page" do
a.click(page.link_with(:text => %r/Log in/))
end
story_page = timeIt "Submit story page" do
login_page.form_with(:action => %r/login/) do |f|
f.login = 'allen@substantial.com'
f.password = 'PUT PASSWORD HERE'
f.came_from = "#{baseurl}#{story}/"
end.click_button
end
results = timeIt "Comment submit" do
form = story_page.form_with(:action => %r/comment/)
form['comment.text'] = comment
form.submit
end
puts results.parser.xpath("//div[@class='portalMessage']").children.to_html.gsub /"/, ''
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment