Dealing with UTF-8 characters

To create our automated tests for the Desktop at Ubuntu we are using LDTP (Linux Desktop Testing Project), a framework that relies on the Accesibility layer to manipulate the desktop objects.

LDTP comes with a python wrapper to be able to create tests in python. One of the tests that we wrote was Gedit Chains that tries to open Gedit, writes a string chain, saves it, and compares the resulting file with an already saved oracle file.

We have two test cases for this test. The first one wrote an ASCII string, “This is a very basic string”, and it was successfully run against Intrepid Alpha3. The second one tried to write a string with Japanese characters, to test UTF-8 with Gedit. This test failed. The problem root was that python-ldtp communicates with LDTP server with XML, and the necessary encoding was not being done properly. Therefore, each time I tried to run this test I got the following error:

settextvalue _message = generatexml (command.SETTEXTVALUE, _requestId,
windowName, componentName, text) File
"/var/lib/python-support/python2.5/", line 84, in generatexml
_argDebug += ", " + str (args [index]) UnicodeEncodeError: 'ascii' codec
can't encode characters in position 27-30: ordinal not in range(128 )

I posted the error on the LDTP mailing list and 24 hours later Nagappan, one of the main LDTP developers, checked the patch into their GIT repository (Thanks!!). I tried again my script with the LDTP GIT version and this time it run smoothly.

I think it is a very important fix, as UTF-8 characters are likely to give errors in text editors, terminals or browsers. I have created PPA packages for Intrepid that include this fix so that anyone can try this test. Intrepid packages are available at

One comment