[Libreoffice-commits] core.git: sc/qa uitest/uitest

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Fri Jun 4 12:01:21 UTC 2021


 sc/qa/uitest/calc_tests9/tdf57841.py |    3 ++-
 sc/qa/uitest/calc_tests9/tdf60468.py |    3 ++-
 uitest/uitest/test.py                |   13 +++++++++----
 3 files changed, 13 insertions(+), 6 deletions(-)

New commits:
commit 4839b7ca3b5a730edf90ebebc749db145efec098
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Fri Jun 4 13:17:34 2021 +0200
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Fri Jun 4 14:00:42 2021 +0200

    Fix UITests that use File Open dialog to load documents
    
    It relied upon the component being loaded before the next
    Python code line is executed. OTOH, UITest.load_file uses
    EventListener to wait for the OnLoad event, which should
    be reused in all such cases.
    
    This moves the waiting code to a dedicated context manager,
    and modifies UITest.load_file to use it. Respective tests
    using the File dialog also use the new manager to wrap the
    action starting the loading process.
    
    Change-Id: Ic6eb0533b06e0ccc63dffc2ddc0e91d8159cae4a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116693
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/sc/qa/uitest/calc_tests9/tdf57841.py b/sc/qa/uitest/calc_tests9/tdf57841.py
index 4c3722bf29d2..0eb2d260b699 100644
--- a/sc/qa/uitest/calc_tests9/tdf57841.py
+++ b/sc/qa/uitest/calc_tests9/tdf57841.py
@@ -36,7 +36,8 @@ class Tdf57841(UITestCase):
         xTextDelimiter.executeAction("TYPE", mkPropertyValues({"TEXT": "\""}))
 
         xOK = xDialog.getChild('ok')
-        self.ui_test.close_dialog_through_button(xOK)
+        with self.ui_test.wait_until_component_loaded():
+            self.ui_test.close_dialog_through_button(xOK)
 
         document = self.ui_test.get_component()
 
diff --git a/sc/qa/uitest/calc_tests9/tdf60468.py b/sc/qa/uitest/calc_tests9/tdf60468.py
index 33230737db73..48af292df505 100644
--- a/sc/qa/uitest/calc_tests9/tdf60468.py
+++ b/sc/qa/uitest/calc_tests9/tdf60468.py
@@ -36,7 +36,8 @@ class Tdf60468(UITestCase):
         xTextDelimiter.executeAction("TYPE", mkPropertyValues({"TEXT": "\""}))
 
         xOK = xDialog.getChild('ok')
-        self.ui_test.close_dialog_through_button(xOK)
+        with self.ui_test.wait_until_component_loaded():
+            self.ui_test.close_dialog_through_button(xOK)
 
         document = self.ui_test.get_component()
 
diff --git a/uitest/uitest/test.py b/uitest/uitest/test.py
index b96bcdf1bc30..cfa9b83e5a1c 100644
--- a/uitest/uitest/test.py
+++ b/uitest/uitest/test.py
@@ -7,6 +7,7 @@
 
 import time
 import threading
+from contextlib import contextmanager
 from uitest.config import DEFAULT_SLEEP
 from uitest.config import MAX_WAIT
 from uitest.uihelper.common import get_state_as_dict
@@ -72,10 +73,10 @@ class UITest(object):
                 time_ += DEFAULT_SLEEP
                 time.sleep(DEFAULT_SLEEP)
 
-    def load_file(self, url):
-        desktop = self.get_desktop()
+    @contextmanager
+    def wait_until_component_loaded(self):
         with EventListener(self._xContext, "OnLoad") as event:
-            component = desktop.loadComponentFromURL(url, "_default", 0, tuple())
+            yield
             time_ = 0
             while time_ < MAX_WAIT:
                 if event.executed:
@@ -83,10 +84,14 @@ class UITest(object):
                     if len(frames) == 1:
                         self.get_desktop().setActiveFrame(frames[0])
                     time.sleep(DEFAULT_SLEEP)
-                    return component
+                    break
                 time_ += DEFAULT_SLEEP
                 time.sleep(DEFAULT_SLEEP)
 
+    def load_file(self, url):
+        with self.wait_until_component_loaded():
+            return self.get_desktop().loadComponentFromURL(url, "_default", 0, tuple())
+
     def execute_dialog_through_command(self, command, printNames=False):
         with EventListener(self._xContext, "DialogExecute", printNames=printNames) as event:
             if not self._xUITest.executeDialog(command):


More information about the Libreoffice-commits mailing list