[Libreoffice-commits] core.git: 4 commits - uitest/demo_ui uitest/uitest

Markus Mohrhard markus.mohrhard at googlemail.com
Sat Jul 16 22:22:18 UTC 2016


 uitest/demo_ui/handle_multiple_files.py |   66 ++++++++++++++++++++++++++++++++
 uitest/uitest/test.py                   |   21 ++++++++++
 2 files changed, 87 insertions(+)

New commits:
commit 07403d67e43da90563a6a8dc4817f1e90feefa59
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sun Jul 17 00:19:29 2016 +0200

    uitest: add demo showing how to select active frame
    
    Change-Id: I76bb79047b9d15228dc29379203300ccf50fc4f1

diff --git a/uitest/demo_ui/handle_multiple_files.py b/uitest/demo_ui/handle_multiple_files.py
index 9fdcd86..ab56c55 100644
--- a/uitest/demo_ui/handle_multiple_files.py
+++ b/uitest/demo_ui/handle_multiple_files.py
@@ -48,4 +48,19 @@ class HandleFiles(UITestCase):
 
         self.ui_test.close_doc()
 
+    def test_select_frame(self):
+        calc_file = self.ui_test.load_file(get_url_for_data_file("test.ods"))
+
+        calc_file2 = self.ui_test.load_file(get_url_for_data_file("test2.ods"))
+        frames = self.ui_test.get_frames()
+        self.assertEqual(len(frames), 2)
+        frames[0].activate()
+
+        self.ui_test.close_doc()
+
+        frames = self.ui_test.get_frames()
+        self.assertEqual(len(frames), 1)
+
+        self.assertTrue(frames[0].getTitle().startswith("test2.ods"))
+
 # vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit b29d15dec890f1defd99a792c28d3a1f576847e0
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sun Jul 17 00:18:45 2016 +0200

    uitest: don't hard code my path in test
    
    Change-Id: I65959552f74d860ee8773f1f5649bd160686f288

diff --git a/uitest/demo_ui/handle_multiple_files.py b/uitest/demo_ui/handle_multiple_files.py
index cc36baf..9fdcd86 100644
--- a/uitest/demo_ui/handle_multiple_files.py
+++ b/uitest/demo_ui/handle_multiple_files.py
@@ -13,14 +13,24 @@ from uitest.framework import UITestCase
 from uitest.debug import sleep
 
 import time
+import os
+import pathlib
+
+def get_data_dir():
+    current_dir = os.path.dirname(os.path.realpath(__file__))
+    return os.path.join(current_dir, "data")
+
+def get_url_for_data_file(file_name):
+    path = os.path.join(get_data_dir(), file_name)
+    return pathlib.Path(path).as_uri()
 
 class HandleFiles(UITestCase):
 
     def test_load_file(self):
 
-        calc_file = self.ui_test.load_file("file:///home/moggi/devel/libo9/uitest/data/test.ods")
+        calc_file = self.ui_test.load_file(get_url_for_data_file("test.ods"))
 
-        calc_file2 = self.ui_test.load_file("file:///home/moggi/devel/libo9/uitest/data/test2.ods")
+        calc_file2 = self.ui_test.load_file(get_url_for_data_file("test2.ods"))
 
         frames = self.ui_test.get_frames()
         self.assertEqual(len(frames), 2)
commit 5f5575f8c4f7766db0c7468a03ce1bed46821cfd
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sat Jul 16 23:44:17 2016 +0200

    uitest: add demo for handling two files
    
    Change-Id: I03cbe67922df521a6cef5f3448c0c9dce10b662d

diff --git a/uitest/demo_ui/handle_multiple_files.py b/uitest/demo_ui/handle_multiple_files.py
new file mode 100644
index 0000000..cc36baf
--- /dev/null
+++ b/uitest/demo_ui/handle_multiple_files.py
@@ -0,0 +1,41 @@
+# -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+#
+# 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 libreoffice.uno.propertyvalue import mkPropertyValues
+from libreoffice.uno.eventlistener import EventListener
+
+from uitest.framework import UITestCase
+
+from uitest.debug import sleep
+
+import time
+
+class HandleFiles(UITestCase):
+
+    def test_load_file(self):
+
+        calc_file = self.ui_test.load_file("file:///home/moggi/devel/libo9/uitest/data/test.ods")
+
+        calc_file2 = self.ui_test.load_file("file:///home/moggi/devel/libo9/uitest/data/test2.ods")
+
+        frames = self.ui_test.get_frames()
+        self.assertEqual(len(frames), 2)
+
+        self.ui_test.close_doc()
+
+        frames = self.ui_test.get_frames()
+        self.assertEqual(len(frames), 1)
+
+        # this is currently still necessary as otherwise
+        # the command is not forwarded to the correct frame
+        # TODO: provide an additional event that we can use
+        #       and get rid of the sleep
+        time.sleep(1)
+
+        self.ui_test.close_doc()
+
+# vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit f260194ae283fde803c4cf30c913ecc0d9d10358
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sat Jul 16 23:43:50 2016 +0200

    uitest: add some work to load several documents
    
    Change-Id: If9bf0e88fd7b223f10c31e3b0ed357da2bc4f9b0

diff --git a/uitest/uitest/test.py b/uitest/uitest/test.py
index 4eb8c84..c9c51f5 100644
--- a/uitest/uitest/test.py
+++ b/uitest/uitest/test.py
@@ -23,6 +23,27 @@ class UITest(object):
         self._xUITest = xUITest
         self._xContext = xContext
 
+    def get_desktop(self):
+        desktop = self._xContext.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", self._xContext)
+        return desktop
+
+    def get_frames(self):
+        desktop = self.get_desktop()
+        frames = desktop.getFrames()
+        return frames
+
+    def load_file(self, url):
+        desktop = self.get_desktop()
+        with EventListener(self._xContext, "OnLoad") as event:
+            component = desktop.loadComponentFromURL(url, "_default", 0, tuple())
+            time_ = 0
+            while time_ < 30:
+                if event.executed:
+                    time.sleep(DEFAULT_SLEEP)
+                    return component
+                time_ += DEFAULT_SLEEP
+                time.sleep(DEFAULT_SLEEP)
+
     def execute_dialog_through_command(self, command):
         with EventListener(self._xContext, "DialogExecute") as event:
             self._xUITest.executeCommand(command)


More information about the Libreoffice-commits mailing list