summaryrefslogtreecommitdiff
path: root/uitest
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2016-06-22 05:27:22 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2016-06-22 18:19:33 +0200
commit4fa28812f3574efaca42769e9e4ff28f7d545bd8 (patch)
treeef0376117ac6f402595b84598b341f8c0c41e4b8 /uitest
parent660e5597813f88b1aca564198fdf5f78298adc13 (diff)
uitest: start the switch to python's unittest
Change-Id: Ic6e0d99a567b7080928accb61ed036b1c25ec7ff
Diffstat (limited to 'uitest')
-rw-r--r--uitest/UITestCase.py32
-rw-r--r--uitest/calc_tests/about_test.py22
-rw-r--r--uitest/calc_tests/calc_demo.txt1
-rw-r--r--uitest/calc_tests/create_chart.py228
-rw-r--r--uitest/test_main.py101
5 files changed, 244 insertions, 140 deletions
diff --git a/uitest/UITestCase.py b/uitest/UITestCase.py
new file mode 100644
index 000000000000..5628d9de3f67
--- /dev/null
+++ b/uitest/UITestCase.py
@@ -0,0 +1,32 @@
+# -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-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 unittest
+
+from uitest_helper import UITest
+
+from connection import PersistentConnection, OfficeConnection
+
+class UITestCase(unittest.TestCase):
+
+ def __init__(self, test_name, opts):
+ unittest.TestCase.__init__(self, test_name)
+ self.opts = opts
+
+ def setUp(self):
+ self.connection = PersistentConnection(self.opts)
+ self.connection.setUp()
+ self.xContext = self.connection.getContext()
+ self.xUITest = self.xContext.ServiceManager.createInstanceWithContext(
+ "org.libreoffice.uitest.UITest", self.xContext)
+
+ self.ui_test = UITest(self.xUITest, self.xContext)
+
+ def tearDown(self):
+ self.connection.tearDown()
+
+# vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/uitest/calc_tests/about_test.py b/uitest/calc_tests/about_test.py
index b5120841e1e8..df90e7da79bc 100644
--- a/uitest/calc_tests/about_test.py
+++ b/uitest/calc_tests/about_test.py
@@ -5,25 +5,23 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
-import time
-
from uitest_helper import UITest
-def test_about_dlg(xContext):
- xUITest = xContext.ServiceManager.createInstanceWithContext(
- "org.libreoffice.uitest.UITest", xContext)
+from UITestCase import UITestCase
+
+class AboutDlgTest(UITestCase):
- ui_test = UITest(xUITest, xContext)
+ def test_about_dlg(self):
- ui_test.create_doc_in_start_center("calc")
+ self.ui_test.create_doc_in_start_center("calc")
- ui_test.execute_dialog_through_command(".uno:About")
+ self.ui_test.execute_dialog_through_command(".uno:About")
- xAboutDlg = xUITest.getTopFocusWindow()
+ xAboutDlg = self.xUITest.getTopFocusWindow()
- xCloseBtn = xAboutDlg.getChild("close")
- xCloseBtn.executeAction("CLICK", tuple())
+ xCloseBtn = xAboutDlg.getChild("close")
+ xCloseBtn.executeAction("CLICK", tuple())
- ui_test.close_doc()
+ self.ui_test.close_doc()
# vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/uitest/calc_tests/calc_demo.txt b/uitest/calc_tests/calc_demo.txt
index 6ff4e2219175..1c2629e91f73 100644
--- a/uitest/calc_tests/calc_demo.txt
+++ b/uitest/calc_tests/calc_demo.txt
@@ -2,4 +2,3 @@ calc_tests.create_range_name.create_range_name
calc_tests.create_range_name.create_local_range_name
calc_tests.function_wizard.open_function_wizard
calc_tests.gridwindow.input
-calc_tests.about_test.test_about_dlg
diff --git a/uitest/calc_tests/create_chart.py b/uitest/calc_tests/create_chart.py
index 6ec7082e7c77..6db4d58d474c 100644
--- a/uitest/calc_tests/create_chart.py
+++ b/uitest/calc_tests/create_chart.py
@@ -9,6 +9,8 @@ from uitest_helper import UITest
from helper import mkPropertyValues
+from UITestCase import UITestCase
+
import time
try:
@@ -21,199 +23,171 @@ except ImportError:
print("URE_BOOTSTRAP=file:///installation/opt/program/fundamentalrc")
raise
-def add_content_to_cell(gridwin, cell, content):
- selectProps = mkPropertyValues({"CELL": cell})
- gridwin.executeAction("SELECT", selectProps)
-
- contentProps = mkPropertyValues({"TEXT": content})
- gridwin.executeAction("TYPE", contentProps)
-
-
-def fill_spreadsheet(xUITest):
- xCalcDoc = xUITest.getTopFocusWindow()
- xGridWindow = xCalcDoc.getChild("grid_window")
-
- add_content_to_cell(xGridWindow, "A1", "col1")
- add_content_to_cell(xGridWindow, "B1", "col2")
- add_content_to_cell(xGridWindow, "C1", "col3")
- add_content_to_cell(xGridWindow, "A2", "1")
- add_content_to_cell(xGridWindow, "B2", "3")
- add_content_to_cell(xGridWindow, "C2", "5")
-
- xGridWindow.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:C2"}))
-
-def cancel_immediately(xContext):
- xUITest = xContext.ServiceManager.createInstanceWithContext(
- "org.libreoffice.uitest.UITest", xContext)
-
- ui_test = UITest(xUITest, xContext)
-
- ui_test.create_doc_in_start_center("calc")
+class CalcChartUIDemo(UITestCase):
- fill_spreadsheet(xUITest)
+ def add_content_to_cell(self, gridwin, cell, content):
+ selectProps = mkPropertyValues({"CELL": cell})
+ gridwin.executeAction("SELECT", selectProps)
- ui_test.execute_dialog_through_command(".uno:InsertObjectChart")
+ contentProps = mkPropertyValues({"TEXT": content})
+ gridwin.executeAction("TYPE", contentProps)
- xChartDlg = xUITest.getTopFocusWindow()
+ def fill_spreadsheet(self):
+ xCalcDoc = self.xUITest.getTopFocusWindow()
+ xGridWindow = xCalcDoc.getChild("grid_window")
- xCancelBtn = xChartDlg.getChild("cancel")
- xCancelBtn.executeAction("CLICK", tuple())
+ self.add_content_to_cell(xGridWindow, "A1", "col1")
+ self.add_content_to_cell(xGridWindow, "B1", "col2")
+ self.add_content_to_cell(xGridWindow, "C1", "col3")
+ self.add_content_to_cell(xGridWindow, "A2", "1")
+ self.add_content_to_cell(xGridWindow, "B2", "3")
+ self.add_content_to_cell(xGridWindow, "C2", "5")
- ui_test.close_doc()
+ xGridWindow.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:C2"}))
-def create_from_first_page(xContext):
- xUITest = xContext.ServiceManager.createInstanceWithContext(
- "org.libreoffice.uitest.UITest", xContext)
+ def test_cancel_immediately(self):
- ui_test = UITest(xUITest, xContext)
+ self.ui_test.create_doc_in_start_center("calc")
- ui_test.create_doc_in_start_center("calc")
+ self.fill_spreadsheet()
- fill_spreadsheet(xUITest)
+ self.ui_test.execute_dialog_through_command(".uno:InsertObjectChart")
- ui_test.execute_dialog_through_command(".uno:InsertObjectChart")
+ xChartDlg = self.xUITest.getTopFocusWindow()
- xChartDlg = xUITest.getTopFocusWindow()
- print(xChartDlg.getChildren())
- time.sleep(2)
+ xCancelBtn = xChartDlg.getChild("cancel")
+ xCancelBtn.executeAction("CLICK", tuple())
- xOkBtn = xChartDlg.getChild("finish")
- xOkBtn.executeAction("CLICK", tuple())
+ self.ui_test.close_doc()
- time.sleep(2)
+ def test_create_from_first_page(self):
- ui_test.close_doc()
+ self.ui_test.create_doc_in_start_center("calc")
-def create_from_second_page(xContext):
- xUITest = xContext.ServiceManager.createInstanceWithContext(
- "org.libreoffice.uitest.UITest", xContext)
+ self.fill_spreadsheet()
- ui_test = UITest(xUITest, xContext)
+ self.ui_test.execute_dialog_through_command(".uno:InsertObjectChart")
- ui_test.create_doc_in_start_center("calc")
+ xChartDlg = self.xUITest.getTopFocusWindow()
+ print(xChartDlg.getChildren())
+ time.sleep(2)
- fill_spreadsheet(xUITest)
+ xOkBtn = xChartDlg.getChild("finish")
+ xOkBtn.executeAction("CLICK", tuple())
- ui_test.execute_dialog_through_command(".uno:InsertObjectChart")
+ time.sleep(2)
- xChartDlg = xUITest.getTopFocusWindow()
- print(xChartDlg.getChildren())
- time.sleep(2)
+ self.ui_test.close_doc()
- xNextBtn = xChartDlg.getChild("next")
- xNextBtn.executeAction("CLICK", tuple())
+ def test_create_from_second_page(self):
- print(xChartDlg.getChildren())
+ self.ui_test.create_doc_in_start_center("calc")
- time.sleep(2)
+ self.fill_spreadsheet()
- xDataInRows = xChartDlg.getChild("RB_DATAROWS")
- xDataInRows.executeAction("CLICK", tuple())
+ self.ui_test.execute_dialog_through_command(".uno:InsertObjectChart")
- time.sleep(2)
+ xChartDlg = self.xUITest.getTopFocusWindow()
+ print(xChartDlg.getChildren())
+ time.sleep(2)
- xDataInCols = xChartDlg.getChild("RB_DATACOLS")
- xDataInCols.executeAction("CLICK", tuple())
+ xNextBtn = xChartDlg.getChild("next")
+ xNextBtn.executeAction("CLICK", tuple())
- time.sleep(2)
+ print(xChartDlg.getChildren())
- xCancelBtn = xChartDlg.getChild("finish")
- xCancelBtn.executeAction("CLICK", tuple())
+ time.sleep(2)
- time.sleep(5)
+ xDataInRows = xChartDlg.getChild("RB_DATAROWS")
+ xDataInRows.executeAction("CLICK", tuple())
- ui_test.close_doc()
+ time.sleep(2)
-def deselect_chart(xContext):
- xUITest = xContext.ServiceManager.createInstanceWithContext(
- "org.libreoffice.uitest.UITest", xContext)
+ xDataInCols = xChartDlg.getChild("RB_DATACOLS")
+ xDataInCols.executeAction("CLICK", tuple())
- ui_test = UITest(xUITest, xContext)
+ time.sleep(2)
- ui_test.create_doc_in_start_center("calc")
+ xCancelBtn = xChartDlg.getChild("finish")
+ xCancelBtn.executeAction("CLICK", tuple())
- fill_spreadsheet(xUITest)
+ time.sleep(5)
- xCalcDoc = xUITest.getTopFocusWindow()
- xGridWindow = xCalcDoc.getChild("grid_window")
+ self.ui_test.close_doc()
- ui_test.execute_dialog_through_command(".uno:InsertObjectChart")
+ def test_deselect_chart(self):
+ self.ui_test.create_doc_in_start_center("calc")
- xChartDlg = xUITest.getTopFocusWindow()
+ self.fill_spreadsheet()
- xNextBtn = xChartDlg.getChild("finish")
- xNextBtn.executeAction("CLICK", tuple())
+ xCalcDoc = self.xUITest.getTopFocusWindow()
+ xGridWindow = xCalcDoc.getChild("grid_window")
- xGridWindow.executeAction("DESELECT", mkPropertyValues({"OBJECT": ""}))
+ self.ui_test.execute_dialog_through_command(".uno:InsertObjectChart")
- time.sleep(2)
+ xChartDlg = self.xUITest.getTopFocusWindow()
- ui_test.close_doc()
+ xNextBtn = xChartDlg.getChild("finish")
+ xNextBtn.executeAction("CLICK", tuple())
-def activate_chart(xContext):
- xUITest = xContext.ServiceManager.createInstanceWithContext(
- "org.libreoffice.uitest.UITest", xContext)
+ xGridWindow.executeAction("DESELECT", mkPropertyValues({"OBJECT": ""}))
- ui_test = UITest(xUITest, xContext)
+ time.sleep(2)
- ui_test.create_doc_in_start_center("calc")
+ self.ui_test.close_doc()
- fill_spreadsheet(xUITest)
+ def test_activate_chart(self):
- xCalcDoc = xUITest.getTopFocusWindow()
- xGridWindow = xCalcDoc.getChild("grid_window")
+ self.ui_test.create_doc_in_start_center("calc")
- ui_test.execute_dialog_through_command(".uno:InsertObjectChart")
+ self.fill_spreadsheet()
- xChartDlg = xUITest.getTopFocusWindow()
+ xCalcDoc = self.xUITest.getTopFocusWindow()
+ xGridWindow = xCalcDoc.getChild("grid_window")
- xNextBtn = xChartDlg.getChild("finish")
- xNextBtn.executeAction("CLICK", tuple())
+ self.ui_test.execute_dialog_through_command(".uno:InsertObjectChart")
- xGridWindow.executeAction("DESELECT", mkPropertyValues({"OBJECT": ""}))
+ xChartDlg = self.xUITest.getTopFocusWindow()
- time.sleep(2)
+ xNextBtn = xChartDlg.getChild("finish")
+ xNextBtn.executeAction("CLICK", tuple())
- xGridWindow.executeAction("SELECT", mkPropertyValues({"OBJECT": "Object 1"}))
- xGridWindow.executeAction("ACTIVATE", tuple())
+ xGridWindow.executeAction("DESELECT", mkPropertyValues({"OBJECT": ""}))
- time.sleep(2)
+ time.sleep(2)
- xGridWindow.executeAction("DESELECT", mkPropertyValues({"OBJECT": ""}))
+ xGridWindow.executeAction("SELECT", mkPropertyValues({"OBJECT": "Object 1"}))
+ xGridWindow.executeAction("ACTIVATE", tuple())
- ui_test.close_doc()
+ time.sleep(2)
-def select_chart_element(xContext):
- xUITest = xContext.ServiceManager.createInstanceWithContext(
- "org.libreoffice.uitest.UITest", xContext)
+ xGridWindow.executeAction("DESELECT", mkPropertyValues({"OBJECT": ""}))
- ui_test = UITest(xUITest, xContext)
+ self.ui_test.close_doc()
- ui_test.create_doc_in_start_center("calc")
+ def select_chart_element(self):
- fill_spreadsheet(xUITest)
+ self.ui_test.create_doc_in_start_center("calc")
- xCalcDoc = xUITest.getTopFocusWindow()
- xGridWindow = xCalcDoc.getChild("grid_window")
+ self.fill_spreadsheet()
- ui_test.execute_dialog_through_command(".uno:InsertObjectChart")
+ xCalcDoc = self.xUITest.getTopFocusWindow()
+ xGridWindow = xCalcDoc.getChild("grid_window")
- xChartDlg = xUITest.getTopFocusWindow()
+ self.ui_test.execute_dialog_through_command(".uno:InsertObjectChart")
- xNextBtn = xChartDlg.getChild("finish")
- xNextBtn.executeAction("CLICK", tuple())
+ xChartDlg = self.xUITest.getTopFocusWindow()
- xGridWindow.executeAction("DESELECT", mkPropertyValues({"OBJECT": ""}))
+ xNextBtn = xChartDlg.getChild("finish")
+ xNextBtn.executeAction("CLICK", tuple())
- time.sleep(2)
+ xGridWindow.executeAction("DESELECT", mkPropertyValues({"OBJECT": ""}))
- xGridWindow.executeAction("SELECT", mkPropertyValues({"OBJECT": "Object 1"}))
- xGridWindow.executeAction("ACTIVATE", tuple())
+ xGridWindow.executeAction("SELECT", mkPropertyValues({"OBJECT": "Object 1"}))
+ xGridWindow.executeAction("ACTIVATE", tuple())
- time.sleep(2)
- xCalcDoc = xUITest.getTopFocusWindow()
- print(xCalcDoc.getChildren())
- time.sleep(1)
- ui_test.close_doc()
+ xCalcDoc = self.xUITest.getTopFocusWindow()
+ print(xCalcDoc.getChildren())
+ self.ui_test.close_doc()
# vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/uitest/test_main.py b/uitest/test_main.py
new file mode 100644
index 000000000000..2a0fca1546d3
--- /dev/null
+++ b/uitest/test_main.py
@@ -0,0 +1,101 @@
+# -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-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 sys
+import getopt
+import os
+import unittest
+import calc_tests
+import importlib
+import importlib.machinery
+
+from UITestCase import UITestCase
+
+from connection import PersistentConnection, OfficeConnection
+
+def parseArgs(argv):
+ (optlist,args) = getopt.getopt(argv[1:], "hr",
+ ["help", "soffice=", "userdir=", "dir="])
+ return (dict(optlist), args)
+
+def usage():
+ message = """usage: {program} [option]... [task_file]..."
+ -h | --help: print usage information
+ {connection_params}
+ the 'task_file' parameters should be
+ full absolute pathnames, not URLs."""
+ print(message.format(program = os.path.basename(sys.argv[0]), \
+ connection_params = OfficeConnection.getHelpText()))
+
+
+def find_test_files(dir_path):
+ valid_files = []
+ for f in os.listdir(dir_path):
+ file_path = os.path.join(dir_path, f)
+
+ # don't go through the sub-directories
+ if not os.path.isfile(file_path):
+ continue
+
+ # ignore any non .py files
+ if not os.path.splitext(file_path)[1] == ".py":
+ continue
+
+ # ignore the __init__.py file
+ # it is obviously not a test file
+ if f is "__init__.py":
+ continue
+
+ valid_files.append(file_path)
+
+ return valid_files
+
+def get_classes_of_module(module):
+ md = module.__dict__
+ return [ md[c] for c in md if (
+ isinstance(md[c], type) and md[c].__module__ == module.__name__ ) ]
+
+def get_test_case_classes_of_module(module):
+ classes = get_classes_of_module(module)
+ return [ c for c in classes if issubclass(c, UITestCase) ]
+
+def get_test_suite(opts):
+ test_loader = unittest.TestLoader()
+ test_suite = unittest.TestSuite()
+
+ valid_test_files = find_test_files(opts['--dir'])
+ for test_file in valid_test_files:
+ module_name = os.path.splitext(os.path.split(test_file)[1])[0]
+ loader = importlib.machinery.SourceFileLoader(module_name, test_file)
+ mod = loader.load_module()
+ classes = get_test_case_classes_of_module(mod)
+ for c in classes:
+ test_names = test_loader.getTestCaseNames(c)
+ for test_name in test_names:
+ obj = c(test_name, opts)
+ test_suite.addTest(obj)
+
+ return test_suite
+
+
+if __name__ == '__main__':
+ (opts,args) = parseArgs(sys.argv)
+ if "-h" in opts or "--help" in opts:
+ usage()
+ sys.exit()
+ elif not "--soffice" in opts:
+ usage()
+ sys.exit(1)
+ elif not "--dir" in opts:
+ usage()
+ sys.exit()
+ test_suite = get_test_suite(opts)
+ print(test_suite)
+
+ unittest.TextTestRunner().run(test_suite)
+
+# vim:set shiftwidth=4 softtabstop=4 expandtab: */