Jmeter: Statistics Aggregate Report

January 7, 2010 girlie Leave a comment

I found this interesting Jmeter plugin that would make your Jmeter reporting more effective.

To enhance your graph and reports with Jmeter, here’s a listener plugin that you could add in your distribution file.

1. Download Statistics Aggregate Report here

2. To install, unzip the file to your Jmeter directory. Please note that the zip file consists of 4 files and should be extracted as follows:

JMETER_HOME/lib/jcommon-1.0.5.jar

JMETER_HOME/lib/jdnc-0_6-all.jar

JMETER_HOME/lib/jfreechart-1.0.2.jar

JMETER_HOME/lib/ext/StatAggVisualizer.jar

3. Restart Jmeter, in GUI right click from your Testplan, select Add -> Listener menu, an option “Statistical Aggregate Report” should now be available. ;)

statistical aggregate report

Categories: jmeter

JMeter: Using property function to fetch data from user input

November 3, 2009 girlie Leave a comment

If our objective is to run our test scripts from the command line with variable number of users and ramp up period without editing our test plan every now and then, we could do this using JMeter’s simplified property function(“__P”).

First we need to set our Thread Group property as follows:

Thread group properties

Thread group thread and ramp-up properties

That is changing the value of Threads and Ramp-up as:

Threads: ${__P(group1.threads)}

Ramp-up: ${__P(group1.ramp)}

We could also use the property function when saving our test results. ${__property(result_dir)}/graph.jtl

Graph test result

Save graph result to a file

From the above settings, Jmeter will automatically generate a graph.jtl file inside result_dir folder.

Notice that number of threads, ramp-up period, result filename are all set as parameters.

After adding samplers and listeners to our testplan. We run our test from the command line by invoking:

jmeter -n -t test.jmx -Jgroup1.threads=10 -Jgroup1.ramp=5

From here onwards we could set different number of threads and ramp up period depending on the scenarios we’d like to test. Cool huh!

Categories: jmeter Tags: ,

JMeter: Run scripts from the console

October 29, 2009 girlie Leave a comment

Running Jmeter scripts from the console is one way of reducing the resources needed to execute the load as compared to a GUI mode.

From the console, we say:
jmeter -n -t <testplan filename> -l <listener filename>
(e.g. jmeter -n -t testplan.jmx -l listener.jtl)

The first time I tried to run my scripts from the command line, this is what I exactly saw:

D:\Jmeter\bin>jmeter -n -t testplan.jmx -l listener.jtl
 Created the tree successfully using testplan.jmx
 Starting the test @ Fri Oct 28 07:50:29 CST 2009 (1256255429500)
 Waiting for possible shutdown message on port 4445
 Tidying up ...    @ Fri Oct 28 07:50:34 CST 2009 (1256255434468)
 ... end of run

This information tells us that execution was successful. But if I wanted to see more results of the test, Jmeter provides a listener that displays the summary results also from the console where we type our commands.

We do this by adding the “Generate Summary Results” listener in our testplan.

generate results

Again we type the same command in the console:


D:\Jmeter\bin>jmeter -n -t testplan.jmx -l listener.jtl
Created the tree successfully using testplan.jmx
Starting the test @ Thu Oct 29 11:23:49 CST 2009 (1256786629265)
Waiting for possible shutdown message on port 4445
Generate Summary Results +     5 in   8.5s =    0.6/s Avg:   981 Min:   296 Max:  2344 Err:     0 (0.00%)
Generate Summary Results +     1 in   0.2s =    4.3/s Avg:   232 Min:   232 Max:   232 Err:     0 (0.00%)
Generate Summary Results =     6 in   9.6s =    0.6/s Avg:   856 Min:   232 Max:  2344 Err:     0 (0.00%)
Tidying up ...    @ Thu Oct 29 11:24:02 CST 2009 (1256786642453)
... end of run

From here we could clearly see the results happening per thread which I prefer more than the first.

Here are some commands that we could use when running test in nonGUI mode:

-h, –help -> prints usage information and exit
-n, –nongui -> run JMeter in nongui mode
-t, –testfile <argument> -> the jmeter test(.jmx) file to run
-l, –logfile <argument> -> the file to log samples to
-r, –runremote -> Start remote servers (as defined in remote_hosts)
-H, –proxyHost <argument> -> Set a proxy server for JMeter to use
-P, –proxyPort <argument> -> Set proxy server port for JMeter to use

example:

jmeter -n -t test1.jmx -l logfile1.jtl -H 192.168.1.1 -P 8080

could clearly see the results per thread which I prefer more than the first.

