diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2021-06-21 16:21:30 +0200 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2021-06-22 14:46:39 +0200 |
commit | be0a41679fea524e0935dc6617b5e65349812dd1 (patch) | |
tree | f14372226d5054c045f954e38ea09da5c412215b /sd/qa/uitest | |
parent | 14069d84174ca7a4e60db4d75912903e9679b643 (diff) |
uitest: guard load_file
Mostly done by a script
for motivation, see 89aaa17a0a4413f07da2bc5084b0164f15dc01ac
< UITest: introduce guarded context managers >
Change-Id: Ia924293dc2a12230fd13f69fd734875ced86be8a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117593
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'sd/qa/uitest')
-rw-r--r-- | sd/qa/uitest/findReplace/findReplace.py | 214 | ||||
-rw-r--r-- | sd/qa/uitest/impress_tests/embedded.py | 30 | ||||
-rw-r--r-- | sd/qa/uitest/impress_tests/tdf141297.py | 20 |
3 files changed, 129 insertions, 135 deletions
diff --git a/sd/qa/uitest/findReplace/findReplace.py b/sd/qa/uitest/findReplace/findReplace.py index 2d300e249517..b0f26723b1dc 100644 --- a/sd/qa/uitest/findReplace/findReplace.py +++ b/sd/qa/uitest/findReplace/findReplace.py @@ -13,113 +13,111 @@ from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file, typ class findReplace(UITestCase): def test_find_impress(self): - impress_doc = self.ui_test.load_file(get_url_for_data_file("findReplace.odp")) - document = self.ui_test.get_component() - # print(dir(document)) - # xPages= document.CurrentController.getCurrentPage().Number - # print(xPages) - - # check current slide is 1 - self.assertEqual(document.CurrentController.getCurrentPage().Number, 1) - - # search for string "second" - self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog") - xDialog = self.xUITest.getTopFocusWindow() - searchterm = xDialog.getChild("searchterm") - searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"second"})) #2nd slide - xsearch = xDialog.getChild("search") - xsearch.executeAction("CLICK", tuple()) - - # verify we moved to slide 2 - self.assertEqual(document.CurrentController.getCurrentPage().Number, 2) - - # search for string "third" - searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) - searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"})) - searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"third"})) - xsearch.executeAction("CLICK", tuple()) - - #verify we moved to slide 3 - self.assertEqual(document.CurrentController.getCurrentPage().Number, 3) #3rd slide - - # close the dialog - xcloseBtn = xDialog.getChild("close") - self.ui_test.close_dialog_through_button(xcloseBtn) - - # now open dialog and verify find="third" (remember last value); - # replace value with "First" (click match case) with word "Replace" - # click twice the Replace button, check "Replace first first" - - # open the dialog again - self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog") - xDialog = self.xUITest.getTopFocusWindow() - - # verify search string is still "third" from previous search - searchterm = xDialog.getChild("searchterm") - self.assertEqual(get_state_as_dict(searchterm)["Text"], "third") - - # replace it with "First" - searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) - searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"})) - searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"First"})) - - # click "match case" - matchcase = xDialog.getChild("matchcase") - matchcase.executeAction("CLICK", tuple()) #click match case - - # set the replace string to "Replace" - replaceterm = xDialog.getChild("replaceterm") - replaceterm.executeAction("TYPE", mkPropertyValues({"TEXT":"Replace"})) #replace textbox - - # hit replace button 2 times - replace = xDialog.getChild("replace") - replace.executeAction("CLICK", tuple()) - replace.executeAction("CLICK", tuple()) #click twice Replace button (one selects, second replaces) - - # close and reopen the dialog, because of bug 122788 - xcloseBtn = xDialog.getChild("close") - self.ui_test.close_dialog_through_button(xcloseBtn) - self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog") - xDialog = self.xUITest.getTopFocusWindow() - - # now replace first (uncheck match case) with word "aaa" - click once Replace All button, check "Replace aaa aaa" - matchcase = xDialog.getChild("matchcase") - matchcase.executeAction("CLICK", tuple()) # uncheck match case - - replaceterm = xDialog.getChild("replaceterm") - replaceterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) - replaceterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"})) - replaceterm.executeAction("TYPE", mkPropertyValues({"TEXT":"aaa"})) - replaceall = xDialog.getChild("replaceall") - replaceall.executeAction("CLICK", tuple()) # click on replace all button - xcloseBtn = xDialog.getChild("close") - self.ui_test.close_dialog_through_button(xcloseBtn) #close the dialog - - # go to second page - self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog") - xDialog = self.xUITest.getTopFocusWindow() - searchterm = xDialog.getChild("searchterm") - searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"second"})) #2nd slide - xsearch = xDialog.getChild("search") - xsearch.executeAction("CLICK", tuple()) - xcloseBtn = xDialog.getChild("close") - self.ui_test.close_dialog_through_button(xcloseBtn) - self.assertEqual(document.CurrentController.getCurrentPage().Number, 2) - #now check if text "Replace aaa aaa" is on first slide - self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog") - xDialog = self.xUITest.getTopFocusWindow() - searchterm = xDialog.getChild("searchterm") - backsearch = xDialog.getChild("backsearch") - searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) - searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"})) - searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"Replace aaa aaa"})) - backsearch.executeAction("CLICK", tuple()) - #verify - self.assertEqual(document.CurrentController.getCurrentPage().Number, 1) #1st slide - - xcloseBtn = xDialog.getChild("close") - self.ui_test.close_dialog_through_button(xcloseBtn) - - self.ui_test.close_doc() + with self.ui_test.load_file(get_url_for_data_file("findReplace.odp")) as impress_doc: + document = self.ui_test.get_component() + # print(dir(document)) + # xPages= document.CurrentController.getCurrentPage().Number + # print(xPages) + + # check current slide is 1 + self.assertEqual(document.CurrentController.getCurrentPage().Number, 1) + + # search for string "second" + self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog") + xDialog = self.xUITest.getTopFocusWindow() + searchterm = xDialog.getChild("searchterm") + searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"second"})) #2nd slide + xsearch = xDialog.getChild("search") + xsearch.executeAction("CLICK", tuple()) + + # verify we moved to slide 2 + self.assertEqual(document.CurrentController.getCurrentPage().Number, 2) + + # search for string "third" + searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) + searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"})) + searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"third"})) + xsearch.executeAction("CLICK", tuple()) + + #verify we moved to slide 3 + self.assertEqual(document.CurrentController.getCurrentPage().Number, 3) #3rd slide + + # close the dialog + xcloseBtn = xDialog.getChild("close") + self.ui_test.close_dialog_through_button(xcloseBtn) + + # now open dialog and verify find="third" (remember last value); + # replace value with "First" (click match case) with word "Replace" + # click twice the Replace button, check "Replace first first" + + # open the dialog again + self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog") + xDialog = self.xUITest.getTopFocusWindow() + + # verify search string is still "third" from previous search + searchterm = xDialog.getChild("searchterm") + self.assertEqual(get_state_as_dict(searchterm)["Text"], "third") + + # replace it with "First" + searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) + searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"})) + searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"First"})) + + # click "match case" + matchcase = xDialog.getChild("matchcase") + matchcase.executeAction("CLICK", tuple()) #click match case + + # set the replace string to "Replace" + replaceterm = xDialog.getChild("replaceterm") + replaceterm.executeAction("TYPE", mkPropertyValues({"TEXT":"Replace"})) #replace textbox + + # hit replace button 2 times + replace = xDialog.getChild("replace") + replace.executeAction("CLICK", tuple()) + replace.executeAction("CLICK", tuple()) #click twice Replace button (one selects, second replaces) + + # close and reopen the dialog, because of bug 122788 + xcloseBtn = xDialog.getChild("close") + self.ui_test.close_dialog_through_button(xcloseBtn) + self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog") + xDialog = self.xUITest.getTopFocusWindow() + + # now replace first (uncheck match case) with word "aaa" - click once Replace All button, check "Replace aaa aaa" + matchcase = xDialog.getChild("matchcase") + matchcase.executeAction("CLICK", tuple()) # uncheck match case + + replaceterm = xDialog.getChild("replaceterm") + replaceterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) + replaceterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"})) + replaceterm.executeAction("TYPE", mkPropertyValues({"TEXT":"aaa"})) + replaceall = xDialog.getChild("replaceall") + replaceall.executeAction("CLICK", tuple()) # click on replace all button + xcloseBtn = xDialog.getChild("close") + self.ui_test.close_dialog_through_button(xcloseBtn) #close the dialog + + # go to second page + self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog") + xDialog = self.xUITest.getTopFocusWindow() + searchterm = xDialog.getChild("searchterm") + searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"second"})) #2nd slide + xsearch = xDialog.getChild("search") + xsearch.executeAction("CLICK", tuple()) + xcloseBtn = xDialog.getChild("close") + self.ui_test.close_dialog_through_button(xcloseBtn) + self.assertEqual(document.CurrentController.getCurrentPage().Number, 2) + #now check if text "Replace aaa aaa" is on first slide + self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog") + xDialog = self.xUITest.getTopFocusWindow() + searchterm = xDialog.getChild("searchterm") + backsearch = xDialog.getChild("backsearch") + searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) + searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"})) + searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"Replace aaa aaa"})) + backsearch.executeAction("CLICK", tuple()) + #verify + self.assertEqual(document.CurrentController.getCurrentPage().Number, 1) #1st slide + + xcloseBtn = xDialog.getChild("close") + self.ui_test.close_dialog_through_button(xcloseBtn) # vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/sd/qa/uitest/impress_tests/embedded.py b/sd/qa/uitest/impress_tests/embedded.py index 3cec962dd1b4..1e3c23014a4f 100644 --- a/sd/qa/uitest/impress_tests/embedded.py +++ b/sd/qa/uitest/impress_tests/embedded.py @@ -12,26 +12,24 @@ from libreoffice.calc.document import get_cell_by_position class EmbeddedDocument(UITestCase): def test_open_embedded_document(self): - self.ui_test.load_file(get_url_for_data_file("embedded.pptx")) + with self.ui_test.load_file(get_url_for_data_file("embedded.pptx")): - xImpressDoc = self.xUITest.getTopFocusWindow() - xEditWin = xImpressDoc.getChild("impress_win") + xImpressDoc = self.xUITest.getTopFocusWindow() + xEditWin = xImpressDoc.getChild("impress_win") - xEditWin.executeAction("SELECT", mkPropertyValues({"OBJECT":"Object 2"})) + xEditWin.executeAction("SELECT", mkPropertyValues({"OBJECT":"Object 2"})) - xEditWin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"})) + xEditWin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"})) - document = self.ui_test.get_component() - self.assertEqual("Name", get_cell_by_position(document, 0, 0, 0).getString()) - self.assertEqual("NWell", get_cell_by_position(document, 0, 0, 1).getString()) - self.assertEqual("PWell", get_cell_by_position(document, 0, 0, 2).getString()) - self.assertEqual("Active", get_cell_by_position(document, 0, 0, 3).getString()) - self.assertEqual("NoPoly", get_cell_by_position(document, 0, 0, 4).getString()) - self.assertEqual("Poly", get_cell_by_position(document, 0, 0, 5).getString()) - self.assertEqual("Sized", get_cell_by_position(document, 0, 0, 6).getString()) + document = self.ui_test.get_component() + self.assertEqual("Name", get_cell_by_position(document, 0, 0, 0).getString()) + self.assertEqual("NWell", get_cell_by_position(document, 0, 0, 1).getString()) + self.assertEqual("PWell", get_cell_by_position(document, 0, 0, 2).getString()) + self.assertEqual("Active", get_cell_by_position(document, 0, 0, 3).getString()) + self.assertEqual("NoPoly", get_cell_by_position(document, 0, 0, 4).getString()) + self.assertEqual("Poly", get_cell_by_position(document, 0, 0, 5).getString()) + self.assertEqual("Sized", get_cell_by_position(document, 0, 0, 6).getString()) - self.xUITest.executeCommand(".uno:CloseDoc") - - self.ui_test.close_doc() + self.xUITest.executeCommand(".uno:CloseDoc") # vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/sd/qa/uitest/impress_tests/tdf141297.py b/sd/qa/uitest/impress_tests/tdf141297.py index 76aab4d4594f..cf6991414715 100644 --- a/sd/qa/uitest/impress_tests/tdf141297.py +++ b/sd/qa/uitest/impress_tests/tdf141297.py @@ -81,18 +81,16 @@ class tdf141297(UITestCase): # Close the Writer document self.ui_test.close_doc() - self.ui_test.load_file(systemPathToFileUrl(xFilePath)) + with self.ui_test.load_file(systemPathToFileUrl(xFilePath)): - self.xUITest.executeCommand(".uno:ManageLinks") + self.xUITest.executeCommand(".uno:ManageLinks") - # Since the image is no longer linked, the link dialog is not open. - # Without the fix in place, this dialog would have been opened - xMainWin = self.xUITest.getTopFocusWindow() - self.assertTrue(sLinks not in xMainWin.getChildren()) - self.assertTrue(sFileName not in xMainWin.getChildren()) - self.assertTrue(sBreakLink not in xMainWin.getChildren()) - self.assertTrue("impress_win" in xMainWin.getChildren()) - - self.ui_test.close_doc() + # Since the image is no longer linked, the link dialog is not open. + # Without the fix in place, this dialog would have been opened + xMainWin = self.xUITest.getTopFocusWindow() + self.assertTrue(sLinks not in xMainWin.getChildren()) + self.assertTrue(sFileName not in xMainWin.getChildren()) + self.assertTrue(sBreakLink not in xMainWin.getChildren()) + self.assertTrue("impress_win" in xMainWin.getChildren()) # vim: set shiftwidth=4 softtabstop=4 expandtab: |