[LDTP-Dev] Launch application in specific locale?

Nagappan Alagappan nagappan at gmail.com
Fri Jan 6 18:00:35 PST 2012


Hi Andre,

Comments inline.

On Fri, Jan 6, 2012 at 3:36 PM, Andre Klapper <ak-47 at gmx.net> wrote:

> Hi,
>
> On Fri, 2012-01-06 at 10:34 -0800, Nagappan Alagappan wrote:
> > On Fedora 16, I tried like this:
> > launchapp('gedit', lang = 'de_DE')
> >
> > it worked as expected. I haven't used setlocale. Can you please verify
> > the above and see it works in your environment ?
>
> Thanks nags, this works perfectly!
>
> Now I'm trying this in Czech (open gedit in Czech and close it by going
> to File>Quit which is Soubor>Ukončit in Czech):
>
>  launchapp('gedit', lang = 'cs_CZ.utf8')
>  time.sleep (3)
>  selectmenuitem ('*gedit', 'mnuSoubor;mnuUkončit') # File > Quit
>

The following issue was bug in LDTP. I have now fixed in git head and the
above scenario works.

I would write the above code as:

launchapp('gedit', lang = 'cs_CZ.utf8')
waittillguiexist('*gedit')
selectmenuitem ('*gedit', 'mnuSoubor;mnuUkončit') # File > Quit
waittillguinotexist('*gedit')


> This triggers the following error:
>
> Traceback (most recent call last):
>  File "/usr/lib/python2.7/site-packages/pyatspi/registry.py", line 193, in
> eventWrapper
>    return callback(event)
>  File "/usr/lib/python2.7/site-packages/ldtpd/waiters.py", line 105, in
> _event_cb
>    self.event_cb(event)
>  File "/usr/lib/python2.7/site-packages/ldtpd/waiters.py", line 340, in
> event_cb
>    if self._match_name_to_acc(self._frame_name, event.source):
>  File "/usr/lib/python2.7/site-packages/ldtpd/utils.py", line 463, in
> _match_name_to_acc
>    _ldtpize_accessible_name[1])
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 5:
> ordinal not in range(128)
> Traceback (most recent call last):
>  File "/usr/lib/python2.7/site-packages/pyatspi/registry.py", line 193, in
> eventWrapper
>    return callback(event)
>  File "/usr/lib/python2.7/site-packages/ldtpd/core.py", line 118, in
> _event_cb
>    win_name = u'%s%s' % (abbrev_role, abbrev_name)
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 5:
> ordinal not in range(128)
> Traceback (most recent call last):
>  File "/usr/lib/python2.7/site-packages/ldtpd/waiters.py", line 85, in
> _timeout_cb
>    self.poll()
>  File "/usr/lib/python2.7/site-packages/ldtpd/waiters.py", line 336, in
> poll
>    gui, _window_name = self._get_window_handle(self._frame_name)
>  File "/usr/lib/python2.7/site-packages/ldtpd/utils.py", line 804, in
> _get_window_handle
>    if self._match_name_to_acc(window_name, gui):
>  File "/usr/lib/python2.7/site-packages/ldtpd/utils.py", line 463, in
> _match_name_to_acc
>    _ldtpize_accessible_name[1])
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 5:
> ordinal not in range(128)
> Traceback (most recent call last):
>  File "/usr/lib/python2.7/site-packages/pyatspi/registry.py", line 193, in
> eventWrapper
>    return callback(event)
>  File "/usr/lib/python2.7/site-packages/ldtpd/waiters.py", line 105, in
> _event_cb
>    self.event_cb(event)
>  File "/usr/lib/python2.7/site-packages/ldtpd/waiters.py", line 340, in
> event_cb
>    if self._match_name_to_acc(self._frame_name, event.source):
>  File "/usr/lib/python2.7/site-packages/ldtpd/utils.py", line 453, in
> _match_name_to_acc
>    if acc.name == name:
>  File "/usr/lib/python2.7/site-packages/pyatspi/Accessibility.py", line
> 177, in <lambda>
>    Atspi.Accessible.name = property(fget=lambda x:
> exwrap(Atspi.Accessible.get_name, x))
>  File "/usr/lib/python2.7/site-packages/pyatspi/Accessibility.py", line
> 154, in exwrap
>    raise LookupError
> LookupError
>
>
> As I have no idea how to fix (telling Python to interpret as UTF-8 or
> so?) I instead tried accessing an menuitem via using an index:
>
>  launchapp('gedit', lang = 'de_DE.utf8')
>  time.sleep (3)
>  selectmenuitem ('*gedit', 'mnu1;mnu1')
>

launchapp('gedit', lang = 'de_DE.utf8')
waittillguiexist('*gedit')
selectmenuitem ('*gedit', 'mnu#9') # For Quit
waittillguiexist('*gedit')

Note the hierarchy number is based on accessibility output.

How to get the object index:

getobjectproperty('window name', 'object name', 'obj_index')

example:
getobjectproperty('*gedit', 'mnuQuit', 'obj_index')


> This probably only works for objects without labels, as I get this error?:
>
> Traceback (most recent call last):
>  File "dummie.py", line 24, in <module>
>    selectmenuitem ('*gedit', 'mnu1;mnu1')
>  File "/usr/lib/python2.7/site-packages/ldtp/client.py", line 65, in
> __call__
>    return self.__send(self.__name, args)
>  File "/usr/lib/python2.7/xmlrpclib.py", line 1575, in __request
>    verbose=self.__verbose
>  File "/usr/lib/python2.7/site-packages/ldtp/client.py", line 180, in
> request
>    raise LdtpExecutionError(e.faultString.encode('utf-8'))
> ldtp.client_exception.LdtpExecutionError: Unable to find object name
> "mnu1" in application map
>
>
> My problem is likely similar to
> http://lists.freedesktop.org/archives/ldtp-dev/2009-October/000923.html
> - I would like to start the same application in several different human
> languages by looping over some locales, and perform the same steps
> everytime, and would like to use a language-independent way to access
> objects (either via somehow defining that for object-related commands in
> the script the en_US default shall be looked up while still showing the
> user interface in a different language; or by using "generic" names for
> objects, like indexes, that are language-independent).
>
> Any ideas, or is this not doable currently?
>

Above one works, but I recommend to do this way:

Use variable name in the script and import appropriate locale file which
has same variable name mapping with respective locale string.

example:

gedit_cs_CZ.py will have the following entries:

mnuFile = mnuSoubor
mnuQuit = mnuUkončit

gedit_de_DE.py will have similar entries as above, but with appropriate
locale string as value.

In actual test file:

import imp

languages = ['cs_CZ', 'de_DE']
for lang in languages:
   moduleName = 'gedit_%s' % lang
   locals()[moduleName] = __import__(moduleName)
   launchapp('gedit', lang = lang)
   waittillguiexist('*gedit')
   selectmenuitem('*gedit', '%s;%s' % (mnuFile, mnuQuit))

Hope the above code helps to start with automation.

Thanks
Nagappan


>
> My long-term aim is to have some script for localized screenshot
> generation for e.g. release notes, by the way.
>
> Thanks,
> andre
> --
> mailto:ak-47 at gmx.net | failed
> http://blogs.gnome.org/aklapper
>
> _______________________________________________
> LDTP-dev mailing list
> LDTP-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/ldtp-dev
>



-- 
Linux Desktop (GUI Application) Testing Project -
http://ldtp.freedesktop.org
http://nagappanal.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/ldtp-dev/attachments/20120106/8342bcdd/attachment.html>


More information about the LDTP-dev mailing list