sw/qa/uitest/writer_tests/wordCount.py  |   15 ++++-----------
 sw/qa/uitest/writer_tests7/tdf132169.py |    6 +++---
 sw/source/uibase/inc/conttree.hxx       |    5 +++++
 sw/source/uibase/uitest/uiobject.cxx    |    1 +
 uitest/uitest/test.py                   |   18 ++++++++++++++++++
 uitest/writer_tests5/tdf114724.py       |   22 ++++++++++++----------
 6 files changed, 43 insertions(+), 24 deletions(-)

New commits:
commit 4534d8146f383f75df5f6f4ba2cfe547bcf66a4b
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Thu May 21 19:32:58 2020 +0200
Commit:     Xisco Faulí <xiscofa...@libreoffice.org>
CommitDate: Fri May 22 20:05:06 2020 +0200

    uitest: Add wait methods for slow elements
    
    some elements take some time to be updated, specially
    with slow machines or ASan+UBSan builds
    
    Use the same time based approach used for launching the dialogs
    
    also reintroduce 634ce6f2d87a30b8abd2e8c67668e3bb5d87406b
    
    Change-Id: Ia1cca74474ef65578bbc60a53a8a511402a082b6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94648
    Tested-by: Xisco Faulí <xiscofa...@libreoffice.org>
    Reviewed-by: Xisco Faulí <xiscofa...@libreoffice.org>

diff --git a/sw/qa/uitest/writer_tests/wordCount.py 
b/sw/qa/uitest/writer_tests/wordCount.py
index d7b7ca07bb4e..07a4c69342ba 100644
--- a/sw/qa/uitest/writer_tests/wordCount.py
+++ b/sw/qa/uitest/writer_tests/wordCount.py
@@ -10,7 +10,6 @@ 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
@@ -276,24 +275,18 @@ class writerWordCount(UITestCase):
         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)
-
+        #needs 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.ui_test.wait_until_property_is_updated(xselectwords, "Text", "1")
         self.assertEqual(get_state_as_dict(xselectwords)["Text"], "1")
         self.assertEqual(get_state_as_dict(xselectchars)["Text"], "4")
 
         #4. Click after "At nunc" then <Shift><Home>
         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)
-
+        #needs 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.ui_test.wait_until_property_is_updated(xselectwords, "Text", "2")
         self.assertEqual(get_state_as_dict(xselectwords)["Text"], "2")
         self.assertEqual(get_state_as_dict(xselectchars)["Text"], "7")
 
diff --git a/sw/qa/uitest/writer_tests7/tdf132169.py 
b/sw/qa/uitest/writer_tests7/tdf132169.py
index ce4865000cf0..e96cf7250a91 100644
--- a/sw/qa/uitest/writer_tests7/tdf132169.py
+++ b/sw/qa/uitest/writer_tests7/tdf132169.py
@@ -8,7 +8,6 @@ from uitest.framework import UITestCase
 from uitest.path import get_srcdir_url
 from uitest.uihelper.common import get_state_as_dict
 from libreoffice.uno.propertyvalue import mkPropertyValues
-import time
 
 def get_url_for_data_file(file_name):
     return get_srcdir_url() + "/sw/qa/uitest/writer_tests/data/" + file_name
@@ -39,14 +38,15 @@ class tdf132169(UITestCase):
         self.xUITest.executeCommand(".uno:JumpToNextFrame")
 
         #wait until the toolbar is available
-        time.sleep(1)
+        self.ui_test.wait_until_child_is_available(xWriterEdit, 'metricfield')
         xLineMetric = xWriterEdit.getChild('metricfield')
+        self.assertEqual(get_state_as_dict(xLineMetric)["Text"], "0.0 pt")
 
         props = {"VALUE": "5.0"}
         actionProps = mkPropertyValues(props)
         xLineMetric.executeAction("VALUE", actionProps)
 
-        self.assertEqual(get_state_as_dict(xLineMetric)['Text'], '5.0 pt')
+        self.assertEqual(get_state_as_dict(xLineMetric)["Text"], "5.0 pt")
 
         document = self.ui_test.get_component()
         drawPage = document.getDrawPages().getByIndex(0)
diff --git a/sw/source/uibase/inc/conttree.hxx 
b/sw/source/uibase/inc/conttree.hxx
index 28ea07a1c1de..59df0d51c3ea 100644
--- a/sw/source/uibase/inc/conttree.hxx
+++ b/sw/source/uibase/inc/conttree.hxx
@@ -247,6 +247,11 @@ public:
         m_xTreeView->grab_focus();
     }
 