Categories: jmeter Tags: ,

JMeter: Simple Data Writer + Current Date

September 15, 2009 girlie Leave a comment

My first time to use Simple Data Writer, I have no idea how it works. So I figured it’s time to learn a new JMeter report (wink)

1. Add Simple Data Writer listener to my Google search script

2. Define its filename(where the generated result file will be saved) to:

D:\QA-Training\jakarta-jmeter-2.3.4\bin\reports\google.log.txt

3. Under “Log/Display” tick “Successes”

4. Run the test

I then opened google.log.txt in Open Office which is a comma delimited file and got this data:

simple data writer report

Looks helpful right? Except for the timeStamp which I can’t decipher the format… yet :)

Anyway, rerunning my test scripts updates the log file and appends the new results at the end of the file. But what if you’d like to parameterized your report and include the current time in your log file everytime you execute your test?

JMeter can absolutely do this… since it supports certain Functions and Variables

One of which is the __time function which returns the current time in various formats:

  • YMD = yyyyMMdd
  • HMS = HHmmss
  • YMDHMS = yyyyMMdd-HHmmss
  • USER1 = whatever is in the Jmeter property time.USER1
  • USER2 = whatever is in the Jmeter property time.USER2

From my current simple data writer listener, I edited its filename to:

D:\QA-Training\jakarta-jmeter-2.3.4\bin\reports\google.log.${__time(YMDHMS)}.txt

With this configuration, Jmeter generates a new log file with the current date and time in yyyyMMdd-HHmmss format, everytime I run the test. With regards to the timeStamp details, I’m still on my way to find it.

Bumper Stickers for Software QA

September 11, 2009 girlie 1 comment

Here’s my personal favorite:

* Software Testing: Where failure is always an option.
* Improving the world one bug at a time.
* Software Testing: You make it, we break it.
* Software Testers don’t break software; it’s broken when we get it.
* Software Testers: We break it because we care.
* If developers are so smart, why do testers have such job security?
* Life is too short for manual testing.
* Trust, But Verify.
* The Definition of an Upgrade: Take old bugs out, put new ones in.
* We break software so you don’t have to.
* I used to build software…now I break it! Its a lot more fun!!
* All code is guilty, until proven innocent.
* It’s Automation, Not Automagic!
* Quality Assurance, we take the blame so you don’t have to.
* In God we trust, and for everything else we test.

Pick yours in the list. =)

Bumper Stickers for Software QA

Categories: quality assurance Tags: , ,

Run your RC server via Rakefile

September 8, 2009 girlie Leave a comment

Gone tired of starting your selenium server by typing,

java -jar selenium-server.jar"

from your console or if you’re luckier create a batch file then run it to start your server...

Here’s a more powerful tool to do it. Utilizing the selenium-client ruby gem, first you need to create a rakefile and define the tasks that you want to do. For instance we want to tell our rake to do the following tasks:

1. Start selenium server,

2. Stop selenium server, and

3. Restart selenium server


require 'rubygems'
require 'selenium/rake/tasks' # use selenium rc rake tasks that are bundled with the selenium-client gem

SELENIUM_RC_JAR = Dir[File.dirname(__FILE__) + "/selenium-server*.jar"].first

# Start selenium server task
Selenium::Rake::RemoteControlStartTask.new(:'rc:start') do |rc|
 rc.port = 4444
 rc.timeout_in_seconds = 3 * 60
 rc.background = true
 rc.wait_until_up_and_running = true
 rc.jar_file = SELENIUM_RC_JAR
 rc.additional_args << " -multiWindow -firefoxProfileTemplate FirefoxProfile"

end

# Stop selenium server task
Selenium::Rake::RemoteControlStopTask.new(:'rc:stop') do |rc|
 rc.host = "localhost"
 rc.port = 4444
 rc.timeout_in_seconds = 3 * 60
end

# Restart selenium server task
desc "Restart Selenium Remote Control"
task :'rc:restart' do
 Rake::Task[:"rc:stop"].execute [] rescue nil
 Rake::Task[:"rc:start"].execute []
end

In your console go to the root folder where your rake file is saved, type
“rake -T” or “rake –task”

D:\Projects>rake -T

Console will list all available tasks defined in the rake:

(in D:/Projects)
rake rc:restart  # Restart Selenium Remote Control
rake rc:start    # Launch Selenium Remote Control
rake rc:stop     # Stop Selenium Remote Control running

From this list you can restart/start/close the server by simply invoking the commands  e.g. rake rc:start

Categories: selenium Tags: ,

Selenium and Ruby setup in Windows

September 4, 2009 gracielpablo 1 comment

