Friday, December 5, 2014

Making autopilot 'human'

A bit late to share a feature that I implemented in Autopilot. First, a lot of thanks to Chris Lee for having the patience for the code review.

Autopilot is a test running that we at Canonical use for the UI testing at the integration level. This nice tool is pretty fun and easy to use with some basic knowledge of python. After using it to write automation for more than a year, I finally ended up contributing to the test runner code itself.

One of the issues that was discovered while writing tests with autopilot that when it was doing multiple clicks continuously there was very little gap between the events. Imagine a test where the phone dials a long number in less than a second ? Not so human, is it ?

The solution that was agreed upon, was to introduce a reusable mechanism in autopilot where it would try to "humanize" the click/tap events. So now, when you dial a number or do some calculation in calculator app with autopilot, it will have at least a delay of 100 ms between those events. The below code sample would make it easy to understand.

    # lets assume 'pointer' is the input emulator for Mouse
    self.pointer.click_object(target_object1, time_between_events=2)
    # This click will happen after somewhat ~2 seconds.
    self.pointer.click_object(target_object2)

The feature is in trunk and will hopefully be released with the next autopilot version.