diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2020-10-26 16:07:20 +0100 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2020-10-26 19:51:23 +0100 |
commit | 5711858e00f542f1770d7ff3c035e8a2fdb72266 (patch) | |
tree | bcb16f0f8c835ccf7291e85a83d67414fee3fb50 /sw/qa/uitest/writer_tests3 | |
parent | 8f362f1bc5ceca9bde282b5db98282b1ab132309 (diff) |
uitest: move all writer tests to sw/qa/uitest
remove a few duplicated ones
Change-Id: I25b031c8fe11ae28f55978f8a25528c307a908e3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104814
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'sw/qa/uitest/writer_tests3')
-rw-r--r-- | sw/qa/uitest/writer_tests3/autoredactDialog.py | 198 | ||||
-rw-r--r-- | sw/qa/uitest/writer_tests3/customizeDialog.py | 135 | ||||
-rw-r--r-- | sw/qa/uitest/writer_tests3/goToPage.py | 48 | ||||
-rw-r--r-- | sw/qa/uitest/writer_tests3/tdf79236.py | 124 |
4 files changed, 505 insertions, 0 deletions
diff --git a/sw/qa/uitest/writer_tests3/autoredactDialog.py b/sw/qa/uitest/writer_tests3/autoredactDialog.py new file mode 100644 index 000000000000..015081431d7a --- /dev/null +++ b/sw/qa/uitest/writer_tests3/autoredactDialog.py @@ -0,0 +1,198 @@ +# -*- 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 +from uitest.uihelper.common import select_text +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() + + + def test_edit_target(self): + self.ui_test.create_doc_in_start_center("writer") + xDialog = self.launch_and_get_autoredact_dialog() + xAddBtn = xDialog.getChild("add") + xEditBtn = xDialog.getChild("edit") + + # Make sure we are starting with an empty targets list + self.clearTargetsbox(xDialog) + + # We first need to add a target so that we can edit it + 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, "TestTarget") + type_text(xNewContentTxt, "TestContent") + + self.ui_test.close_dialog_through_button(xOKBtn) + + self.ui_test.execute_blocking_action(xAddBtn.executeAction, args=('CLICK', ()), + dialog_handler=handle_add_dlg) #close add target dialog with OK button + + # Make sure target is added successfully + xTargetsListbox = xDialog.getChild("targets") + targets_box_state_dict = get_state_as_dict(xTargetsListbox) + self.assertEqual(int(targets_box_state_dict["Children"]), 1) + + # Select the added target + target_entry = xTargetsListbox.getChild(0) + target_entry.executeAction("SELECT", tuple()) + + # Now edit the target + def handle_edit_dlg(dialog): #handle add target dialog - need special handling + xNameTxt=dialog.getChild("name") + xContentTxt=dialog.getChild("content") + xOKBtn = dialog.getChild("close") + + xNameTxt.executeAction("CLEAR", tuple()) + xContentTxt.executeAction("CLEAR", tuple()) + + type_text(xNameTxt, "TestTargetEdited") + type_text(xContentTxt, "TestContentEdited") + + self.ui_test.close_dialog_through_button(xOKBtn) + + self.ui_test.execute_blocking_action(xEditBtn.executeAction, args=('CLICK', ()), + dialog_handler=handle_edit_dlg) #close add target dialog with OK button + + # Make sure target is still there + xTargetsListbox = xDialog.getChild("targets") + targets_box_state_dict = get_state_as_dict(xTargetsListbox) + self.assertEqual(int(targets_box_state_dict["Children"]), 1) + + # Make sure target has the new values + target_entry = xTargetsListbox.getChild(0) + target_text = self.parseTargetContent(target_entry) + self.assertEqual(target_text[0], "TestTargetEdited") #name + self.assertEqual(target_text[2], "TestContentEdited") #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: diff --git a/sw/qa/uitest/writer_tests3/customizeDialog.py b/sw/qa/uitest/writer_tests3/customizeDialog.py new file mode 100644 index 000000000000..5b6ab664346a --- /dev/null +++ b/sw/qa/uitest/writer_tests3/customizeDialog.py @@ -0,0 +1,135 @@ +# -*- 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/. + +import time + +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 select_pos + +class ConfigureDialog(UITestCase): + + def test_open_ConfigureDialog_writer(self): + + self.ui_test.create_doc_in_start_center("writer") + self.ui_test.execute_dialog_through_command(".uno:ConfigureDialog") + xDialog = self.xUITest.getTopFocusWindow() + + xcancBtn = xDialog.getChild("cancel") + xcancBtn.executeAction("CLICK", tuple()) + + self.ui_test.close_doc() + + def test_search_filter(self): + self.ui_test.create_doc_in_start_center("writer") + self.ui_test.execute_dialog_through_command(".uno:ConfigureDialog") + xDialog = self.xUITest.getTopFocusWindow() + + xfunc = xDialog.getChild("functions") + xSearch = xDialog.getChild("searchEntry") + + initialEntryCount = get_state_as_dict(xfunc)["Children"] + self.assertTrue(initialEntryCount != 0) + + xSearch.executeAction("SET", mkPropertyValues({"TEXT":"format"})) + + # Wait for the search/filter op to be completed + timeout = time.time() + 1 + while time.time() < timeout: + filteredEntryCount = get_state_as_dict(xfunc)["Children"] + if filteredEntryCount != initialEntryCount: + break + time.sleep(0.1) + + self.assertTrue(filteredEntryCount < initialEntryCount) + + xSearch.executeAction("CLEAR", tuple()) + + # Wait for the search/filter op to be completed + timeout = time.time() + 1 + while time.time() < timeout: + finalEntryCount = get_state_as_dict(xfunc)["Children"] + if finalEntryCount != filteredEntryCount: + break + time.sleep(0.1) + + self.assertEqual(initialEntryCount, finalEntryCount) + + + xcancBtn = xDialog.getChild("cancel") #button Cancel + xcancBtn.executeAction("CLICK", tuple()) #click the button + + self.ui_test.close_doc() + + def test_category_listbox(self): + self.ui_test.create_doc_in_start_center("writer") + self.ui_test.execute_dialog_through_command(".uno:ConfigureDialog") + xDialog = self.xUITest.getTopFocusWindow() + + xFunc = xDialog.getChild("functions") + xCategory = xDialog.getChild("commandcategorylist") + + initialEntryCount = get_state_as_dict(xFunc)["Children"] + self.assertTrue(initialEntryCount != 0) + + select_pos(xCategory, "1") + filteredEntryCount = get_state_as_dict(xFunc)["Children"] + self.assertTrue(filteredEntryCount < initialEntryCount) + + select_pos(xCategory, "0") + finalEntryCount = get_state_as_dict(xFunc)["Children"] + self.assertEqual(initialEntryCount, finalEntryCount) + + xcancBtn = xDialog.getChild("cancel") #button Cancel + xcancBtn.executeAction("CLICK", tuple()) #click the button + + self.ui_test.close_doc() + + def test_tdf133862(self): + self.ui_test.create_doc_in_start_center("writer") + + self.xUITest.executeCommand(".uno:InsertObjectStarMath") + + # Without the fix in place, calling customize dialog after inserting + # a formula object would crash + self.ui_test.execute_dialog_through_command(".uno:ConfigureDialog") + xDialog = self.xUITest.getTopFocusWindow() + + xcancBtn = xDialog.getChild("cancel") + xcancBtn.executeAction("CLICK", tuple()) + + self.ui_test.close_doc() + + def test_gear_button_menu(self): + self.ui_test.create_doc_in_start_center("writer") + + self.ui_test.execute_dialog_through_command(".uno:ConfigureDialog") + def close_dialog(dlg): + CancelBtn = dlg.getChild("cancel") + self.ui_test.close_dialog_through_button(CancelBtn) + + # Open the New Menu Dialog with id = 0 + xDialog = self.xUITest.getTopFocusWindow() + xmenugearbtn=xDialog.getChild("menugearbtn") + def show_dialog0(): + xmenugearbtn.executeAction("OPENFROMLIST", mkPropertyValues({"POS": "0" })) + self.ui_test.execute_blocking_action( action=show_dialog0, dialog_handler=close_dialog) + + # Open the Rename Menu Dialog with id = 2 + xDialog = self.xUITest.getTopFocusWindow() + xmenugearbtn=xDialog.getChild("menugearbtn") + def show_dialog2(): + xmenugearbtn.executeAction("OPENFROMLIST", mkPropertyValues({"POS": "2"})) + self.ui_test.execute_blocking_action( action=show_dialog2, dialog_handler=close_dialog) + + xDialog = self.xUITest.getTopFocusWindow() + xcancBtn = xDialog.getChild("cancel") + self.ui_test.close_dialog_through_button(xcancBtn) + + self.ui_test.close_doc() + +# vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/sw/qa/uitest/writer_tests3/goToPage.py b/sw/qa/uitest/writer_tests3/goToPage.py new file mode 100644 index 000000000000..7c56791a9066 --- /dev/null +++ b/sw/qa/uitest/writer_tests3/goToPage.py @@ -0,0 +1,48 @@ +# +# 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 +import org.libreoffice.unotest +import pathlib + +def get_url_for_data_file(file_name): + return pathlib.Path(org.libreoffice.unotest.makeCopyFromTDOC(file_name)).as_uri() + +class GoToPage_dialog(UITestCase): + + def test_go_to_page(self): + writer_doc = self.ui_test.load_file(get_url_for_data_file("3pages.odt")) + xWriterDoc = self.xUITest.getTopFocusWindow() + xWriterEdit = xWriterDoc.getChild("writer_edit") + + self.ui_test.execute_dialog_through_command(".uno:GotoPage") + xDialog = self.xUITest.getTopFocusWindow() + xPageText = xDialog.getChild("page") + xPageText.executeAction("TYPE", mkPropertyValues({"TEXT":"2"})) + xOkBtn = xDialog.getChild("ok") + xOkBtn.executeAction("CLICK", tuple()) + + self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "2") + + self.ui_test.execute_dialog_through_command(".uno:GotoPage") + xDialog = self.xUITest.getTopFocusWindow() + xPageText = xDialog.getChild("page") + xPageText.executeAction("TYPE", mkPropertyValues({"TEXT":"3a"})) + xOkBtn = xDialog.getChild("ok") + xOkBtn.executeAction("CLICK", tuple()) + + self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "3") + + # check cancel button + self.ui_test.execute_dialog_through_command(".uno:GotoPage") + xDialog = self.xUITest.getTopFocusWindow() + xCancelBtn = xDialog.getChild("cancel") + self.ui_test.close_dialog_through_button(xCancelBtn) + + self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "3") + + self.ui_test.close_doc() diff --git a/sw/qa/uitest/writer_tests3/tdf79236.py b/sw/qa/uitest/writer_tests3/tdf79236.py new file mode 100644 index 000000000000..8585e48d8c64 --- /dev/null +++ b/sw/qa/uitest/writer_tests3/tdf79236.py @@ -0,0 +1,124 @@ +# +# 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 +import time +from uitest.uihelper.common import get_state_as_dict, type_text + +class tdf79236(UITestCase): + + def test_paragraph(self): + + self.ui_test.create_doc_in_start_center("writer") + + xWriterDoc = self.xUITest.getTopFocusWindow() + xWriterEdit = xWriterDoc.getChild("writer_edit") + + type_text(xWriterEdit, "Test for tdf79236") + + document = self.ui_test.get_component() + + selection = self.xUITest.executeCommand(".uno:SelectAll") + + self.assertEqual(document.CurrentSelection.getByIndex(0).ParaLeftMargin, 0) + self.assertEqual(document.CurrentSelection.getByIndex(0).ParaRightMargin, 0) + self.assertEqual(document.CurrentSelection.getByIndex(0).ParaTopMargin, 0) + self.assertEqual(document.CurrentSelection.getByIndex(0).ParaBottomMargin, 0) + self.assertEqual(document.CurrentSelection.getByIndex(0).ParaFirstLineIndent, 0) + + self.assertEqual(document.CurrentSelection.getByIndex(0).String, "Test for tdf79236") + + self.ui_test.execute_dialog_through_command(".uno:ParagraphDialog") + + xParagraphDlg = self.xUITest.getTopFocusWindow() + + + xLeftSpnBtn = xParagraphDlg.getChild("spinED_LEFTINDENT") + for _ in range(0,20): + xLeftSpnBtn.executeAction("UP", tuple()) + + xRightSpnBtn = xParagraphDlg.getChild("spinED_RIGHTINDENT") + for _ in range(0,20): + xRightSpnBtn.executeAction("UP", tuple()) + + + xLineSpnBtn = xParagraphDlg.getChild("spinED_FLINEINDENT") + for _ in range(0,20): + xLineSpnBtn.executeAction("UP", tuple()) + + + xBottomSpnBtn = xParagraphDlg.getChild("spinED_BOTTOMDIST") + for _ in range(0,20): + xBottomSpnBtn.executeAction("UP", tuple()) + + xTopSpnBtn = xParagraphDlg.getChild("spinED_TOPDIST") + for _ in range(0,20): + xTopSpnBtn.executeAction("UP", tuple()) + + xOkBtn = xParagraphDlg.getChild("ok") + xOkBtn.executeAction("CLICK", tuple()) + + self.assertEqual(document.CurrentSelection.getByIndex(0).ParaLeftMargin, 3704) + self.assertEqual(document.CurrentSelection.getByIndex(0).ParaRightMargin, 3704) + self.assertEqual(document.CurrentSelection.getByIndex(0).ParaTopMargin, 5503) + self.assertEqual(document.CurrentSelection.getByIndex(0).ParaBottomMargin, 5503) + self.assertEqual(document.CurrentSelection.getByIndex(0).ParaFirstLineIndent, 3704) + + self.ui_test.execute_dialog_through_command(".uno:ParagraphDialog") + + xParagraphDlg = self.xUITest.getTopFocusWindow() + + xLeftSpnBtn = xParagraphDlg.getChild("spinED_LEFTINDENT") + for _ in range(0,20): + xLeftSpnBtn.executeAction("DOWN", tuple()) + + xRightSpnBtn = xParagraphDlg.getChild("spinED_RIGHTINDENT") + for _ in range(0,20): + xRightSpnBtn.executeAction("DOWN", tuple()) + + + xLineSpnBtn = xParagraphDlg.getChild("spinED_FLINEINDENT") + for _ in range(0,20): + xLineSpnBtn.executeAction("DOWN", tuple()) + + xBottomSpnBtn = xParagraphDlg.getChild("spinED_BOTTOMDIST") + for _ in range(0,20): + xBottomSpnBtn.executeAction("DOWN", tuple()) + + xTopSpnBtn = xParagraphDlg.getChild("spinED_TOPDIST") + for _ in range(0,20): + xTopSpnBtn.executeAction("DOWN", tuple()) + + xOkBtn = xParagraphDlg.getChild("ok") + self.ui_test.close_dialog_through_button(xOkBtn) + + self.assertEqual(document.CurrentSelection.getByIndex(0).ParaLeftMargin, 0) + self.assertEqual(document.CurrentSelection.getByIndex(0).ParaRightMargin, 0) + self.assertEqual(document.CurrentSelection.getByIndex(0).ParaTopMargin, 0) + self.assertEqual(document.CurrentSelection.getByIndex(0).ParaBottomMargin, 0) + self.assertEqual(document.CurrentSelection.getByIndex(0).ParaFirstLineIndent, 0) + + self.xUITest.executeCommand(".uno:Undo") + + self.assertEqual(document.CurrentSelection.getByIndex(0).ParaLeftMargin, 3704) + self.assertEqual(document.CurrentSelection.getByIndex(0).ParaRightMargin, 3704) + self.assertEqual(document.CurrentSelection.getByIndex(0).ParaTopMargin, 5503) + self.assertEqual(document.CurrentSelection.getByIndex(0).ParaBottomMargin, 5503) + self.assertEqual(document.CurrentSelection.getByIndex(0).ParaFirstLineIndent, 3704) + + self.xUITest.executeCommand(".uno:Undo") + + self.assertEqual(document.CurrentSelection.getByIndex(0).ParaLeftMargin, 0) + self.assertEqual(document.CurrentSelection.getByIndex(0).ParaRightMargin, 0) + self.assertEqual(document.CurrentSelection.getByIndex(0).ParaTopMargin, 0) + self.assertEqual(document.CurrentSelection.getByIndex(0).ParaBottomMargin, 0) + self.assertEqual(document.CurrentSelection.getByIndex(0).ParaFirstLineIndent, 0) + + self.assertEqual(document.CurrentSelection.getByIndex(0).String, "Test for tdf79236") + + self.ui_test.close_doc() + +# vim: set shiftwidth=4 softtabstop=4 expandtab: |