[Libreoffice-commits] core.git: uitest/writer_tests

Muhammet Kara (via logerrit) logerrit at kemper.freedesktop.org
Fri Jul 12 07:27:16 UTC 2019


 uitest/writer_tests/autoredactDialog.py |  128 ++++++++++++++++++++++++++++++++
 1 file changed, 128 insertions(+)

New commits:
commit 11b60ba223b3667eb4718e160c9c14072c07a5c7
Author:     Muhammet Kara <muhammet.kara at collabora.com>
AuthorDate: Thu Jul 11 17:06:08 2019 +0300
Commit:     Muhammet Kara <muhammet.kara at collabora.com>
CommitDate: Fri Jul 12 09:26:02 2019 +0200

    Add UITest for AutoRedactDialog
    
    Includes:
    * test_open_AutoRedactDialog_writer()
    * test_add_target()
    
    Change-Id: Ia70f4cdf01f8a69aa42d0514eecc20d2a2ada530
    Reviewed-on: https://gerrit.libreoffice.org/75429
    Tested-by: Jenkins
    Reviewed-by: Muhammet Kara <muhammet.kara at collabora.com>

diff --git a/uitest/writer_tests/autoredactDialog.py b/uitest/writer_tests/autoredactDialog.py
new file mode 100644
index 000000000000..69a6fbef8d20
--- /dev/null
+++ b/uitest/writer_tests/autoredactDialog.py
@@ -0,0 +1,128 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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 uitest.framework import UITestCase
+from libreoffice.uno.propertyvalue import mkPropertyValues
+from uitest.uihelper.common import get_state_as_dict
+from uitest.uihelper.common import type_text
+from uitest.uihelper.common import select_pos
+import time
+import re
+from uitest.debug import sleep
+
+class AutoRedactDialog(UITestCase):
+
+    add_target_counter = 0
+
+    # Open the Auto Redact Dialog
+    def launch_and_get_autoredact_dialog(self):
+        self.ui_test.execute_dialog_through_command(".uno:AutoRedactDoc")
+        xDialog = self.xUITest.getTopFocusWindow()
+        self.assertTrue(xDialog is not None)
+        return xDialog
+
+    def getText(self, xObj):
+        return get_state_as_dict(xObj)["Text"]
+
+    def parseTargetContent(self, xObj):
+        return re.split(r'\t+', self.getText(xObj))
+
+    def clearTargetsbox(self, xDialog):
+        xTargetsListbox = xDialog.getChild("targets")
+        xDeleteBtn = xDialog.getChild("delete")
+
+        child_count = len(xTargetsListbox.getChildren())
+
+        if child_count < 1:
+            return
+
+        for i in range(0, child_count):
+            child = xTargetsListbox.getChild(0)
+            child.executeAction("SELECT", tuple())
+            xDeleteBtn.executeAction("CLICK", tuple())
+
+        # Verify
+        self.assertEqual(len(xTargetsListbox.getChildren()), 0)
+
+
+    def test_open_AutoRedactDialog_writer(self):
+        self.ui_test.create_doc_in_start_center("writer")
+        xDialog = self.launch_and_get_autoredact_dialog()
+        xcancBtn = xDialog.getChild("cancel")
+        self.ui_test.close_dialog_through_button(xcancBtn)
+        self.ui_test.close_doc()
+
+    def test_add_target(self):
+        self.ui_test.create_doc_in_start_center("writer")
+        xDialog = self.launch_and_get_autoredact_dialog()
+        xAddBtn = xDialog.getChild("add")
+
+        # Make sure we are starting with an empty targets list
+        self.clearTargetsbox(xDialog)
+
+        # Names need to be distinct
+        # ["target name", "target content"],
+        targets_list = [
+        ["target1", "content1"],
+        ["target2", "content2"],
+        ["target3", "content3"],
+        ]
+
+        def handle_add_dlg(dialog):                     #handle add target dialog - need special handling
+            xNewNameTxt=dialog.getChild("name")
+            xNewContentTxt=dialog.getChild("content")
+            xOKBtn = dialog.getChild("close")
+            xTypeList = dialog.getChild("type") #0: Text, 1: Regex, 2: Predefined
+
+            select_pos(xTypeList, 0) #Text
+            self.assertEqual(int(get_state_as_dict(xTypeList)["SelectEntryPos"]), 0)
+
+            type_text(xNewNameTxt, targets_list[self.add_target_counter][0])
+            type_text(xNewContentTxt, targets_list[self.add_target_counter][1])
+
+            self.ui_test.close_dialog_through_button(xOKBtn)
+
+        for i in range(0, len(targets_list)):
+            self.add_target_counter = i
+            self.ui_test.execute_blocking_action(xAddBtn.executeAction, args=('CLICK', ()),
+                    dialog_handler=handle_add_dlg)             #close add target dialog with OK button
+
+        # Make sure targets are added successfully
+        xTargetsListbox = xDialog.getChild("targets")
+        targets_box_state_dict = get_state_as_dict(xTargetsListbox)
+        self.assertEqual(int(targets_box_state_dict["Children"]), len(targets_list))
+
+        # Make sure targets are added with correct names and contents
+        for i in range(0, len(targets_list)):
+            child = xTargetsListbox.getChild(i)
+            child_text = self.parseTargetContent(child)
+            self.assertEqual(child_text[0], targets_list[i][0]) #name
+            self.assertEqual(child_text[2], targets_list[i][1]) #content
+
+        xcancBtn = xDialog.getChild("cancel")
+        self.ui_test.close_dialog_through_button(xcancBtn)
+
+        # Now let's make sure the dialog remembers last state
+        xDialog = self.launch_and_get_autoredact_dialog()
+        xTargetsListbox = xDialog.getChild("targets")
+        targets_box_state_dict = get_state_as_dict(xTargetsListbox)
+        self.assertEqual(int(targets_box_state_dict["Children"]), len(targets_list))
+
+        # Make sure targets are remembered with correct names and contents
+        for i in range(0, len(targets_list)):
+            child = xTargetsListbox.getChild(i)
+            child_text = self.parseTargetContent(child)
+            self.assertEqual(child_text[0], targets_list[i][0]) #name
+            self.assertEqual(child_text[2], targets_list[i][1]) #content
+
+        xcancBtn = xDialog.getChild("cancel")
+        self.ui_test.close_dialog_through_button(xcancBtn)
+
+        self.ui_test.close_doc()
+
+
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:


More information about the Libreoffice-commits mailing list