Newbie in Ruby? Never heard Selenium? Had a reformat?
No sweat! Here’s a list of requirements to set up Selenium and Ruby in your Windows machine.

SELENIUM Remote-Control (RC )

–> is a test tool that allows you to write automated web application UI tests in any programming language against any HTTP website using any mainstream JavaScript-enabled browser.

  • extract the file anywhere in you local machine

JAVA

–> Requirement to run the selenium server, should be 1.5 or later version

  • install Java and configure your PATH environment variable correctly.
  • from the console, you can verify the installation by typing:  java -version

SELENIUM RC RUBY CLIENT DRIVER

  • requires Ruby

Rubygems

  • get the latest rubygem distribution as tgz or zip from here
  • extract the archive to your desired directory
  • 2 ways to install ruby:

from the console, go to the extracted directory then type:  ruby setup.rb

from your explorer, go to the extracted directory and double click setup.rb file

  • install the ruby client driver as a rubygem by typing:  gem install <ruby gem>

gem install selenium-client

  • install other gems that will be useful in your testing:

gem install rspec -v=1.2.6

gem install syntax

gem install faker

BDoc documentation

–> guide for all your rubygems documentations

  • from the console type: gem install aptinio-bdoc
  • then save the doc to your local, from the console  type:  bdoc //[path]

To get scripts or file from a repository through Git

  1. from the console, install github, bash or gui OpenInGitGui-2.0.zip
  2. generate an SSH rsa, type: $ ssh-keygen -t rsa
  3. copy the generated id_rsa pub
  4. paste it on the personal settings of ur public_key
  5. then clone
Categories: ruby, selenium Tags: , , ,

Get all hyperlinks within a page using Nokogiri

August 27, 2009 girlie Leave a comment

Task: Create a selenium script using Ruby that will collect all the available links within a page.

In essence we will try to create a method that will parse the html source of the current page and get all the elements with css(‘a’) or xpath ‘//a’ which indicates an anchor element. First let’s try to do it in IRB.

Steps:

1. Start your server and fire up your irb

2. In your console, type

require 'nokogiri'

3. Initialize the page we want to test, say we want to get all the hyperlinks within a google home page.

page = "http://www.google.com.ph"

4. Type the following commands

doc = Nokogiri::HTML(open(page))
links = doc.css('a')
hrefs = links.map {|link| link.attribute('href').to_s}.uniq.sort.delete_if
{|href| href.empty?}

Of course we would not like to do the procedure every time in our console, thus we could save it as a method in our class like the following:

# method that will get all links using Nokogiri
 def get_all_hrefs_nokogiri
   page = self.get_location()
   doc = Nokogiri::HTML(open(page))
   links = doc.css('a')

   hrefs = links.map {|link| link.attribute('href').to_s}.uniq.sort.delete_if {|href| href.empty?}
   return hrefs
 end

# get all links without using Nokogiri
 def get_all_hrefs
   hrefs = []
   self.get_xpath_count('//a').to_i.times do |i|
     if self.is_element_present("document.links[#{i}]") {hrefs << self.get_attribute("document.links[#{i}]@href")}
     end
     return hrefs
   end
 end
Categories: ruby Tags: ,

Convert XML to CSV with Nokogiri Ruby gem

August 14, 2009 girlie Leave a comment

Once upon a time, in an exciting world of software testing… Exist QA team had been using Testlink 1.8.3 as an open-source tool for test management. They were happy and it serves them well not until their client request for a copy of the testcases with complete details in EXCEL format. Doomed! Testlink only offers generation of test specification in HTML, OpenOffice Writer and MS Word but unfortunately not in EXCEL.

But just like a princess with a prince charming… then came Nokogiri(saw in Japanese) gem from Ruby which is an HTML, XML, SAX  and Reader parser. It supports document searching via XPATH and CSS3 Selectors. Not to mention FasterCSV also a Ruby gem which provides a complete interface to CSV files and data.  It offers tools to enable you to read and write to and from Strings or IO objects, as needed.

First they install these precious gems in their Windows machine by executing the following commands:

gem install nokogiri
gem install fastercsv

With these tools Exist QA carefully plans a plot to solve their problem. Since Testlink has the ability to export testsuite together with its testcases in XML format, they use this advantage to pass it as an input file in their Testlink parser code in Ruby. Here’s their gameplan:

require 'rubygems'
require 'nokogiri'
require 'fastercsv'

FIELDS = %w{Testsuite ID Name Summary Steps Expected_Result }

