Skip to content

Instantly share code, notes, and snippets.

@daniellimws
Last active April 14, 2018 05:35
Show Gist options
  • Save daniellimws/5d44ee76dc1ae8849a0b2dc07465f811 to your computer and use it in GitHub Desktop.
Save daniellimws/5d44ee76dc1ae8849a0b2dc07465f811 to your computer and use it in GitHub Desktop.
Set up testbed environment for GNOME software autopkgtests

Short guide to add automated test cases for GNOME Software

Setting up testbed environment

Firstly, you need to branch the repository. You can do that by running

bzr init-repo ubuntu-system-tests
cd ubuntu-system-tests
bzr branch lp:ubuntu-system-tests trunk
bzr branch trunk add-gnome-software-tests

To run the system tests, you will need autopilot, you can install that via pip.

pip install autopilot

Now, you need to set up a qemu image running Ubuntu 17.10 (it must be 17.10) as your testbed. Download the Ubuntu 17.10 iso if you haven't already done so. You'll also need qemu.

sudo apt install qemu-system-x86_64

Once you've got them downloaded and installed, go to the directory where you branched the repository. We'll be setting up the testbed environment as follows.

./system-tests build-qemu --iso "/path/to/your/ubuntu.iso" --img "/path/to/where/you/want/to/save/the/image"

This command may ask you to confirm and warn you that it will clear everything in the designated directory. Just be careful.

Once, that's done, do the following

./system-tests setup --img /path/to/your/image -s                                              

Now you should be able to run the tests.

./system-tests run ubuntu_system_tests.tests.test_gnome_software -s 

About the files

About the source files we need to care about, they are ubuntu_system_tests/helpers/gnome_sofware/cpo.py and ubuntu_system_tests/tests/test_gnome_software.py.

cpo.py, which stands for custom proxy object, is responsible as as interface for the tests to interact with the GUI. test_gnome_software.py as its name suggests, is full of the test cases.

At any point, please refrain from adding code to directly interact with the GUI from the test script. It is not a good programming practice and will most likely not get approved.

Some basic overview of what's inside the custom proxy object

Clicking

As you can see, we use input_manager as our primary method of clicking objects in the GUI. Sometimes, we'll face this error of the input_manager being unable to find positional attributes for the object to click on. To tackle this, we can use @retry to try it a few times until it passes.

Proxy object

If we want to access a different page for example, we can have a different proxy object to handle that, to prevent one proxy object to be cluttered with functions not even related. Currently we already have 2 others which are ResultsPage and ItemDetailsPage, and they work exactly the same as the main cpo.

Selecting

Selecting an object is the easiest thing in the world, use wait_select_single to select a single item or wait_select_many to select multiple items, by providing distinguishable attributes. Another way is to use select_single or select_many.

The difference between the two is the former waits until the item is loaded/found, while the latter will raise an exception if it does not find the object on the first try.

Debugging

Similar to Chrome, you can open GNOME software and press ctrl+shift+I to open the inspector to find out the names and properties of every object in the GUI.

That's all, I think?

With all these you should be able to create a few automated test cases for GNOME software. I think some are just pure copy pasting from other test cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment