in , ,

Ruby Performance Testing with Watir

A reader of mine asked me how they should go about performance testing some front end performance.  This is a good question, because tools such as JMeter are pretty good at getting performance metrics for load – but you must keep in mind that JMeter isn’t a browser and doesn’t always find front end performance issues.

For example, if a user had a AJAX call on a web page, and they click the button in browser – the response back to the browser of the loaded element probably will be lost in JMeter.

Ruby Performance Testing

In such a case, we can try to capture performance testing with timestamps.

In their example, they had a test that did the following:

  1. Instantiated the Watir browser object
  2. started a loop to iterate X times
  3. went to a URL and did some web actions
  4. closed the browser
  5. did some sql lookups

They made use of the watir-webdriver-performance gem… I can’t attest to it’s effectiveness… I tried using it many years ago and dropped it.  I preferred to simply add in time timers around the function calls:

t1 = Time.new

@browser.goto “http://google.com”

t2 = Time.new

p “time to load page #{t2-t1}.” 

You can use this type of timing for any AJAX function call, page load, db query… etc.  It’s a simple way to collect performance data.

About Loops

One more thing… when working with loops, be sure that if you close the browser in the loop, you also are creating it again.  In other words, if you have a loop like:

5.times do 

…..

end

and you close the browser in the loop, you must have a statement at the beginning of the loop to create a new browser… if the browser creation /instantiation is done outside the loop you’ll error out as the browser object is now gone.

Example code

 

5.times do
  @browser = Watir::Browser.new :ff
  t1 = Time.new
  @browser.goto "http://google.com"
  t2 = Time.new
  p "time is #{t2-t1}"
  @browser.close
end

What do you think?

0 points
Upvote Downvote

Total votes: 0

Upvotes: 0

Upvotes percentage: 0.000000%

Downvotes: 0

Downvotes percentage: 0.000000%

Written by Admin

I work for a Telecom company writing and testing software. My passion for writing code is expressed through this blog. It's my hope that it gives hope to any and all who are self-taught.

Comments

Leave a Reply

Loading…

Rails: Dynamic Population of Select Dropdowns

Python & Pentesting: Signals Exercise