def new_testcase(csv, suite, id, name, summary, steps, expectedresult)

  testcases = []
  testcases << suite
  testcases << "GPC - #{id}"
  testcases << name
  testcases << summary
  testcases << steps
  testcases << expectedresult

  csv << FasterCSV::Row.new(FIELDS, testcases)
end  

csv = FasterCSV.open(ARGV[1],"w")
csv << FIELDS

doc = Nokogiri::XML(open(ARGV[0]))

doc.xpath('//testsuite').each do |tsuite|
  puts "#{tsuite.attribute('name')}\n"

  doc.xpath('//testcase').each do |tcase|
    new_testcase(csv, tsuite.attribute('name'), tcase.css('externalid').inner_text,
      tcase.attribute('name'), tcase.css('summary').inner_text,
      tcase.css('steps').inner_text, tsuite.css('expectedresults').inner_text)
  end
end

All they need to do is run the program in their console following this format:

ruby <filename> “<input>” “<output>”

Where filename is the name of the Testlink parser code; input is the xml filename(generated XML file from Testlink) and output is the csv filename(file where the parsed xml data will be saved).

ruby tlparser.rb “test.xml” “test.csv”

Nokogiri and FasterCSV saves the day! Now they can provide the testcase report in no time, every time their client request for it. And Exist QA lives happily ever after…

Categories: ruby Tags: , ,

Testlink Database SQL query

July 27, 2009 girlie Leave a comment

Objective # 1: Filter all testcases under Globe Portal Capabilities testplan (testplan_id = ‘9007′) and include summary, steps and expected result in the query

testplan_tcversions

tcversions
field description
field description
id internal id for testcase versioning id unique id per testcase
testplan_id id that determines the testplan tc_external_id external id
tcversion_id unique id per testcase version latest version
node_order order of the node summary summary of testcase
urgency degree of urgency steps steps of testcase
expected_results expected result
importance degree of importance
author_id author
creation_ts date of creation
updater_id updater
modification_ts date of modification
active is active?
is_open is open?
execution_type type of execution 1-manual;2-automated

SQL query:


SELECT * FROM testplan_tcversions LEFT JOIN tcversions ON tcversions.id = testplan_tcversions.tcversion_id

WHERE testplan_tcversions.testplan_id = '9007'

Problem: Testcases have does not indicate its component/testsuite (Contacts, Search, Widgets etc.)

Objective # 2: Include Component(from nodes_hierarchy table) for each testcase in the query

nodes_hierarchy node_types
field description
field description
id unique id per testcase id id of node
name description / name description description of node
parent_id id of the parent node
node_type type of node node_types table
id description
1 testproject
2 testsuite=Component
3 testcase=Testcase Summary
4 testcase_version=Testcase Steps
5 testplan
6 requirement_spec
7 requirement

SQL query:


SELECT a.*,  b.*, c.parent_id, c.node_type FROM testplan_tcversions a LEFT JOIN tcversions b ON b.id = a.tcversion_id LEFT JOIN nodes_hierarchy c ON a.tcversion_id = c.id

WHERE testplan_tcversions.testplan_id = '9007'

Problem: parent_id for testcases with node_type = ‘4′ is not sufficient to get the testcase component/testsuite

e.g.

nodes_hierarchy
id parent_id node_type description value
9068 9067 4 testcase steps < steps >
9067 9010 3 testcase summary User can view his Contacts
9010 9006 2 testsuite/component Personalizations: Contacts
9006 - 1 testproject Gportal Capabilities

In our result query for id = ‘9068′, ‘9067′ will only give us the summary/title of the testcase but not its component/testsuite , our next objective is to get the parent_id of ‘9067′

Objective # 3: Include the parent_id of  each parent_id for all the testcases in the query. Just like the following

id parent_id parent_id2 name
9068 9067 9010 Personalizations: Contacts

To get the parent_id for each parent_id from the nodes_hierarchy table, we create a subquery:


SELECT x.id, x.name, x.node_type_id, x.parent_id, y.parent_id as parent_id2

FROM nodes_hierarchy x left join nodes_hierarchy y ON x.parent_id = y.id

Then add our subquery to our major query in Objective # 1:

SELECT a.*, b.*, d.*
FROM testplan_tcversions a
LEFT JOIN tcversions b on a.tcversion_id = b.id
LEFT JOIN (<em>select x.id, x.name, x.node_type_id, x.parent_id, y.parent_id as parent_id2 from nodes_hierarchy x left join nodes_hierarchy y on x.parent_id = y.id</em>) d on a.tcversion_id = d.id
WHERE a.testplan_id = '9007'

:D Hats off Kuya Ed!

Categories: database Tags: , , , , ,