Creating filters can be one of the trickiest things in QC OTA API usage. The first thing you might run into when using Ruby is how you set a filter. In Visual Basic you set a filter like this:
testsetFilter.Filter("CY_CYCLE_ID") = "> 0"
However, in Ruby you have to use the setproperty method e.g.
testsetFilter.setproperty('Filter', 'CY_CYCLE_ID', '> 0')
There were a couple of filters that I was struggling with, but finally got them working. The first one was when I wanted to filter only test cases for some specific test sets in the Test Lab. The working Ruby code looks like this:
testsetf = qc.TestSetFactory
testsetFilter = testsetf.Filter
testsetFilter.setproperty('Filter', 'CY_CYCLE_ID', '> 0')
testsetl = testsetf.NewList(testsetFilter.Text)
testf = qc.TestFactory
testFilter = testf.Filter
testFilter.setproperty('XFilter','TEST-TESTSET',testsetFilter.Text)
testl = testFilter.NewList()
... and I have a list with the filtered tests.
The second problem was with filtering tests for only a specific folder path in Test Plan. The working Ruby code looks like this:
aFilter.setproperty('Filter', 'TS_SUBJECT', "^Subject\\release1^")
... using the TS_PATH property only returned empty value and the trick with TS_SUBJECT property was to use "^ and ^" before and after the value. To get the test path from a list of tests e.g.
thisTest.Field('TS_SUBJECT').Path
Thoughts, examples and information about test automation, tools and scripting
Showing posts with label ruby scripting. Show all posts
Showing posts with label ruby scripting. Show all posts
Friday, September 14, 2012
QC OTA API Filter usage in Ruby
Thursday, August 30, 2012
Ruby charts
Managers love charts and statistics. Few open-source test automation tools are having any built-in tools for it. If you are using Ruby for scripting, then one of the easiest way to create charts is to use the googlecharts gem. It is using Google Charts API for creating charts.
You can install googlecharts gem with following command:
gem install googlecharts
Here is an example on how to use it:
require 'gchart'
g = Gchart.bar(:data => [5, 10, 20, 15],
:bar_colors => 'DDFFAA,5BFFA5,FFCDCD,FFADAD',
:stacked => true,
:size => '666x450',
:bg => 'f8f8ff',
:bar_width_and_spacing => '50,12,24',
:legend => ['1-Low','2-Medium','3-High'],
:max_value => 50,
:axis_with_labels => 'x,y',
:axis_labels => [['New','Open','Closed'],[5,10,15,20,25],
:title => "Defects Summary Graph - by Status group by Severity" )
gcharturl = g.split('?')[0]
gchartpostdata = g.split('?')[1]
url = URI.parse(gcharturl)
ht = Net::HTTP.new(url.host, url.port)
ht.start
res = ht.request_post(gcharturl, gchartpostdata)
ht.finish
open("summary.png", "wb") { |file|
file.write(res.body)
}
... and it would create an image close to this one:
With Ruby you can easily access MySQL database. So test results can be easily saved to database and the data can be used to create nice graphs for the management to love!
You can install googlecharts gem with following command:
gem install googlecharts
Here is an example on how to use it:
require 'gchart'
g = Gchart.bar(:data => [5, 10, 20, 15],
:bar_colors => 'DDFFAA,5BFFA5,FFCDCD,FFADAD',
:stacked => true,
:size => '666x450',
:bg => 'f8f8ff',
:bar_width_and_spacing => '50,12,24',
:legend => ['1-Low','2-Medium','3-High'],
:max_value => 50,
:axis_with_labels => 'x,y',
:axis_labels => [['New','Open','Closed'],[5,10,15,20,25],
:title => "Defects Summary Graph - by Status group by Severity" )
gcharturl = g.split('?')[0]
gchartpostdata = g.split('?')[1]
url = URI.parse(gcharturl)
ht = Net::HTTP.new(url.host, url.port)
ht.start
res = ht.request_post(gcharturl, gchartpostdata)
ht.finish
open("summary.png", "wb") { |file|
file.write(res.body)
}
... and it would create an image close to this one:
A couple of things to notice.
- The Gchart function call will return the URL to the graph. You can access it using GET, but it won't work if the URL is longer than 1024 characters . That's why I used POST to get the image data.
- The chart can contain max. 300000 pixels, so if you specify a size larger than that, then creating the image will fail.
With Ruby you can easily access MySQL database. So test results can be easily saved to database and the data can be used to create nice graphs for the management to love!
If you haven't used Ruby with MySQL, here's simple instructions:
- Install mysql gem with command: gem install mysql
- Make sure that libmysql.dll exist on your PC and that it is accessible (in a folder in PATH). Also the version need to match with the gem version. More information about it can be found from here.
How to use it e.g.
require 'mysql'
con = Mysql.new(myserver.com, 'myuser', 'mypwd', 'mydb')
con.query("UPDATE xxx SET yyy=1 WHERE 1=1")
con.close
More information about googlecharts:
Subscribe to:
Posts (Atom)