+    OUString get_selected_text() const
+    {
+        return m_xTreeView->get_selected_text();
+    }
+
     int count_selected_rows() const
     {
         return m_xTreeView->count_selected_rows();
diff --git a/sw/source/uibase/uitest/uiobject.cxx 
b/sw/source/uibase/uitest/uiobject.cxx
index 6a55e42cf5ac..7f922dc9ce16 100644
--- a/sw/source/uibase/uitest/uiobject.cxx
+++ b/sw/source/uibase/uitest/uiobject.cxx
@@ -139,6 +139,7 @@ StringMap SwNavigationPIUIObject::get_state()
     StringMap aMap = WindowUIObject::get_state();
 
     aMap["selectioncount"] = 
OUString::number(mxSwNavigationPI->m_xContentTree->count_selected_rows());
+    aMap["selectedtext"] = 
mxSwNavigationPI->m_xContentTree->get_selected_text();
 
     return aMap;
 }
diff --git a/uitest/uitest/test.py b/uitest/uitest/test.py
index f0cc1747b02e..ab8f650d548d 100644
--- a/uitest/uitest/test.py
+++ b/uitest/uitest/test.py
@@ -48,6 +48,24 @@ class UITest(object):
             if component is not None:
                 return component
 
+    def wait_until_child_is_available(self, parent, childName):
+        time_ = 0
+        while time_ < MAX_WAIT:
+            if childName in parent.getChildren():
+                break
+            else:
+                time_ += DEFAULT_SLEEP
+                time.sleep(DEFAULT_SLEEP)
+
+    def wait_until_property_is_updated(self, element, propertyName, value):
+        time_ = 0
+        while time_ < MAX_WAIT:
+            if get_state_as_dict(element)[propertyName] == value:
+                break
+            else:
+                time_ += DEFAULT_SLEEP
+                time.sleep(DEFAULT_SLEEP)
+
     def load_file(self, url):
         desktop = self.get_desktop()
         with EventListener(self._xContext, "OnLoad") as event:
diff --git a/uitest/writer_tests5/tdf114724.py 
b/uitest/writer_tests5/tdf114724.py
index 46d19468d43c..09341149c242 100644
--- a/uitest/writer_tests5/tdf114724.py
+++ b/uitest/writer_tests5/tdf114724.py
@@ -6,7 +6,6 @@
 from uitest.framework import UITestCase
 from libreoffice.uno.propertyvalue import mkPropertyValues
 from uitest.uihelper.common import get_state_as_dict
-import time
 from uitest.path import get_srcdir_url
 
 def get_url_for_data_file(file_name):
@@ -25,21 +24,24 @@ class tdf114724(UITestCase):
         xNavigatorPanel = xWriterEdit.getChild("NavigatorPanelParent")
         xNavigatorPanel.executeAction("ROOT", tuple())
 
-        xContentTree = xNavigatorPanel.getChild('contenttree')
-        #Check the content has changed
-        self.assertEqual(len(xContentTree.getChildren()), 1)
-
         xWriterEdit.executeAction("FOCUS", tuple())
-        time.sleep(2)
+
+        self.ui_test.wait_until_property_is_updated(xNavigatorPanel, 
"selectedtext", "Headings")
+        self.assertEqual(get_state_as_dict(xNavigatorPanel)["selectedtext"], 
"Headings")
         self.assertEqual(get_state_as_dict(xNavigatorPanel)["selectioncount"], 
"1")
         for _ in range(0,3):
             xWriterEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE": 
"DOWN"}))
-            time.sleep(2)
-            
self.assertEqual(get_state_as_dict(xNavigatorPanel)["selectioncount"], "1")
+
+        self.ui_test.wait_until_property_is_updated(xNavigatorPanel, 
"selectedtext", "HEADING 4")
+        self.assertEqual(get_state_as_dict(xNavigatorPanel)["selectedtext"], 
"HEADING 4")
+        self.assertEqual(get_state_as_dict(xNavigatorPanel)["selectioncount"], 
"1")
+
         for _ in range(0,3):
             xWriterEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE": 
"UP"}))
-            time.sleep(2)
-            
self.assertEqual(get_state_as_dict(xNavigatorPanel)["selectioncount"], "1")
+
+        self.ui_test.wait_until_property_is_updated(xNavigatorPanel, 
"selectedtext", "HEADING 1")
+        self.assertEqual(get_state_as_dict(xNavigatorPanel)["selectedtext"], 
"HEADING 1")
+        self.assertEqual(get_state_as_dict(xNavigatorPanel)["selectioncount"], 
"1")
 
         self.xUITest.executeCommand(".uno:Sidebar")
         self.ui_test.close_doc()
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to