From 57839969381d93e96e98fdaee65e8593c8f07893 Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Mon, 20 Apr 2020 18:05:28 +0200 Subject: uitest: re-enable test using sleep MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit and instead of sleep(3) use timeout = time.time() + 3 while condition != True and time.time() < timeout: sleep(0.1) execution time of this particular test goes from 7.785 seconds to 3.343 for me Change-Id: I7c99385ccd858dfbb77cfc6e53a0b3f1a8b57c73 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92588 Tested-by: Jenkins Reviewed-by: Xisco FaulĂ­ --- sw/qa/uitest/writer_tests/wordCount.py | 98 +++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 43 deletions(-) diff --git a/sw/qa/uitest/writer_tests/wordCount.py b/sw/qa/uitest/writer_tests/wordCount.py index 96ff3ea47349..d7b7ca07bb4e 100644 --- a/sw/qa/uitest/writer_tests/wordCount.py +++ b/sw/qa/uitest/writer_tests/wordCount.py @@ -10,6 +10,7 @@ from libreoffice.uno.propertyvalue import mkPropertyValues from uitest.debug import sleep from uitest.uihelper.common import get_state_as_dict, type_text from uitest.path import get_srcdir_url +import time def get_url_for_data_file(file_name): return get_srcdir_url() + "/sw/qa/uitest/writer_tests/data/" + file_name @@ -247,47 +248,58 @@ class writerWordCount(UITestCase): self.ui_test.close_dialog_through_button(xCloseBtn) self.ui_test.close_doc() - #need sleep() in test. Disable for now -# def test_tdf51816(self): -# writer_doc = self.ui_test.load_file(get_url_for_data_file("tdf51816.odt")) -# xWriterDoc = self.xUITest.getTopFocusWindow() -# xWriterEdit = xWriterDoc.getChild("writer_edit") -# document = self.ui_test.get_component() -# #1. Open attached document -# #2. Tools> Word count -# self.ui_test.execute_modeless_dialog_through_command(".uno:WordCountDialog") -# xDialog = self.xUITest.getTopFocusWindow() -# xselectwords = xDialog.getChild("selectwords") -# xdocwords = xDialog.getChild("docwords") -# xselectchars = xDialog.getChild("selectchars") -# xdocchars = xDialog.getChild("docchars") -# xselectcharsnospaces = xDialog.getChild("selectcharsnospaces") -# xdoccharsnospaces = xDialog.getChild("doccharsnospaces") -# xselectcjkchars = xDialog.getChild("selectcjkchars") -# xdoccjkchars = xDialog.getChild("doccjkchars") - -# #3. Click after "At nunc" then -# self.xUITest.executeCommand(".uno:GoRight") -# self.xUITest.executeCommand(".uno:GoRight") -# self.xUITest.executeCommand(".uno:GoRight") -# self.xUITest.executeCommand(".uno:GoRight") -# self.xUITest.executeCommand(".uno:GoRight") -# self.xUITest.executeCommand(".uno:GoRight") -# self.xUITest.executeCommand(".uno:GoRight") -# self.xUITest.executeCommand(".uno:WordLeftSel") -# sleep(3) #need to wait, because Word count dialog is already open and it takes time to refresh the counter -# #Expected result : Words 1 & Characters 4 #Actual result : Words 0 & Characters 0 -# self.assertEqual(get_state_as_dict(xselectwords)["Text"], "1") -# self.assertEqual(get_state_as_dict(xselectchars)["Text"], "4") -# #4. Click after "At nunc" then -# self.xUITest.executeCommand(".uno:StartOfParaSel") -# sleep(3) #need to wait, because Word count dialog is already open and it takes time to refresh the counter -# #Expected result : Words 2 & Characters 7 & excluding space 6 #Actual result : Words 0 & Characters 0 -# self.assertEqual(get_state_as_dict(xselectwords)["Text"], "2") -# self.assertEqual(get_state_as_dict(xselectchars)["Text"], "7") -# self.assertEqual(get_state_as_dict(xselectcharsnospaces)["Text"], "6") - -# xCloseBtn = xDialog.getChild("close") -# self.ui_test.close_dialog_through_button(xCloseBtn) -# self.ui_test.close_doc() + def test_tdf51816(self): + writer_doc = self.ui_test.load_file(get_url_for_data_file("tdf51816.odt")) + xWriterDoc = self.xUITest.getTopFocusWindow() + xWriterEdit = xWriterDoc.getChild("writer_edit") + document = self.ui_test.get_component() + #1. Open attached document + #2. Tools> Word count + self.ui_test.execute_modeless_dialog_through_command(".uno:WordCountDialog") + xDialog = self.xUITest.getTopFocusWindow() + xselectwords = xDialog.getChild("selectwords") + xdocwords = xDialog.getChild("docwords") + xselectchars = xDialog.getChild("selectchars") + xdocchars = xDialog.getChild("docchars") + xselectcharsnospaces = xDialog.getChild("selectcharsnospaces") + xdoccharsnospaces = xDialog.getChild("doccharsnospaces") + xselectcjkchars = xDialog.getChild("selectcjkchars") + xdoccjkchars = xDialog.getChild("doccjkchars") + + #3. Click after "At nunc" then + self.xUITest.executeCommand(".uno:GoRight") + self.xUITest.executeCommand(".uno:GoRight") + self.xUITest.executeCommand(".uno:GoRight") + self.xUITest.executeCommand(".uno:GoRight") + self.xUITest.executeCommand(".uno:GoRight") + self.xUITest.executeCommand(".uno:GoRight") + self.xUITest.executeCommand(".uno:GoRight") + self.xUITest.executeCommand(".uno:WordLeftSel") + + #need to wait, because Word count dialog is already open and it takes time to refresh the counter + timeout = time.time() + 3 + while get_state_as_dict(xselectwords)["Text"] != "1" and time.time() < timeout: + sleep(0.1) + + #Expected result : Words 1 & Characters 4 #Actual result : Words 0 & Characters 0 + self.assertEqual(get_state_as_dict(xselectwords)["Text"], "1") + self.assertEqual(get_state_as_dict(xselectchars)["Text"], "4") + + #4. Click after "At nunc" then + self.xUITest.executeCommand(".uno:StartOfParaSel") + + #need to wait, because Word count dialog is already open and it takes time to refresh the counter + timeout = time.time() + 3 + while get_state_as_dict(xselectwords)["Text"] != "2" and time.time() < timeout: + sleep(0.1) + + #Expected result : Words 2 & Characters 7 & excluding space 6 #Actual result : Words 0 & Characters 0 + self.assertEqual(get_state_as_dict(xselectwords)["Text"], "2") + self.assertEqual(get_state_as_dict(xselectchars)["Text"], "7") + + self.assertEqual(get_state_as_dict(xselectcharsnospaces)["Text"], "6") + + xCloseBtn = xDialog.getChild("close") + self.ui_test.close_dialog_through_button(xCloseBtn) + self.ui_test.close_doc() # vim: set shiftwidth=4 softtabstop=4 expandtab: -- cgit