Re: Accessing main window menus during C++ test run

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

Le 26/05/2022 à 10:11, Xisco Fauli a écrit :
The UItest framework [1] uses UNO commands to interact with the UI. However, Markus also evaluated the accessibility approach when he implemented it. You can read more in https://mmohrhard.wordpress.com/2016/09/07/ui-testing-in-libreoffice/. I hope it helps.

While as mentioned previously the article didn't really help, I just went ahead and tried to exercise the UITest setup for accessing the accessibility tree.

And a little unexpectedly, I there could access all UI elements through the accessibility interfaces just as I was trying to in C++. Does anybody know why this works there, and not in my CppUnit tests? Anything I should set up differently, await, or else?

Attached is a small UITest that shows there is everything, and especially all menu items. Now my goal is to get comparable results in CppUnit.

Thanks in advance,
Colomban
# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from uitest.framework import UITestCase

from com.sun.star.accessibility import AccessibleRole


def getRoleName(role):
    ''' Map an AccessibleRole value to its name '''
    for name in dir(AccessibleRole):
        if getattr(AccessibleRole, name) == role:
            return name
    return None

class TestAccessibleTree(UITestCase):
    def testTree(self):
        with self.ui_test.create_doc_in_start_center("writer") as component:
            w = component.getCurrentController().getFrame().getContainerWindow()
            w.toFront()

            def rec(o, d=0):
                print("% *s%s" % (d * 2, '', getRoleName(o.getAccessibleRole())))
                for i in range(0, o.getAccessibleChildCount()):
                    c = o.getAccessibleChild(i)
                    rec(c.getAccessibleContext(), d + 1)

            ctx = w.getAccessibleContext()

            rec(ctx)
            # check the menu (ctx[0]) has children
            self.assertGreaterEqual(ctx.getAccessibleChild(0).getAccessibleContext().getAccessibleChildCount(), 1)

# vim: set shiftwidth=4 softtabstop=4 expandtab:

[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux