test_linker
Description
This is a Ruby wrapper around the TestLink XMLRPC API, thus allowing access to your TestLink test projects, plans, cases, and results using Ruby. We’ve added a few helper methods as well to allow for getting at more of your data a little easier. This supports TestLink APIs 1.0 Beta 5 (from TestLink 1.8.x) and 1.0 (from TestLink 1.9.x).
Features
-
Basic wrapper around existing XMLRPC functions.
-
Allow for calling methods via Ruby style (#projects) or XMLRPC style (#getProjects).
-
Support for TestLink API versions 1.0 Beta 5 and 1.0.
-
Only one error/exception type: TestLinker::Error.
-
Limited set of helper methods, attempting to fill in gaps from the API.
Examples
Get results to a CSV file:
require 'test_linker'
require 'pp'
server = 'http://testlink'
dev_key = "90b7941411928ae0a84d19f365a01a63"
tl_project = "My nifty project"
tl = TestLinker.new(server, dev_key)
# Write out the CSV headers
csv_file_name = "report.csv"
csv_file = File.new(csv_file_name, "w")
csv_file.write "Build,Passed,Failed,Blocked,TOTAL,Overall %,Overall % (+B)\n"
# Get the list of test plans that I want to report on
project_id = tl.project_id tl_project
test_plans = tl.find_test_plans(project_id, /^Component.+1.0/)
puts "All test plans for project #{project_id}"
pp test_plans
# Get a list of all builds from those test plans
builds = test_plans.collect do |test_plan|
tl.builds_for_test_plan(test_plan[:id])
end
builds.flatten!
overall = {}
overall[:pass] = 0
overall[:failed] = 0
overall[:blocked] = 0
results = {}
# Total up results for each build and write to the CSV file
builds.each do |build|
results[:pass] = 0
results[:failed] = 0
results[:blocked] = 0
test_cases = tl.test_cases_for_test_plan(build[:testplan_id],
{ :buildid => build[:id] })
test_cases.each_value do |test_case|
case test_case[:exec_status]
when "p"
results[:pass] += 1
when "f"
results[:failed] += 1
when "b"
results[:blocked] += 1
end
end
overall[:pass] += results[:pass]
overall[:failed] += results[:failed]
overall[:blocked] += results[:blocked]
build_total = results[:pass] + results[:failed] + results[:blocked]
overall_rate = "%2.2f" % (overall[:pass] * 100 / (overall[:pass] +
overall[:failed]).to_f)
overall_rate_plus_blocked = "%2.2f" % (overall[:pass] * 100 / (overall[:pass] +
overall[:failed] + overall[:blocked]).to_f)
csv_line = "#{build[:name]},#{results[:pass]},#{results[:failed]},#{results[:blocked]},"
csv_line << "#{build_total},#{overall_rate},#{overall_rate_plus_blocked}\n"
csv_file.write csv_line
end
csv_file.close
Requirements
-
Rubies (tested)
-
1.8.7
-
1.9.2
-
jruby 1.6.1
-
ree 1.8.7
-
-
Gems
-
versionomy, ~> 0.4.0
-
-
Gems (development)
-
bundler, ~> 1.0.0
-
cucumber, ~> 0.10.0
-
fakeweb, ~> 1.3.0
-
rspec, ~> 2.5.0
-
simplecov, >= 0.4.0 (MRI 1.9.x only)
-
yard, ~> 0.6.0
-
Getting it all running (on the TestLink side):
-
Enable automation in the TestLink config file:
config.inc.php => $tlCfg->api->enabled = TRUE;
-
The user that needs to run the automated tests needs to generate a API key
that will be used in creating the connection. This is accomplished by logging in to TestLink and going to “Personal -> API Key -> Generate a new key”.
Install
$ gem install test_linker
Copyright
Copyright © 2011 sloveless
See LICENSE.rdoc for details.