diff options
author | Ahmed ElShreif <aelshreif7@gmail.com> | 2020-06-19 23:29:49 +0200 |
---|---|---|
committer | Ahmed ElShreif <aelshreif7@gmail.com> | 2020-07-09 16:34:17 +0200 |
commit | a5b00f6e9790b17d47a8573b441ce886f5374014 (patch) | |
tree | d8c946cca0c70d6d153ccd8277976736e3e6ce9c | |
parent | c0a6d6f2bd5de731ebe0cd839f6a62cc5150b05b (diff) |
uitest : Fix the old demo of writer comments
This test case is added as the old test case here:
https://gerrit.libreoffice.org/c/core/+/96295
makes some randomly fail.
I tried to fix this in the new test case .
By trying to run the old test case multiple times locally .
The problem was when you execute Command to add new comment . Sometimes the comment doesn't have enough time to be created and added as a child in the MainWindow Object So test case fails .
So the fix was to use this function:
"ui_test.wait_until_child_is_available(parent, childName)"
This will make sure that that the comment was created successfully and added as a child in the MainWindow to be selected in next lines .
I tried to run the test case again multiple times in my laptop and it never fails .
Change-Id: I51e4b0802f3fa92139cbc6cdc7092c119e49d1b6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96752
Tested-by: Jenkins
Reviewed-by: Ahmed ElShreif <aelshreif7@gmail.com>
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
-rw-r--r-- | sw/qa/uitest/writer_tests/comments.py | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/sw/qa/uitest/writer_tests/comments.py b/sw/qa/uitest/writer_tests/comments.py new file mode 100644 index 000000000000..c85ed256de37 --- /dev/null +++ b/sw/qa/uitest/writer_tests/comments.py @@ -0,0 +1,160 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# This file is part of the LibreOffice project. +# +# 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 +from libreoffice.uno.propertyvalue import mkPropertyValues +from uitest.debug import sleep +from uitest.config import DEFAULT_SLEEP +#test comments + +class Comments(UITestCase): + + def test_comments_features(self): + + xMainDoc = self.ui_test.create_doc_in_start_center("writer") + + xMainWindow = self.xUITest.getTopFocusWindow() + + xwriter_edit = xMainWindow.getChild("writer_edit") + xwriter_edit.executeAction("TYPE", mkPropertyValues({"TEXT": "Before "})) + + # adding new Comment + self.xUITest.executeCommand(".uno:InsertAnnotation") + + # wait until the comment is available + self.ui_test.wait_until_child_is_available(xMainWindow, 'Comment1') + + xComment1 = xMainWindow.getChild("Comment1") + xComment1.executeAction("TYPE", mkPropertyValues({"TEXT": "This is the First Comment"})) + self.assertEqual(get_state_as_dict(xComment1)["Text"], "This is the First Comment" ) + self.assertEqual(get_state_as_dict(xComment1)["Resolved"], "false" ) + self.assertEqual(get_state_as_dict(xComment1)["Author"], "Unknown Author" ) + self.assertEqual(get_state_as_dict(xComment1)["ReadOnly"], "false" ) + + xComment1.executeAction("LEAVE", mkPropertyValues({})) + + xwriter_edit.executeAction("TYPE", mkPropertyValues({"TEXT": "After"})) + xwriter_edit.executeAction("SELECT", mkPropertyValues({"END_POS": "0", "START_POS": "13"})) + self.assertEqual(get_state_as_dict(xwriter_edit)["SelectedText"], "Before After" ) + + # test Resolve Comment + xComment1.executeAction("RESOLVE", mkPropertyValues({})) + self.assertEqual(get_state_as_dict(xComment1)["Resolved"], "true" ) + + # test Select text from Comment + xComment1.executeAction("SELECT", mkPropertyValues({"FROM": "0", "TO": "4"})) + self.assertEqual(get_state_as_dict(xComment1)["SelectedText"], "This" ) + + # test Hide then Show Comment + xComment1.executeAction("HIDE", mkPropertyValues({})) + self.assertEqual(get_state_as_dict(xComment1)["Visible"], "false" ) + xComment1.executeAction("SHOW", mkPropertyValues({})) + self.assertEqual(get_state_as_dict(xComment1)["Visible"], "true" ) + + # test delete Comment + xComment1.executeAction("DELETE", mkPropertyValues({})) + self.assertTrue("Comment1" not in xMainWindow.getChildren()) + + self.ui_test.close_doc() + + def test_multi_comments(self): + + xMainDoc = self.ui_test.create_doc_in_start_center("writer") + + xMainWindow = self.xUITest.getTopFocusWindow() + + xwriter_edit = xMainWindow.getChild("writer_edit") + + # adding 3 new Comment + xwriter_edit.executeAction("TYPE", mkPropertyValues({"TEXT": "Line 1"})) + self.xUITest.executeCommand(".uno:InsertAnnotation") + # wait until the comment is available + self.ui_test.wait_until_child_is_available(xMainWindow, 'Comment1') + xComment1 = xMainWindow.getChild("Comment1") + xComment1.executeAction("TYPE", mkPropertyValues({"TEXT": "First Comment"})) + xComment1.executeAction("LEAVE", mkPropertyValues({})) + xwriter_edit.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"})) + + xwriter_edit.executeAction("TYPE", mkPropertyValues({"TEXT": "Line 2"})) + self.xUITest.executeCommand(".uno:InsertAnnotation") + # wait until the comment is available + self.ui_test.wait_until_child_is_available(xMainWindow, 'Comment2') + xComment2 = xMainWindow.getChild("Comment2") + xComment2.executeAction("TYPE", mkPropertyValues({"TEXT": "Second Comment"})) + xComment2.executeAction("LEAVE", mkPropertyValues({})) + xwriter_edit.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"})) + + xwriter_edit.executeAction("TYPE", mkPropertyValues({"TEXT": "Line 3"})) + self.xUITest.executeCommand(".uno:InsertAnnotation") + # wait until the comment is available + self.ui_test.wait_until_child_is_available(xMainWindow, 'Comment3') + xComment3 = xMainWindow.getChild("Comment3") + xComment3.executeAction("TYPE", mkPropertyValues({"TEXT": "Third Comment"})) + xComment3.executeAction("LEAVE", mkPropertyValues({})) + xwriter_edit.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"})) + + # Check text + self.assertEqual(get_state_as_dict(xComment1)["Text"], "First Comment" ) + self.assertEqual(get_state_as_dict(xComment2)["Text"], "Second Comment" ) + self.assertEqual(get_state_as_dict(xComment3)["Text"], "Third Comment" ) + + xComment2.executeAction("RESOLVE", mkPropertyValues({})) + xComment3.executeAction("RESOLVE", mkPropertyValues({})) + + # Check Resolved + self.assertEqual(get_state_as_dict(xComment1)["Resolved"], "false" ) + self.assertEqual(get_state_as_dict(xComment2)["Resolved"], "true" ) + self.assertEqual(get_state_as_dict(xComment3)["Resolved"], "true" ) + + # Check ReadOnly + self.assertEqual(get_state_as_dict(xComment1)["ReadOnly"], "false" ) + self.assertEqual(get_state_as_dict(xComment2)["ReadOnly"], "false" ) + self.assertEqual(get_state_as_dict(xComment3)["ReadOnly"], "false" ) + + # Check Select + xComment1.executeAction("SELECT", mkPropertyValues({"FROM": "0", "TO": "5"})) + self.assertEqual(get_state_as_dict(xComment1)["SelectedText"], "First" ) + + xComment2.executeAction("SELECT", mkPropertyValues({"FROM": "0", "TO": "6"})) + self.assertEqual(get_state_as_dict(xComment2)["SelectedText"], "Second" ) + + xComment3.executeAction("SELECT", mkPropertyValues({"FROM": "0", "TO": "5"})) + self.assertEqual(get_state_as_dict(xComment3)["SelectedText"], "Third" ) + + # Check that they all are Visible + self.assertEqual(get_state_as_dict(xComment1)["Visible"], "true" ) + self.assertEqual(get_state_as_dict(xComment2)["Visible"], "true" ) + self.assertEqual(get_state_as_dict(xComment3)["Visible"], "true" ) + + # Hide all + xComment1.executeAction("HIDE", mkPropertyValues({})) + self.assertEqual(get_state_as_dict(xComment1)["Visible"], "false" ) + xComment2.executeAction("HIDE", mkPropertyValues({})) + self.assertEqual(get_state_as_dict(xComment2)["Visible"], "false" ) + xComment3.executeAction("HIDE", mkPropertyValues({})) + self.assertEqual(get_state_as_dict(xComment3)["Visible"], "false" ) + + # Show comment 2 only + xComment2.executeAction("SHOW", mkPropertyValues({})) + self.assertEqual(get_state_as_dict(xComment2)["Visible"], "true" ) + + # Then remove the 3 comments + xComment1.executeAction("DELETE", mkPropertyValues({})) + xComment2.executeAction("DELETE", mkPropertyValues({})) + xComment3.executeAction("DELETE", mkPropertyValues({})) + self.assertTrue("Comment1" not in xMainWindow.getChildren()) + self.assertTrue("Comment2" not in xMainWindow.getChildren()) + self.assertTrue("Comment3" not in xMainWindow.getChildren()) + + self.ui_test.close_doc() + +# vim: set shiftwidth=4 softtabstop=4 expandtab: + |