[Libreoffice-commits] core.git: uitest/loginterpreter.py
uitest/loginterpreter.py |3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) New commits: commit a98058199410bdb183acd0ec5e7899ea4baf6c5a Author: Markus Mohrhard AuthorDate: Fri Sep 28 15:17:56 2018 +0200 Commit: Markus Mohrhard CommitDate: Fri Sep 28 15:32:44 2018 +0200 make the loginterpreter executable Change-Id: I9dcb562f9309c75a2d1719f1ad4fe6b5a4c23385 diff --git a/uitest/loginterpreter.py b/uitest/loginterpreter.py old mode 100644 new mode 100755 index 770beb966064..e84d9a0ed7e1 --- a/uitest/loginterpreter.py +++ b/uitest/loginterpreter.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- # # This file is part of the LibreOffice project. @@ -205,4 +206,4 @@ def main(): if __name__ == '__main__': main() -# vim: set shiftwidth=4 softtabstop=4 expandtab: \ No newline at end of file +# vim: set shiftwidth=4 softtabstop=4 expandtab: ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] core.git: uitest/loginterpreter.py
uitest/loginterpreter.py | 23 ++- 1 file changed, 18 insertions(+), 5 deletions(-) New commits: commit db68a9c002314e17c2b1d1748269af4d1851ef48 Author: Saurav Chirania AuthorDate: Mon Jul 30 21:13:34 2018 +0530 Commit: Saurav Chirania CommitDate: Mon Aug 27 09:33:03 2018 +0200 uitest interpreter: some improvements Change-Id: I7b768694ba5a82f7273fd7641fae5c3fc84233a6 Reviewed-on: https://gerrit.libreoffice.org/58340 Reviewed-by: Markus Mohrhard Tested-by: Jenkins diff --git a/uitest/loginterpreter.py b/uitest/loginterpreter.py index becd8b322937..770beb966064 100644 --- a/uitest/loginterpreter.py +++ b/uitest/loginterpreter.py @@ -16,14 +16,15 @@ def parse_line(line): This function parses a line from log file and returns the parsed values as a python dictionary """ -if (line == "" or line.startswith("Action on element")): +if (line == ""): return dict = {} if "{" in line: start_index_of_parameters = line.find("{") end_index_of_parameters = line.find("}") + 1 parameters = line[start_index_of_parameters:end_index_of_parameters] -dict["parameters"] = parameters +if parameters != "": +dict["parameters"] = parameters line = line[:start_index_of_parameters-1] word_list = line.split() dict["keyword"] = word_list[0] @@ -54,7 +55,7 @@ def get_log_file(input_address): print("Use " + os.path.basename(sys.argv[0]) + " -h to get usage instructions") sys.exit(1) -content = [x.strip() for x in content] +content = [x.strip() for x in content if not x.startswith("Action on element")] return content def initiate_test_generation(address): @@ -65,6 +66,7 @@ def initiate_test_generation(address): print("Use " + os.path.basename(sys.argv[0]) + " -h to get usage instructions") sys.exit(1) initial_text = \ +"# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-\n\n" + \ "from uitest.framework import UITestCase\n" + \ "from libreoffice.uno.propertyvalue import mkPropertyValues\n" + \ "import importlib\n\n" + \ @@ -135,8 +137,18 @@ def get_test_line_from_one_log_line(log_line): test_line += ",tuple())\n" return test_line elif action_dict["keyword"] == "CommandSent": -test_line += "self.xUITest.executeCommand(\"" + \ -action_dict["Name"] + "\")\n" +if "parameters" not in action_dict: +test_line += "self.xUITest.executeCommand(\"" + \ +action_dict["Name"] + "\")\n" +return test_line +else: +test_line += "self.xUITest.executeCommandWithParameters(\"" + \ +action_dict["Name"] + "\", mkPropertyValues(" + action_dict["parameters"] + \ +"))\n" +return test_line +elif action_dict["keyword"] == "ModalDialogExecuted" or \ +action_dict["keyword"] == "ModelessDialogConstructed": +test_line += action_dict["Id"] + " = " + "self.xUITest.getTopFocusWindow()\n" return test_line return "" @@ -187,6 +199,7 @@ def main(): output_stream.write(test_line) line_number += 2 output_stream.write("self.ui_test.close_doc()") +output_stream.write("\n\n# vim: set shiftwidth=4 softtabstop=4 expandtab:") output_stream.close() if __name__ == '__main__': ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] core.git: uitest/loginterpreter.py
uitest/loginterpreter.py |9 + 1 file changed, 9 insertions(+) New commits: commit 8801cf6fbe3959cb1485a06fb86a41cc05b28ac6 Author: Saurav Chirania Date: Tue Jul 3 11:31:13 2018 +0530 uitest interpreter: support opening existing document In addition, I have imported the mkPropertyValues function which seems to be necessary in almost all test files. Change-Id: Iee44651aaa05fc2ef5da1d7e0f9281f76819d3e4 Reviewed-on: https://gerrit.libreoffice.org/56850 Tested-by: Jenkins Reviewed-by: Markus Mohrhard diff --git a/uitest/loginterpreter.py b/uitest/loginterpreter.py index 93f391edbfa0..becd8b322937 100644 --- a/uitest/loginterpreter.py +++ b/uitest/loginterpreter.py @@ -41,6 +41,7 @@ def parse_args(): parser = argparse.ArgumentParser(description = "Generate a UI test file from log") parser.add_argument("input_address", type = str, help = "The log file address") parser.add_argument("output_address", type = str, help = "The test file address") +parser.add_argument("-d", "--document", metavar = "", help = "Address of the document to be opened") args = parser.parse_args() return args @@ -65,6 +66,7 @@ def initiate_test_generation(address): sys.exit(1) initial_text = \ "from uitest.framework import UITestCase\n" + \ +"from libreoffice.uno.propertyvalue import mkPropertyValues\n" + \ "import importlib\n\n" + \ "class TestClass(UITestCase):\n" + \ "def test_function(self):\n" @@ -165,6 +167,12 @@ def main(): args = parse_args() log_lines = get_log_file(args.input_address) output_stream = initiate_test_generation(args.output_address) +if args.document is not None: +output_line = "pathmodule = importlib.import_module(\"uitest.path\")\n" + \ +"doc_path = pathmodule.get_srcdir_url() + \"" + args.document + "\"\n" + \ +"MainDoc = self.ui_test.load_file(doc_path)\n" + \ +"MainWindow = self.xUITest.getTopFocusWindow()\n" +output_stream.write(output_line) line_number = 0 while line_number < len(log_lines): if line_number == len(log_lines)-1 or \ @@ -178,6 +186,7 @@ def main(): test_line = get_test_line_from_two_log_lines(log_lines[line_number],log_lines[line_number + 1]) output_stream.write(test_line) line_number += 2 +output_stream.write("self.ui_test.close_doc()") output_stream.close() if __name__ == '__main__': ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] core.git: uitest/loginterpreter.py
uitest/loginterpreter.py |4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) New commits: commit 4914c03245983f913ecdd2a5d9682a05bca1fea7 Author: Saurav Chirania Date: Tue Jul 3 21:37:01 2018 +0530 uitest interpreter: handle when parent is empty string Change-Id: I439e2679ce46872f34e095b7f05fa19d404d2c00 Reviewed-on: https://gerrit.libreoffice.org/56887 Tested-by: Jenkins Reviewed-by: Markus Mohrhard diff --git a/uitest/loginterpreter.py b/uitest/loginterpreter.py index ccc805056a7b..93f391edbfa0 100644 --- a/uitest/loginterpreter.py +++ b/uitest/loginterpreter.py @@ -118,7 +118,9 @@ def get_test_line_from_one_log_line(log_line): action_dict["Id"][:-4] +"\")\nMainWindow = " + \ "self.xUITest.getTopFocusWindow()\n" return test_line -elif (parent != ""): +else: +if (parent == ""): +parent = "MainWindow" test_line += \ action_dict["Id"] + " = " + parent + ".getChild(\"" + \ action_dict["Id"] + "\")\n" + \ ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] core.git: uitest/loginterpreter.py
uitest/loginterpreter.py | 17 - 1 file changed, 16 insertions(+), 1 deletion(-) New commits: commit ad511ce89c3ceddd3a8c6d650ce81df1e35bc48f Author: Saurav Chirania Date: Mon Jul 2 08:46:06 2018 +0530 uitest interpreter: add support for starting apps Change-Id: Iaab98515d2046aaff1e3da4f80de192ebc01a9eb Reviewed-on: https://gerrit.libreoffice.org/56789 Tested-by: Jenkins Reviewed-by: Saurav Chirania diff --git a/uitest/loginterpreter.py b/uitest/loginterpreter.py index 9da08dd0acb9..ccc805056a7b 100644 --- a/uitest/loginterpreter.py +++ b/uitest/loginterpreter.py @@ -98,12 +98,27 @@ def get_coupling_type(line1, line2): return "NOT_A_COUPLE" +def check_app_starting_action(action_dict): +app_starter_button_ids = \ +set(["draw_all", "impress_all", "calc_all" , "writer_all", "database_all", "math_all"]) + +if action_dict["keyword"] == "ButtonUIObject" and action_dict["Action"] == "CLICK" and \ +action_dict["Id"] in app_starter_button_ids: +return True +return False + def get_test_line_from_one_log_line(log_line): action_dict = parse_line(log_line) test_line = "" if action_dict["keyword"].endswith("UIObject"): parent = action_dict["Parent"] -if (parent != ""): +if (check_app_starting_action(action_dict)): +test_line +=\ +"MainDoc = self.ui_test.create_doc_in_start_center(\"" + \ +action_dict["Id"][:-4] +"\")\nMainWindow = " + \ +"self.xUITest.getTopFocusWindow()\n" +return test_line +elif (parent != ""): test_line += \ action_dict["Id"] + " = " + parent + ".getChild(\"" + \ action_dict["Id"] + "\")\n" + \ ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] core.git: uitest/loginterpreter.py
uitest/loginterpreter.py | 31 --- 1 file changed, 12 insertions(+), 19 deletions(-) New commits: commit 5560a23cbc1e61cf55bb8c98202d7c93e21f60f1 Author: Saurav Chirania Date: Sat Jun 30 14:37:46 2018 +0530 uitest interpreter: let's use argparse to parse arguments Reasons to do this- 1) We will add more arguments in future, handling them manually will be time consuming. 2) Argparse generates a useful help message automatically. Change-Id: I7ce8cc2746f7774c4fa7cd5b173da637e10a770b Reviewed-on: https://gerrit.libreoffice.org/56777 Tested-by: Jenkins Reviewed-by: Saurav Chirania diff --git a/uitest/loginterpreter.py b/uitest/loginterpreter.py index efdef95c6473..9da08dd0acb9 100644 --- a/uitest/loginterpreter.py +++ b/uitest/loginterpreter.py @@ -9,11 +9,7 @@ import os import sys - -def usage(): -message = "usage: {program} inputfile outputfile" - -print(message.format(program = os.path.basename(sys.argv[0]))) +import argparse def parse_line(line): """ @@ -37,19 +33,16 @@ def parse_line(line): dict[key] = val return dict -def parse_args(argv): +def parse_args(): """ This function parses the command-line arguments to get the input and output file details """ -if len(argv) != 3: -usage() -sys.exit(1) -else: -input_address = argv[1] -output_address = argv[2] - -return input_address, output_address +parser = argparse.ArgumentParser(description = "Generate a UI test file from log") +parser.add_argument("input_address", type = str, help = "The log file address") +parser.add_argument("output_address", type = str, help = "The test file address") +args = parser.parse_args() +return args def get_log_file(input_address): try: @@ -57,7 +50,7 @@ def get_log_file(input_address): content = f.readlines() except IOError as err: print("IO error: {0}".format(err)) -usage() +print("Use " + os.path.basename(sys.argv[0]) + " -h to get usage instructions") sys.exit(1) content = [x.strip() for x in content] @@ -68,7 +61,7 @@ def initiate_test_generation(address): f = open(address,"w") except IOError as err: print("IO error: {0}".format(err)) -usage() +print("Use " + os.path.basename(sys.argv[0]) + " -h to get usage instructions") sys.exit(1) initial_text = \ "from uitest.framework import UITestCase\n" + \ @@ -152,9 +145,9 @@ def get_test_line_from_two_log_lines(log_line1,log_line2): return test_line def main(): -input_address, output_address = parse_args(sys.argv) -log_lines = get_log_file(input_address) -output_stream = initiate_test_generation(output_address) +args = parse_args() +log_lines = get_log_file(args.input_address) +output_stream = initiate_test_generation(args.output_address) line_number = 0 while line_number < len(log_lines): if line_number == len(log_lines)-1 or \ ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] core.git: uitest/loginterpreter.py
uitest/loginterpreter.py | 22 +- 1 file changed, 21 insertions(+), 1 deletion(-) New commits: commit a4be3ebd4daddab219c347af8583bfbb9d63a843 Author: Saurav Chirania Date: Fri Jun 29 12:33:21 2018 +0530 uitest interpreter: add more features 1) Support UNO commands 2) Support closing dialog using buttons 3) Correct keyword for modless dialog 4) Introduce "Redundant Couple" for couples from which only 1 statement can generate the log. Change-Id: I3541fea6a0b72de2c03626476b8abb43a7324dab Reviewed-on: https://gerrit.libreoffice.org/56776 Tested-by: Jenkins Reviewed-by: Saurav Chirania diff --git a/uitest/loginterpreter.py b/uitest/loginterpreter.py index 252fc4bd6c42..efdef95c6473 100644 --- a/uitest/loginterpreter.py +++ b/uitest/loginterpreter.py @@ -91,9 +91,18 @@ def get_coupling_type(line1, line2): return "COMMAND_MODAL_COUPLE" elif action_dict1["keyword"] == "CommandSent" and \ -action_dict2["keyword"] == "ModelessDialogExecuted": +action_dict2["keyword"] == "ModelessDialogConstructed": return "COMMAND_MODELESS_COUPLE" +elif action_dict1["keyword"] == "ButtonUIObject" and \ +action_dict2["keyword"] == "DialogClosed": +return "BUTTON_DIALOGCLOSE_COUPLE" + +elif "parameters" in action_dict1 and \ +"KEYCODE" in action_dict1["parameters"] and \ +action_dict2["keyword"] == "CommandSent": +return "REDUNDANT_COUPLE" + return "NOT_A_COUPLE" def get_test_line_from_one_log_line(log_line): @@ -113,6 +122,10 @@ def get_test_line_from_one_log_line(log_line): else: test_line += ",tuple())\n" return test_line +elif action_dict["keyword"] == "CommandSent": +test_line += "self.xUITest.executeCommand(\"" + \ +action_dict["Name"] + "\")\n" +return test_line return "" @@ -131,6 +144,11 @@ def get_test_line_from_two_log_lines(log_line1,log_line2): "self.ui_test.execute_modeless_dialog_through_command(\"" + \ action_dict1["Name"] + "\")\n" + \ action_dict2["Id"] + " = self.xUITest.getTopFocusWindow()\n" +elif coupling_type == "BUTTON_DIALOGCLOSE_COUPLE": +test_line += \ +action_dict1["Id"] + " = " + action_dict1["Parent"] + ".getChild(\"" + \ +action_dict1["Id"] + "\")\n self.ui_test.close_dialog_through_button(" + \ +action_dict1["Id"] + ")\n" return test_line def main(): @@ -144,6 +162,8 @@ def main(): test_line = get_test_line_from_one_log_line(log_lines[line_number]) output_stream.write(test_line) line_number += 1 +elif get_coupling_type(log_lines[line_number],log_lines[line_number + 1]) == "REDUNDANT_COUPLE": +line_number += 1 else: test_line = get_test_line_from_two_log_lines(log_lines[line_number],log_lines[line_number + 1]) output_stream.write(test_line) ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] core.git: uitest/loginterpreter.py
uitest/loginterpreter.py | 156 +++ 1 file changed, 156 insertions(+) New commits: commit 04645273d7c9dd6927035b571464148a38d3db9f Author: Saurav Chirania Date: Tue Jun 19 19:56:43 2018 +0530 uitest: interpreter for log files this file interprets the following grammar: [] where keyword describes about the UIObject the user interacts with object_description tells the ID, parent, etc. of the UIObject and parameters are the parameters of the action user performs in a format directly readable by mkPropertyValues keyword examples - ModalDialogExecuted, ButtonUIObject parameter examples - {"TEXT":"A"}, {"POS": 1}, etc. Line-by-line, this interpreter tries to convert given log into python code. An example can be found at- "https://pastebin.com/raw/KQi7Y6ie; Change-Id: Iade4388b16094a94df1893f9925605bee51b164f Reviewed-on: https://gerrit.libreoffice.org/56120 Reviewed-by: Markus Mohrhard Tested-by: Markus Mohrhard diff --git a/uitest/loginterpreter.py b/uitest/loginterpreter.py new file mode 100644 index ..252fc4bd6c42 --- /dev/null +++ b/uitest/loginterpreter.py @@ -0,0 +1,156 @@ +# -*- 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/. +# + +import os +import sys + +def usage(): +message = "usage: {program} inputfile outputfile" + +print(message.format(program = os.path.basename(sys.argv[0]))) + +def parse_line(line): +""" +This function parses a line from log file +and returns the parsed values as a python dictionary +""" +if (line == "" or line.startswith("Action on element")): +return +dict = {} +if "{" in line: +start_index_of_parameters = line.find("{") +end_index_of_parameters = line.find("}") + 1 +parameters = line[start_index_of_parameters:end_index_of_parameters] +dict["parameters"] = parameters +line = line[:start_index_of_parameters-1] +word_list = line.split() +dict["keyword"] = word_list[0] + +for index in range(1,len(word_list)): +key, val = word_list[index].split(":",1) +dict[key] = val +return dict + +def parse_args(argv): +""" +This function parses the command-line arguments +to get the input and output file details +""" +if len(argv) != 3: +usage() +sys.exit(1) +else: +input_address = argv[1] +output_address = argv[2] + +return input_address, output_address + +def get_log_file(input_address): +try: +with open(input_address) as f: +content = f.readlines() +except IOError as err: +print("IO error: {0}".format(err)) +usage() +sys.exit(1) + +content = [x.strip() for x in content] +return content + +def initiate_test_generation(address): +try: +f = open(address,"w") +except IOError as err: +print("IO error: {0}".format(err)) +usage() +sys.exit(1) +initial_text = \ +"from uitest.framework import UITestCase\n" + \ +"import importlib\n\n" + \ +"class TestClass(UITestCase):\n" + \ +"def test_function(self):\n" +f.write(initial_text) +return f + +def get_coupling_type(line1, line2): +""" +This function checks if two consecutive lines of log file +refer to the same event +""" +action_dict1 = parse_line(line1) +action_dict2 = parse_line(line2) + +if action_dict1["keyword"] == "CommandSent" and \ +action_dict2["keyword"] == "ModalDialogExecuted": +return "COMMAND_MODAL_COUPLE" + +elif action_dict1["keyword"] == "CommandSent" and \ +action_dict2["keyword"] == "ModelessDialogExecuted": +return "COMMAND_MODELESS_COUPLE" + +return "NOT_A_COUPLE" + +def get_test_line_from_one_log_line(log_line): +action_dict = parse_line(log_line) +test_line = "" +if action_dict["keyword"].endswith("UIObject"): +parent = action_dict["Parent"] +if (parent != ""): +test_line += \ +action_dict["Id"] + " = " + parent + ".getChild(\"" + \ +action_dict["Id"] + "\")\n" + \ +action_dict["Id"] + ".executeAction(\"" + \ +action_dict["Action"] + "\"" +if "parameters" in action_dict: +test_line += ", mkPropertyValues(" + \ +action_dict["parameters"] + "))\n" +else: +test_line += ",tuple())\n" +return test_line + +return "" + +def get_test_line_from_two_log_lines(log_line1,log_line2): +coupling_type = get_coupling_type(log_line1, log_line2) +action_dict1 =