//

Distributed automated acceptance testing with Robot and Chef

18.1.2012 | 3 minutes of reading time

I just go on working on some edge topics around the Robot Framework and blogging about it.

I’ve assume you’re familiar with Chef and Robot Framework as well as VirtualBox and Vagrant. For the basic setup, I suggest my previous post on a similar topic and on how to set up a basic environment: Provisioning of Java web applications using Chef, VirtualBox and Vagrant

What we now want to do is to distribute a Robot test to several virtual box instances. You would do this primarily in order to reduce the acceptance test run time. Whenever you see a way to run pieces of your acceptance test suite in parallel, you should do it. And with this blog post I would like to show you one possible way how to do it using very well proven tools.

So, you take Robot for acceptance testing. You take Chef to provision basic framework components to several machines. You take Vagrant and VirtualBox for a poor’s man virtualization and wiring with Chef. In a bigger setup, you sure would use different virtualization mechanisms, but Chef might still be your choice for configuration management.

How this all will work

First, you need my freshly created Chef cookbooks for the Robot tests: “robot” and “robottest”: https://github.com/pavlobaron/cookbooks/tree/pb_new

Then, you need to configure your Vagrant (again, I build upon the setup from the previous post). My Vagrantfile looks like this:

1# -*- mode: ruby -*-
2# vi: set ft=ruby :
3 
4Vagrant::Config.run do |config|
5  config.vm.box = "lucid32"
6 
7  (1..1).each do |index|
8    config.vm.define "n#{index}".to_sym do |cfg|
9      cfg.vm.host_name = "n#{index}"
10      cfg.vm.network("192.168.100.1#{index}")
11      cfg.vm.forward_port "ssh", 22, "220#{index}".to_i
12      cfg.ssh.max_tries = 100
13      cfg.vm.customize do |vm|
14        vm.name = "Node #{index} VM"
15        vm.memory_size = 512
16      end
17 
18      cfg.vm.provision :chef_client do |chef|
19        chef.chef_server_url = "http://192.168.100.1:4000"
20        chef.validation_key_path = "/etc/chef/validation.pem"
21        chef.node_name = "n#{index}"
22        chef.add_role :robot
23        chef.json.merge!({
24          :robottest => {
25            :runner => "p",
26            :urlbase => "http://192.168.100.1/files",
27            :archive => "test#{index}.tar.gz",
28            :test => "test/test#{index}.txt"
29          }
30        })
31      end
32    end
33  end
34end
35

As you can see, I work only with one VirtualBox node – for simplicity. When you look at my loop, you can easily see that I can add whatever further nodes, as long as I use my own naming convention.

Now we need a Chef role like this:

1{
2  "name": "robot",
3  "default_attributes": {
4  },
5  "json_class": "Chef::Role",
6  "env_run_lists": {
7  },
8  "run_list": [
9    "recipe[robot]",
10    "recipe[robottest]"
11  ],
12  "description": "Baseline to run robot tests",
13  "chef_type": "role",
14  "override_attributes": {
15    "robot": {
16      "version": "2.7a1"
17    },
18    "java": {
19      "install_flavor": "sun"
20    }
21  }
22}
23

The “robot” cookbook itself depends on apt, python etc. This role can be found in the Vagrantfile, so every VirtualBox node will have all the basic stuff provisioned as well as the Robot Framework installed. The “robottest” cookbook is actually there to run the tests. Look at the Vagrantfile how the relevant attributes for the node are getting set according to the documentation I’ve provided with my new cookbooks (README there).

I have a local Apache on the host which provides downloadable tar.gz files in a subdirectory /files (urlbase). My cookbook downloads the gzipped tar, unpacks it and runs a named test there, writing results to the same directory where the test archive has been unpacked in. Archive ensures that you can provision more than just one test but also libraries and dependencies (though I don’t use them in the first step and will add this functionality later). You now can download these files, look at them on the target machine or move them to a location where Apache could access and “show” them from. It’s up to you.

As you hopefully can see, if you follow the naming conventions I use in my Vagrantfile, you can easily provision different tests to different machines. This allows you to do automated distributed acceptance testing with Robot, on the Chef rails.

Please let me know if I should modify anything in the cookbooks or just feel free to contribute. Feedback is anytime very welcome.

share post

Likes

0

//

Gemeinsam bessere Projekte umsetzen

Wir helfen Deinem Unternehmen

Du stehst vor einer großen IT-Herausforderung? Wir sorgen für eine maßgeschneiderte Unterstützung. Informiere dich jetzt.

Hilf uns, noch besser zu werden.

Wir sind immer auf der Suche nach neuen Talenten. Auch für dich ist die passende Stelle dabei.