diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2021-09-08 12:13:32 +0200 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2021-09-08 17:51:47 +0200 |
commit | 2c0e5d8b2e53921f09b2e5036cc25f8b0a177dd6 (patch) | |
tree | 3207b7a36f6308eed648f7404d07420bf4321a81 | |
parent | 9c2d703363798aad33a22b3b4e6ac8043dd53b95 (diff) |
uitest: sc: factor out common code
Change-Id: Iaba3b9633eac26516bbb4bb0b6baadb4c6772fa6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121808
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
-rw-r--r-- | sc/qa/uitest/csv_dialog/tdf114878.py | 44 | ||||
-rw-r--r-- | sc/qa/uitest/csv_dialog/tdf117868.py | 43 | ||||
-rw-r--r-- | sc/qa/uitest/csv_dialog/tdf142395.py | 42 | ||||
-rw-r--r-- | sc/qa/uitest/csv_dialog/tdf57841.py | 41 | ||||
-rw-r--r-- | sc/qa/uitest/csv_dialog/tdf60468.py | 38 | ||||
-rw-r--r-- | sc/qa/uitest/csv_dialog/tdf92503.py | 39 | ||||
-rw-r--r-- | sc/qa/uitest/csv_dialog/tdf96561.py | 40 | ||||
-rw-r--r-- | uitest/libreoffice/calc/csv_dialog.py | 52 |
8 files changed, 113 insertions, 226 deletions
diff --git a/sc/qa/uitest/csv_dialog/tdf114878.py b/sc/qa/uitest/csv_dialog/tdf114878.py index b94368a71343..266f182abdd4 100644 --- a/sc/qa/uitest/csv_dialog/tdf114878.py +++ b/sc/qa/uitest/csv_dialog/tdf114878.py @@ -5,32 +5,19 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. # from uitest.framework import UITestCase -from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file -from libreoffice.uno.propertyvalue import mkPropertyValues +from uitest.uihelper.common import get_state_as_dict from libreoffice.calc.document import get_cell_by_position +from libreoffice.calc.csv_dialog import load_csv_file class Td114878(UITestCase): def test_tdf114878(self): - # Load file from Open dialog - with self.ui_test.execute_dialog_through_command(".uno:Open", close_button="open") as xOpenDialog: - - xFileName = xOpenDialog.getChild("file_name") - xFileName.executeAction("TYPE", mkPropertyValues({"TEXT": get_url_for_data_file("tdf114878.csv")})) - - xDialog = self.ui_test.wait_for_top_focus_window('TextImportCsvDialog') - # First import the file with 'Evaluate Formulas' unchecked - - # Without the fix in place, this test would have failed with - # Could not find child with id: evaluateformulas - xEvalutateFormulas = xDialog.getChild("evaluateformulas") - self.assertEqual('false', get_state_as_dict(xEvalutateFormulas)['Selected']) - - xOK = xDialog.getChild('ok') - with self.ui_test.wait_until_component_loaded(): - self.ui_test.close_dialog_through_button(xOK) + with load_csv_file(self, "tdf114878.csv", True): + # Without the fix in place, this test would have failed with + # Could not find child with id: evaluateformulas + pass document = self.ui_test.get_component() @@ -41,22 +28,11 @@ class Td114878(UITestCase): self.ui_test.close_doc() - # Load the same file again - with self.ui_test.execute_dialog_through_command(".uno:Open", close_button="open") as xOpenDialog: - - xFileName = xOpenDialog.getChild("file_name") - xFileName.executeAction("TYPE", mkPropertyValues({"TEXT": get_url_for_data_file("tdf114878.csv")})) - - xDialog = self.ui_test.wait_for_top_focus_window('TextImportCsvDialog') - # Now import the file with 'Evaluate Formulas' checked - xEvalutateFormulas = xDialog.getChild("evaluateformulas") - xEvalutateFormulas.executeAction("CLICK", tuple()) - self.assertEqual('true', get_state_as_dict(xEvalutateFormulas)['Selected']) - - xOK = xDialog.getChild('ok') - with self.ui_test.wait_until_component_loaded(): - self.ui_test.close_dialog_through_button(xOK) + with load_csv_file(self, "tdf114878.csv", True) as xDialog: + xEvalutateFormulas = xDialog.getChild("evaluateformulas") + xEvalutateFormulas.executeAction("CLICK", tuple()) + self.assertEqual('true', get_state_as_dict(xEvalutateFormulas)['Selected']) document = self.ui_test.get_component() diff --git a/sc/qa/uitest/csv_dialog/tdf117868.py b/sc/qa/uitest/csv_dialog/tdf117868.py index 5cfcd1503749..0a2dac3a7ef7 100644 --- a/sc/qa/uitest/csv_dialog/tdf117868.py +++ b/sc/qa/uitest/csv_dialog/tdf117868.py @@ -5,41 +5,30 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. # from uitest.framework import UITestCase -from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file -from libreoffice.uno.propertyvalue import mkPropertyValues +from uitest.uihelper.common import get_state_as_dict from libreoffice.calc.document import get_cell_by_position +from libreoffice.calc.csv_dialog import load_csv_file class Td117868(UITestCase): def test_tdf117868(self): - # Load file from Open dialog - with self.ui_test.execute_dialog_through_command(".uno:Open", close_button="open") as xOpenDialog: + with load_csv_file(self, "tdf117868.csv", False) as xDialog: + # Set text delimiter in case it's changed by another test + xSeparatedBy = xDialog.getChild("toseparatedby") + xSeparatedBy.executeAction("CLICK", tuple()) - xFileName = xOpenDialog.getChild("file_name") - xFileName.executeAction("TYPE", mkPropertyValues({"TEXT": get_url_for_data_file("tdf117868.csv")})) + # Without the fix in place, this test would have failed with + # AssertionError: 'true' != 'false' + self.assertEqual('true', get_state_as_dict(xDialog.getChild("other"))['Selected']) + self.assertEqual('false', get_state_as_dict(xDialog.getChild("tab"))['Selected']) + self.assertEqual('false', get_state_as_dict(xDialog.getChild("comma"))['Selected']) + self.assertEqual('false', get_state_as_dict(xDialog.getChild("semicolon"))['Selected']) - xDialog = self.ui_test.wait_for_top_focus_window('TextImportCsvDialog') + self.assertEqual('1', get_state_as_dict(xDialog.getChild("fromrow"))['Text']) - # Set text delimiter in case it's changed by another test - xSeparatedBy = xDialog.getChild("toseparatedby") - xSeparatedBy.executeAction("CLICK", tuple()) - - # Without the fix in place, this test would have failed with - # AssertionError: 'true' != 'false' - self.assertEqual('true', get_state_as_dict(xDialog.getChild("other"))['Selected']) - self.assertEqual('false', get_state_as_dict(xDialog.getChild("tab"))['Selected']) - self.assertEqual('false', get_state_as_dict(xDialog.getChild("comma"))['Selected']) - self.assertEqual('false', get_state_as_dict(xDialog.getChild("semicolon"))['Selected']) - - self.assertEqual('1', get_state_as_dict(xDialog.getChild("fromrow"))['Text']) - - xInputOther = xDialog.getChild("inputother") - self.assertEqual("|", get_state_as_dict(xInputOther)['Text']) - - xOK = xDialog.getChild('ok') - with self.ui_test.wait_until_component_loaded(): - self.ui_test.close_dialog_through_button(xOK) + xInputOther = xDialog.getChild("inputother") + self.assertEqual("|", get_state_as_dict(xInputOther)['Text']) document = self.ui_test.get_component() @@ -52,4 +41,6 @@ class Td117868(UITestCase): self.assertEqual('c', get_cell_by_position(document, 0, 0, 4).getString()) self.assertEqual('cow', get_cell_by_position(document, 0, 1, 4).getString()) + self.ui_test.close_doc() + # vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/sc/qa/uitest/csv_dialog/tdf142395.py b/sc/qa/uitest/csv_dialog/tdf142395.py index 66efc397d5b3..829bcb951663 100644 --- a/sc/qa/uitest/csv_dialog/tdf142395.py +++ b/sc/qa/uitest/csv_dialog/tdf142395.py @@ -5,47 +5,18 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. # from uitest.framework import UITestCase -from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file from libreoffice.uno.propertyvalue import mkPropertyValues from libreoffice.calc.document import get_cell_by_position +from libreoffice.calc.csv_dialog import load_csv_file class Tdf142395(UITestCase): def test_tdf142395(self): - - # Load file from Open dialog - with self.ui_test.execute_dialog_through_command(".uno:Open", close_button="open") as xOpenDialog: - - xFileName = xOpenDialog.getChild("file_name") - xFileName.executeAction("TYPE", mkPropertyValues({"TEXT": get_url_for_data_file("tdf142395.csv")})) - - - xDialog = self.ui_test.wait_for_top_focus_window('TextImportCsvDialog') - xSeparatedBy = xDialog.getChild("toseparatedby") - xSeparatedBy.executeAction("CLICK", tuple()) - - # Remove the text delimiter - xTextDelimiter = xDialog.getChild("textdelimiter") - xTextDelimiter.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) - xTextDelimiter.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"})) - - xTab = xDialog.getChild("tab") - if get_state_as_dict(xTab)['Selected'] == 'false': - xTab.executeAction("CLICK", tuple()) - self.assertEqual('true', get_state_as_dict(xTab)['Selected']) - xComma = xDialog.getChild("comma") - if get_state_as_dict(xComma)['Selected'] == 'false': - xComma.executeAction("CLICK", tuple()) - self.assertEqual('true', get_state_as_dict(xComma)['Selected']) - xSemicolon = xDialog.getChild("semicolon") - if get_state_as_dict(xSemicolon)['Selected'] == 'false': - xSemicolon.executeAction("CLICK", tuple()) - self.assertEqual('true', get_state_as_dict(xSemicolon)['Selected']) - self.assertEqual('1', get_state_as_dict(xDialog.getChild("fromrow"))['Text']) - - xOK = xDialog.getChild('ok') - with self.ui_test.wait_until_component_loaded(): - self.ui_test.close_dialog_through_button(xOK) + with load_csv_file(self, "tdf142395.csv", True) as xDialog: + # Remove the text delimiter + xTextDelimiter = xDialog.getChild("textdelimiter") + xTextDelimiter.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) + xTextDelimiter.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"})) document = self.ui_test.get_component() @@ -62,5 +33,6 @@ class Tdf142395(UITestCase): self.assertEqual(" g", get_cell_by_position(document, 0, 2, 1).getString()) self.assertEqual(" ", get_cell_by_position(document, 0, 3, 1).getString()) + self.ui_test.close_doc() # vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/sc/qa/uitest/csv_dialog/tdf57841.py b/sc/qa/uitest/csv_dialog/tdf57841.py index da9948727b7a..f7b068ada681 100644 --- a/sc/qa/uitest/csv_dialog/tdf57841.py +++ b/sc/qa/uitest/csv_dialog/tdf57841.py @@ -5,48 +5,14 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. # from uitest.framework import UITestCase -from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file -from libreoffice.uno.propertyvalue import mkPropertyValues from libreoffice.calc.document import get_cell_by_position +from libreoffice.calc.csv_dialog import load_csv_file class Tdf57841(UITestCase): def test_tdf57841(self): - - # Load file from Open dialog - with self.ui_test.execute_dialog_through_command(".uno:Open", close_button="open") as xOpenDialog: - - xFileName = xOpenDialog.getChild("file_name") - xFileName.executeAction("TYPE", mkPropertyValues({"TEXT": get_url_for_data_file("tdf57841.csv")})) - - - xDialog = self.ui_test.wait_for_top_focus_window('TextImportCsvDialog') - xTab = xDialog.getChild("tab") - if get_state_as_dict(xTab)['Selected'] == 'false': - xTab.executeAction("CLICK", tuple()) - self.assertEqual('true', get_state_as_dict(xTab)['Selected']) - xComma = xDialog.getChild("comma") - if get_state_as_dict(xComma)['Selected'] == 'false': - xComma.executeAction("CLICK", tuple()) - self.assertEqual('true', get_state_as_dict(xComma)['Selected']) - xSemicolon = xDialog.getChild("semicolon") - if get_state_as_dict(xSemicolon)['Selected'] == 'false': - xSemicolon.executeAction("CLICK", tuple()) - self.assertEqual('true', get_state_as_dict(xSemicolon)['Selected']) - self.assertEqual('1', get_state_as_dict(xDialog.getChild("fromrow"))['Text']) - - # Set text delimiter in case it's changed by another test - xSeparatedBy = xDialog.getChild("toseparatedby") - xSeparatedBy.executeAction("CLICK", tuple()) - - xTextDelimiter = xDialog.getChild("textdelimiter") - xTextDelimiter.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) - xTextDelimiter.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"})) - xTextDelimiter.executeAction("TYPE", mkPropertyValues({"TEXT": "\""})) - - xOK = xDialog.getChild('ok') - with self.ui_test.wait_until_component_loaded(): - self.ui_test.close_dialog_through_button(xOK) + with load_csv_file(self, "tdf57841.csv", True): + pass document = self.ui_test.get_component() @@ -55,5 +21,6 @@ class Tdf57841(UITestCase): for i in range(4): self.assertEqual(str(i + 1), get_cell_by_position(document, 0, i, 0).getString()) + self.ui_test.close_doc() # vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/sc/qa/uitest/csv_dialog/tdf60468.py b/sc/qa/uitest/csv_dialog/tdf60468.py index 72650c79d07e..d4686324141f 100644 --- a/sc/qa/uitest/csv_dialog/tdf60468.py +++ b/sc/qa/uitest/csv_dialog/tdf60468.py @@ -5,47 +5,16 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. # from uitest.framework import UITestCase -from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file -from libreoffice.uno.propertyvalue import mkPropertyValues from libreoffice.calc.document import get_cell_by_position +from libreoffice.calc.csv_dialog import load_csv_file class Tdf60468(UITestCase): def test_tdf60468(self): # Load file from Open dialog - with self.ui_test.execute_dialog_through_command(".uno:Open", close_button="open") as xOpenDialog: - - xFileName = xOpenDialog.getChild("file_name") - xFileName.executeAction("TYPE", mkPropertyValues({"TEXT": get_url_for_data_file("tdf60468.csv")})) - - xDialog = self.ui_test.wait_for_top_focus_window('TextImportCsvDialog') - xTab = xDialog.getChild("tab") - if get_state_as_dict(xTab)['Selected'] == 'false': - xTab.executeAction("CLICK", tuple()) - self.assertEqual('true', get_state_as_dict(xTab)['Selected']) - xComma = xDialog.getChild("comma") - if get_state_as_dict(xComma)['Selected'] == 'false': - xComma.executeAction("CLICK", tuple()) - self.assertEqual('true', get_state_as_dict(xComma)['Selected']) - xSemicolon = xDialog.getChild("semicolon") - if get_state_as_dict(xSemicolon)['Selected'] == 'false': - xSemicolon.executeAction("CLICK", tuple()) - self.assertEqual('true', get_state_as_dict(xSemicolon)['Selected']) - self.assertEqual('1', get_state_as_dict(xDialog.getChild("fromrow"))['Text']) - - # Set text delimiter in case it's changed by another test - xSeparatedBy = xDialog.getChild("toseparatedby") - xSeparatedBy.executeAction("CLICK", tuple()) - - xTextDelimiter = xDialog.getChild("textdelimiter") - xTextDelimiter.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) - xTextDelimiter.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"})) - xTextDelimiter.executeAction("TYPE", mkPropertyValues({"TEXT": "\""})) - - xOK = xDialog.getChild('ok') - with self.ui_test.wait_until_component_loaded(): - self.ui_test.close_dialog_through_button(xOK) + with load_csv_file(self, "tdf60468.csv", True): + pass document = self.ui_test.get_component() @@ -61,5 +30,6 @@ class Tdf60468(UITestCase): self.assertEqual("value2.1\n\tvalue2.2\nvalue2.3", get_cell_by_position(document, 0, 1, 1).getString()) self.assertEqual("value3", get_cell_by_position(document, 0, 2, 1).getString()) + self.ui_test.close_doc() # vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/sc/qa/uitest/csv_dialog/tdf92503.py b/sc/qa/uitest/csv_dialog/tdf92503.py index 08a53b56d269..c29302cfd31e 100644 --- a/sc/qa/uitest/csv_dialog/tdf92503.py +++ b/sc/qa/uitest/csv_dialog/tdf92503.py @@ -5,41 +5,30 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. # from uitest.framework import UITestCase -from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file +from uitest.uihelper.common import get_state_as_dict from libreoffice.uno.propertyvalue import mkPropertyValues from libreoffice.calc.document import get_cell_by_position +from libreoffice.calc.csv_dialog import load_csv_file class Tdf92503(UITestCase): def test_tdf92503(self): + with load_csv_file(self, "tdf92503.csv", True) as xDialog: + xFixedWidth = xDialog.getChild("tofixedwidth") + xGrid = xDialog.getChild("csvgrid") + xColumnType = xDialog.getChild("columntype") - # Load file from Open dialog - with self.ui_test.execute_dialog_through_command(".uno:Open", close_button="open") as xOpenDialog: + xFixedWidth.executeAction("CLICK", tuple()) + self.assertEqual('true', get_state_as_dict(xFixedWidth)['Checked']) - xFileName = xOpenDialog.getChild("file_name") - xFileName.executeAction("TYPE", mkPropertyValues({"TEXT": get_url_for_data_file("tdf92503.csv")})) + # Use the right arrow to put the focus in the grid + xGrid.executeAction("TYPE", mkPropertyValues({"KEYCODE":"RIGHT"})) - xDialog = self.ui_test.wait_for_top_focus_window('TextImportCsvDialog') - xFixedWidth = xDialog.getChild("tofixedwidth") - xGrid = xDialog.getChild("csvgrid") - xColumnType = xDialog.getChild("columntype") + self.assertEqual('true', get_state_as_dict(xColumnType)['Enabled']) - self.assertEqual('false', get_state_as_dict(xFixedWidth)['Checked']) - xFixedWidth.executeAction("CLICK", tuple()) - self.assertEqual('true', get_state_as_dict(xFixedWidth)['Checked']) + xColumnType.executeAction("SELECT", mkPropertyValues({"TEXT": "Date (DMY)"})) - # Use the right arrow to put the focus in the grid - xGrid.executeAction("TYPE", mkPropertyValues({"KEYCODE":"RIGHT"})) - - self.assertEqual('true', get_state_as_dict(xColumnType)['Enabled']) - - xColumnType.executeAction("SELECT", mkPropertyValues({"TEXT": "Date (DMY)"})) - - self.assertEqual('Date (DMY)', get_state_as_dict(xColumnType)['SelectEntryText']) - - xOK = xDialog.getChild('ok') - with self.ui_test.wait_until_component_loaded(): - self.ui_test.close_dialog_through_button(xOK) + self.assertEqual('Date (DMY)', get_state_as_dict(xColumnType)['SelectEntryText']) document = self.ui_test.get_component() @@ -56,4 +45,6 @@ class Tdf92503(UITestCase): self.assertEqual("03/29/15 02:00 AM", get_cell_by_position(document, 0, 0, 7).getString()) self.assertEqual("03/29/15 03:00 AM", get_cell_by_position(document, 0, 0, 8).getString()) + self.ui_test.close_doc() + # vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/sc/qa/uitest/csv_dialog/tdf96561.py b/sc/qa/uitest/csv_dialog/tdf96561.py index 6bf3b1d3de21..02d68e599109 100644 --- a/sc/qa/uitest/csv_dialog/tdf96561.py +++ b/sc/qa/uitest/csv_dialog/tdf96561.py @@ -5,47 +5,14 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. # from uitest.framework import UITestCase -from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file -from libreoffice.uno.propertyvalue import mkPropertyValues from libreoffice.calc.document import get_cell_by_position +from libreoffice.calc.csv_dialog import load_csv_file class Tdf96561(UITestCase): def test_tdf96561(self): - - # Load file from Open dialog - with self.ui_test.execute_dialog_through_command(".uno:Open", close_button="open") as xOpenDialog: - - xFileName = xOpenDialog.getChild("file_name") - xFileName.executeAction("TYPE", mkPropertyValues({"TEXT": get_url_for_data_file("tdf96561.csv")})) - - xDialog = self.ui_test.wait_for_top_focus_window('TextImportCsvDialog') - xTab = xDialog.getChild("tab") - if get_state_as_dict(xTab)['Selected'] == 'false': - xTab.executeAction("CLICK", tuple()) - self.assertEqual('true', get_state_as_dict(xTab)['Selected']) - xComma = xDialog.getChild("comma") - if get_state_as_dict(xComma)['Selected'] == 'false': - xComma.executeAction("CLICK", tuple()) - self.assertEqual('true', get_state_as_dict(xComma)['Selected']) - xSemicolon = xDialog.getChild("semicolon") - if get_state_as_dict(xSemicolon)['Selected'] == 'false': - xSemicolon.executeAction("CLICK", tuple()) - self.assertEqual('true', get_state_as_dict(xSemicolon)['Selected']) - self.assertEqual('1', get_state_as_dict(xDialog.getChild("fromrow"))['Text']) - - # Set text delimiter in case it's changed by another test - xSeparatedBy = xDialog.getChild("toseparatedby") - xSeparatedBy.executeAction("CLICK", tuple()) - - xTextDelimiter = xDialog.getChild("textdelimiter") - xTextDelimiter.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) - xTextDelimiter.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"})) - xTextDelimiter.executeAction("TYPE", mkPropertyValues({"TEXT": "\""})) - - xOK = xDialog.getChild('ok') - with self.ui_test.wait_until_component_loaded(): - self.ui_test.close_dialog_through_button(xOK) + with load_csv_file(self, "tdf96561.csv", True): + pass document = self.ui_test.get_component() @@ -60,5 +27,6 @@ class Tdf96561(UITestCase): for j in range(0,3): self.assertEqual("1", get_cell_by_position(document, 0, i, j).getString()) + self.ui_test.close_doc() # vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/uitest/libreoffice/calc/csv_dialog.py b/uitest/libreoffice/calc/csv_dialog.py new file mode 100644 index 000000000000..e15eea1a7564 --- /dev/null +++ b/uitest/libreoffice/calc/csv_dialog.py @@ -0,0 +1,52 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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/. +# + +from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file +from libreoffice.uno.propertyvalue import mkPropertyValues +from contextlib import contextmanager + +@contextmanager +def load_csv_file(UITestCase, fileName, bUseDefaultOptions): + with UITestCase.ui_test.execute_dialog_through_command(".uno:Open", close_button="open") as xOpenDialog: + + xFileName = xOpenDialog.getChild("file_name") + xFileName.executeAction("TYPE", mkPropertyValues({"TEXT": get_url_for_data_file(fileName)})) + + xDialog = UITestCase.ui_test.wait_for_top_focus_window('TextImportCsvDialog') + + try: + if bUseDefaultOptions: + xSeparatedBy = xDialog.getChild("toseparatedby") + xSeparatedBy.executeAction("CLICK", tuple()) + + xTextDelimiter = xDialog.getChild("textdelimiter") + xTextDelimiter.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) + xTextDelimiter.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"})) + xTextDelimiter.executeAction("TYPE", mkPropertyValues({"TEXT": "\""})) + + setToTrue = ['tab', 'comma', 'semicolon'] + for childName in setToTrue: + xChild = xDialog.getChild(childName) + if get_state_as_dict(xChild)['Selected'] == 'false': + xChild.executeAction("CLICK", tuple()) + UITestCase.assertEqual('true', get_state_as_dict(xChild)['Selected']) + + setToFalse = ['space', 'other', 'removespace', 'mergedelimiters', + 'evaluateformulas', 'quotedfieldastext', 'detectspecialnumbers'] + for childName in setToFalse: + xChild = xDialog.getChild(childName) + if get_state_as_dict(xChild)['Selected'] == 'true': + xChild.executeAction("CLICK", tuple()) + UITestCase.assertEqual('false', get_state_as_dict(xChild)['Selected']) + + UITestCase.assertEqual('1', get_state_as_dict(xDialog.getChild("fromrow"))['Text']) + + yield xDialog + finally: + xOK = xDialog.getChild('ok') + with UITestCase.ui_test.wait_until_component_loaded(): + UITestCase.ui_test.close_dialog_through_button(xOK) |