... a little rspec(t) for Qlikview
In the past I've been asked to test a complex Qlikview Project with lots of variables, events and macros.
Manual testing was becoming too complex and boring, so I helped adding a bit of rspec to the mix.
I've been using rspec to test almost everything in the past few years and this was an intriguing new testing challenge.
step 0 - install the tools
- install Qlikview Desktop 11
- install ruby (my swiss-army integration tool of choice)
- install bundler
gem install bundler
- create the project folder
mkdir rspec_for_qlik
- create a file named
Gemfile
into the project folder with the following content:
source 'https://rubygems.org'
gem 'ruby-ole'
group :development, :test do
gem 'rspec'
end
- install all the dependencies
cd rspec_for_qlik && bundle install
- create the project directories
mkdir src && mkdir lib && mkdir spec
step 1 - build a small automation lib
Before even starting to build the actual tests, I wrote a small DRY library.
It's very easy to integrate win32 ole api with ruby (and even more easily java libraries with jruby indeed) as you can see in the following example:
# coding: utf-8
require 'win32ole'
class QlikDoc < Object
attr_accessor :qv_app, :qv_doc
public
def init()
@qv_app = WIN32OLE.new("QlikTech.QlikView")
end
def open_doc(file_path)
@qv_doc = qv_app.openDoc(file_path)
end
def close_doc()
@qv_doc.closeDoc()
end
def quit()
@qv_app.quit()
end
def set_variable(variable_name, variable_value)
qv_variable = @qv_doc.Variables(variable_name)
qv_variable.SetContent(variable_value, true)
end
def get_variable(variable_name)
qv_variable = @qv_doc.Variables(variable_name)
qv_variable.GetContent.String
end
def set_selection(field_name, field_value)
@qv_doc.Fields(field_name).Select(field_value)
end
def clear_selection(field_name)
@qv_doc.Fields(field_name).Clear
end
def press_button(object_id)
qv_button=@qv_doc.GetSheetObject(object_id)
qv_button.press
end
end
save the example above in a file called lib\qlik_doc.rb
step 2 - setup a simple test
Let's create our first test.
First of all create or copy the qvw file you want to test in src\testbed.qvw
.
n.b. in order to pass the test, the testbed.qvw
file must contain a variable named testbed_variable
Next create a rspec test in spec\qlik_spec.rb
with the following content:
# coding: utf-8
require './lib/qlik_doc'
RSpec.describe QlikDoc, :type => :model do
before(:all) do
@q = QlikDoc.new
@q.init()
end
before(:each) do
@q.open_doc("#{Dir.pwd}/src/testbed.qvw")
end
it "should set and read a variable named testbed_variable" do
@q.set_variable('testbed_variable','successful')
expect(@q.get_variable('testbed_variable')).to eq('successful')
end
after(:each) do
@q.close_doc()
end
after(:all) do
@q.quit()
end
end
step 3 - run the test!
To run the test and check the result it's a matter of typying rspec
.
The output should be
Finished in 2.98 seconds (files took 0.45292 seconds to load)
1 example, 0 failures
post scriptum
All the files above are available in github
In the git project there is no testbed.qvw
file. You will find, instead, a folder called testbed-prj
, containing the "xml" content of the original file. In order to create the correct testbed.qvw
file, just create a new and empty qvw
file named testbed.qvw
, open it and save it (under the hood, Qlikview will load the content from the testbed-pro folder...).
notes
front image by Mars Hill Church Seattle