From 37b40939a076cf21767d0bad3bd302a2d90a0575 Mon Sep 17 00:00:00 2001 From: Robin Matz Date: Sat, 16 Jul 2022 16:59:21 +0200 Subject: [PATCH 1/5] Support all Robot Framework time formats --- Mainframe3270/__init__.py | 14 +++-- Mainframe3270/x3270.py | 63 +++++++++++-------- README.md | 5 +- atest/connection.robot | 3 + atest/mainframe.robot | 7 ++- .../custom_keyword_on_import.robot | 3 + atest/run_on_failure/none_on_import.robot | 3 + atest/run_on_failure/run_on_failure.robot | 3 + requirements-dev.txt | 2 +- utest/x3270/test__init__.py | 7 +++ utest/x3270/test_wait_and_timeout.py | 54 ++++++++++++++-- 11 files changed, 123 insertions(+), 41 deletions(-) diff --git a/Mainframe3270/__init__.py b/Mainframe3270/__init__.py index 680935b..2f9e545 100644 --- a/Mainframe3270/__init__.py +++ b/Mainframe3270/__init__.py @@ -1,3 +1,4 @@ +from datetime import timedelta from typing import Any from robot.api import logger @@ -28,8 +29,8 @@ class Mainframe3270(DynamicCore): | *** Test Cases *** | Example | Open Connection Hostname LUname - | Change Wait Time 0.4 - | Change Wait Time After Write 0.4 + | Change Wait Time 0.4 seconds + | Change Wait Time After Write 0.4 seconds | Set Screenshot Folder C:\\Temp\\IMG | ${value} Read 3 10 17 | Page Should Contain String ENTER APPLICATION @@ -46,9 +47,9 @@ class Mainframe3270(DynamicCore): def __init__( self, visible: bool = True, - timeout: int = 30, - wait_time: float = 0.5, - wait_time_after_write: float = 0.0, + timeout: timedelta = timedelta(seconds=30), + wait_time: timedelta = timedelta(milliseconds=500), + wait_time_after_write: timedelta = timedelta(seconds=0), img_folder: str = ".", run_on_failure_keyword: str = "Take Screenshot", ) -> None: @@ -62,7 +63,8 @@ def __init__( Timeout, waits and screenshot folder are set on library import as shown above. However, they can be changed during runtime. To modify the ``wait_time``, see `Change Wait Time`, to modify the ``img_folder``, see `Set Screenshot Folder`, - and to modify the ``timeout``, see the `Change Timeout` keyword. + and to modify the ``timeout``, see the `Change Timeout` keyword. Timeouts support all available + Robot Framework [https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#time-format|time formats]. By default, Mainframe3270 will take a screenshot on failure. You can overwrite this to run any other keyword by setting the ``run_on_failure_keyword`` option. diff --git a/Mainframe3270/x3270.py b/Mainframe3270/x3270.py index ae4c166..4770881 100644 --- a/Mainframe3270/x3270.py +++ b/Mainframe3270/x3270.py @@ -2,12 +2,13 @@ import re import socket import time +from datetime import timedelta from typing import Any, List, Optional, Union from robot.api import logger from robot.api.deco import keyword from robot.libraries.BuiltIn import BuiltIn, RobotNotRunningError -from robot.utils import Matcher +from robot.utils import Matcher, secs_to_timestr, timestr_to_secs from .py3270 import Emulator @@ -16,15 +17,15 @@ class x3270(object): def __init__( self, visible: bool, - timeout: int, - wait_time: float, - wait_time_after_write: float, + timeout: timedelta, + wait_time: timedelta, + wait_time_after_write: timedelta, img_folder: str, ) -> None: self.visible = visible - self.timeout = timeout - self.wait = wait_time - self.wait_write = wait_time_after_write + self.timeout = self._convert_timeout(timeout) + self.wait = self._convert_timeout(wait_time) + self.wait_write = self._convert_timeout(wait_time_after_write) self.imgfolder = img_folder self.mf: Emulator = None # type: ignore # Try Catch to run in Pycharm, and make a documentation in libdoc with no error @@ -33,15 +34,20 @@ def __init__( except RobotNotRunningError: self.output_folder = os.getcwd() + def _convert_timeout(self, time): + if isinstance(time, timedelta): + return time.total_seconds() + return timestr_to_secs(time, round_to=None) + @keyword("Change Timeout") - def change_timeout(self, seconds: int) -> None: + def change_timeout(self, seconds: timedelta) -> None: """ Change the timeout for connection in seconds. Example: - | Change Timeout | 3 | + | Change Timeout | 3 seconds | """ - self.timeout = seconds + self.timeout = self._convert_timeout(seconds) @keyword("Open Connection") def open_connection( @@ -97,7 +103,7 @@ def close_connection(self) -> None: self.mf = None # type: ignore @keyword("Change Wait Time") - def change_wait_time(self, wait_time: float) -> None: + def change_wait_time(self, wait_time: timedelta) -> None: """To give time for the mainframe screen to be "drawn" and receive the next commands, a "wait time" has been created, which by default is set to 0.5 seconds. This is a sleep applied AFTER the following keywords: @@ -110,13 +116,14 @@ def change_wait_time(self, wait_time: float) -> None: If you want to change this value, just use this keyword passing the time in seconds. Example: - | Change Wait Time | 0.1 | - | Change Wait Time | 2 | + | Change Wait Time | 0.5 | + | Change Wait Time | 200 milliseconds | + | Change Wait Time | 0:00:01.500 | """ - self.wait = wait_time + self.wait = self._convert_timeout(wait_time) @keyword("Change Wait Time After Write") - def change_wait_time_after_write(self, wait_time_after_write: float) -> None: + def change_wait_time_after_write(self, wait_time_after_write: timedelta) -> None: """To give the user time to see what is happening inside the mainframe, a "wait time after write" has been created, which by default is set to 0 seconds. This is a sleep applied AFTER sending a string in these keywords: @@ -131,10 +138,11 @@ def change_wait_time_after_write(self, wait_time_after_write: float) -> None: Note: This keyword is useful for debug purpose Example: - | Change Wait Time After Write | 0.5 | - | Change Wait Time After Write | 2 | + | Change Wait Time After Write | 1 | + | Change Wait Time After Write | 0.5 seconds | + | Change Wait Time After Write | 0:00:02 | """ - self.wait_write = wait_time_after_write + self.wait_write = self._convert_timeout(wait_time_after_write) @keyword("Read") def read(self, ypos: int, xpos: int, length: int) -> str: @@ -365,22 +373,25 @@ def _write( time.sleep(self.wait) @keyword("Wait Until String") - def wait_until_string(self, txt: str, timeout: int = 5) -> str: + def wait_until_string( + self, txt: str, timeout: timedelta = timedelta(seconds=5) + ) -> str: """Wait until a string exists on the mainframe screen to perform the next step. If the string does not appear in 5 seconds, the keyword will raise an exception. You can define a different timeout. Example: | Wait Until String | something | - | Wait Until String | something | timeout=10 | + | Wait Until String | something | 10 | + | Wait Until String | something | 15 s | + | Wait Until String | something | 0:00:15 | """ - max_time = time.ctime(int(time.time()) + timeout) - while time.ctime(int(time.time())) < max_time: + timeout = self._convert_timeout(timeout) + max_time = time.time() + timeout # type: ignore + while time.time() < max_time: result = self._search_string(str(txt)) if result: return txt - raise Exception( - 'String "' + txt + '" not found in ' + str(timeout) + " seconds" - ) + raise Exception(f'String "{txt}" not found in {secs_to_timestr(timeout)}') def _search_string(self, string: str, ignore_case: bool = False) -> bool: """Search if a string exists on the mainframe screen and return True or False.""" @@ -409,7 +420,7 @@ def page_should_contain_string( Example: | Page Should Contain String | something | - | Page Should Contain String | someTHING | ignore_case=True | + | Page Should Contain String | someTHING | ignore_case=True | | Page Should Contain String | something | error_message=New error message | """ message = 'The string "' + txt + '" was not found' diff --git a/README.md b/README.md index 52f560f..a6d4a77 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,8 @@ Library Mainframe3270 *** Test Cases *** Example Open Connection Hostname LUname - Change Wait Time 0.4 - Change Wait Time After Write 0.4 + Change Wait Time 0.4 seconds + Change Wait Time After Write 0.4 seconds Set Screenshot Folder C:\\Temp\\IMG ${value} Read 3 10 17 Page Should Contain String ENTER APPLICATION @@ -71,6 +71,7 @@ This is useful when test cases are run in a CI/CD-pipeline and there is no need Timeout, waits and screenshot folder are set on library import as shown above. However, they can be changed during runtime. To modify the ``wait_time``, see [Change Wait Time](https://raw.githack.com/Altran-PT-GDC/Robot-Framework-Mainframe-3270-Library/master/doc/Mainframe3270.html#Change%20Wait%20Time), to modify the ``img_folder``, see [Set Screenshot Folder](https://raw.githack.com/Altran-PT-GDC/Robot-Framework-Mainframe-3270-Library/master/doc/Mainframe3270.html#Set%20Screenshot%20Folder), and to modify the ``timeout``, see the [Change Timeout](https://raw.githack.com/Altran-PT-GDC/Robot-Framework-Mainframe-3270-Library/master/doc/Mainframe3270.html#Change%20Timeout) keyword. +Timeouts support all available Robot Framework [time formats](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#time-format). By default, Mainframe3270 will take a screenshot on failure. You can overwrite this to run any other keyword by setting the ``run_on_failure_keyword`` option. If you pass ``None`` to this argument, no keyword will be run. To change the ``run_on_failure_keyword`` during runtime, see [Register Run On Failure Keyword](https://raw.githack.com/Altran-PT-GDC/Robot-Framework-Mainframe-3270-Library/master/doc/Mainframe3270.html#Register%20Run%20On%20Failure%20Keyword). diff --git a/atest/connection.robot b/atest/connection.robot index 634dfd2..e16ba0e 100644 --- a/atest/connection.robot +++ b/atest/connection.robot @@ -5,10 +5,12 @@ Resource pub400_variables.robot Test Teardown Test Teardown + *** Variables *** ${ARGFILE} ${CURDIR}/resources/argfile.txt ${TRACE_FILE} ${CURDIR}/x3270.trace + *** Test Cases *** Test Connection With Extra Args List ${extra_args} Create List -trace -tracefile ${TRACE_FILE} @@ -21,6 +23,7 @@ Test Connection With Argfile Sleep 0.5 s File Should Exist ${TRACE_FILE} + *** Keywords *** Test Teardown Close Connection diff --git a/atest/mainframe.robot b/atest/mainframe.robot index 7e5bb8c..9be603e 100644 --- a/atest/mainframe.robot +++ b/atest/mainframe.robot @@ -13,6 +13,7 @@ Suite Setup Open Mainframe Suite Teardown Close Mainframe Test Teardown Run Keyword If Test Failed Fatal Error + *** Test Cases *** Exception Test [Setup] Initial Setting @@ -60,6 +61,7 @@ Test With Login Test Send Enter Test Send PF + *** Keywords *** Open Mainframe Open Connection ${host} @@ -232,7 +234,10 @@ Exception Test Page Should Contain String Exception Test Page Should Contain All Strings Verify String Not Found In List Page Should Contain All Strings ${list_strings_wrong_case_in_the_first} 1 - Verify String Not Found In List Page Should Contain All Strings ${list_strings_wrong_case_in_the_second} 2 + Verify String Not Found In List + ... Page Should Contain All Strings + ... ${list_strings_wrong_case_in_the_second} + ... 2 Verify String Not Found In List Page Should Contain All Strings ${list_strings_wrong_case_in_the_third} 3 Verify String Not Found In List Page Should Contain All Strings ${list_strings_wrong_in_the_first} 1 ... ignore_case=${True} diff --git a/atest/run_on_failure/custom_keyword_on_import.robot b/atest/run_on_failure/custom_keyword_on_import.robot index c902d46..c35e8e7 100644 --- a/atest/run_on_failure/custom_keyword_on_import.robot +++ b/atest/run_on_failure/custom_keyword_on_import.robot @@ -5,17 +5,20 @@ Library OperatingSystem Suite Setup Open Mainframe Suite Teardown Close Mainframe + *** Variables *** ${custom_file} ${CURDIR}${/}output.txt ${host} pub400.com ${not_found_string} 4%$3123 + *** Test Cases *** Should Run Custom Keyword Cause Error File Should Exist ${custom_file} [Teardown] Remove File ${custom_file} + *** Keywords *** Open Mainframe Open Connection ${host} diff --git a/atest/run_on_failure/none_on_import.robot b/atest/run_on_failure/none_on_import.robot index dab07b0..06c5fdc 100644 --- a/atest/run_on_failure/none_on_import.robot +++ b/atest/run_on_failure/none_on_import.robot @@ -5,17 +5,20 @@ Library OperatingSystem Suite Setup Open Mainframe Suite Teardown Close Mainframe + *** Variables *** ${custom_file} ${CURDIR}${/}output.txt ${host} pub400.com ${not_found_string} 4%$3123 + *** Test Cases *** None Should Run On Failure Register Run On Failure Keyword None Cause Error File Should Not Exist ${CURDIR}/*.html + *** Keywords *** Open Mainframe Open Connection ${host} diff --git a/atest/run_on_failure/run_on_failure.robot b/atest/run_on_failure/run_on_failure.robot index e2332cb..98a31a8 100644 --- a/atest/run_on_failure/run_on_failure.robot +++ b/atest/run_on_failure/run_on_failure.robot @@ -5,11 +5,13 @@ Library OperatingSystem Suite Setup Open Mainframe Suite Teardown Close Mainframe + *** Variables *** ${custom_file} ${CURDIR}${/}output.txt ${host} pub400.com ${not_found_string} 4%$3123 + *** Test Cases *** Takes Screenshot On Failure Cause Error @@ -27,6 +29,7 @@ Register None To Run On Failure Cause Error File Should Not Exist ${CURDIR}/*.html + *** Keywords *** Open Mainframe Open Connection ${host} diff --git a/requirements-dev.txt b/requirements-dev.txt index c90cc71..9f5a755 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -6,6 +6,6 @@ isort mypy pytest pytest-mock -robotframework-tidy +robotframework-tidy >= 3.0 types-six -r requirements.txt \ No newline at end of file diff --git a/utest/x3270/test__init__.py b/utest/x3270/test__init__.py index a829e60..06a3550 100644 --- a/utest/x3270/test__init__.py +++ b/utest/x3270/test__init__.py @@ -17,6 +17,13 @@ def test_default_args(): under_test.mf is None +def test_import_with_time_string(): + under_test = x3270(True, "30 s", "500 milliseconds", "1 minute", ".") + assert under_test.timeout == 30 + assert under_test.wait == 0.5 + assert under_test.wait_write == 60 + + def test_output_folder_robotframework_running(mocker: MockerFixture): m_get_variable_value = mocker.patch( "robot.libraries.BuiltIn.BuiltIn.get_variable_value", diff --git a/utest/x3270/test_wait_and_timeout.py b/utest/x3270/test_wait_and_timeout.py index ad1ddad..48aa03d 100644 --- a/utest/x3270/test_wait_and_timeout.py +++ b/utest/x3270/test_wait_and_timeout.py @@ -11,18 +11,54 @@ def test_change_timeout(under_test: x3270): assert under_test.timeout == 5 +def test_change_timeout_with_time_string(under_test: x3270): + under_test.change_timeout("2 minutes") + + assert under_test.timeout == 120 + + +def test_change_timeout_with_timer_string(under_test: x3270): + under_test.change_timeout("0:02:00") + + assert under_test.timeout == 120 + + def test_change_wait_time(under_test: x3270): under_test.change_wait_time(2.5) assert under_test.wait == 2.5 +def test_change_wait_time_with_time_string(under_test: x3270): + under_test.change_wait_time("500 millis") + + assert under_test.wait == 0.5 + + +def test_change_wait_time_with_timer_string(under_test: x3270): + under_test.change_wait_time("00:00:00.500") + + assert under_test.wait == 0.5 + + def test_change_wait_time_after_write(under_test: x3270): under_test.change_wait_time_after_write(2.5) assert under_test.wait_write == 2.5 +def test_change_wait_time_after_write_with_time_string(under_test: x3270): + under_test.change_wait_time_after_write("1.5") + + assert under_test.wait_write == 1.5 + + +def test_change_wait_time_after_write_with_timer_string(under_test: x3270): + under_test.change_wait_time_after_write("0:00:01.500") + + assert under_test.wait_write == 1.5 + + def test_wait_field_detected(mocker: MockerFixture, under_test: x3270): mocker.patch("Mainframe3270.py3270.Emulator.wait_for_field") @@ -42,15 +78,23 @@ def test_wait_until_string(mocker: MockerFixture, under_test: x3270): def test_wait_until_string_string_not_found(mocker: MockerFixture, under_test: x3270): mocker.patch("Mainframe3270.py3270.Emulator.string_get", return_value="abc") - with pytest.raises(Exception, match='String "def" not found in 1 seconds'): + with pytest.raises(Exception, match='String "def" not found in 1 second'): under_test.wait_until_string("def", 1) -def test_wait_until_string_not_found_until_timeout( +def test_wait_until_string_with_time_time_string( + mocker: MockerFixture, under_test: x3270 +): + mocker.patch("Mainframe3270.py3270.Emulator.string_get", return_value="abc") + + with pytest.raises(Exception, match='String "def" not found in 500 milliseconds'): + under_test.wait_until_string("def", "500 millis") + + +def test_wait_until_string_with_time_timer_string( mocker: MockerFixture, under_test: x3270 ): mocker.patch("Mainframe3270.py3270.Emulator.string_get", return_value="abc") - mocker.patch("time.ctime", return_value="Sat Feb 12 15:29:51 2022") - with pytest.raises(Exception, match='String "abc" not found in 5 seconds'): - under_test.wait_until_string("abc") + with pytest.raises(Exception, match='String "def" not found in 500 milliseconds'): + under_test.wait_until_string("def", "00:00:00.500") From 2562b5bcf75b886416873c4b05cdade0d92b30d8 Mon Sep 17 00:00:00 2001 From: Robin Matz Date: Tue, 19 Jul 2022 22:52:30 +0200 Subject: [PATCH 2/5] Capitalize global variables --- atest/connection.robot | 4 +- atest/mainframe.robot | 171 +++++++++--------- atest/pub400_variables.robot | 84 ++++----- .../custom_keyword_on_import.robot | 17 +- atest/run_on_failure/none_on_import.robot | 14 +- atest/run_on_failure/run_on_failure.robot | 17 +- 6 files changed, 154 insertions(+), 153 deletions(-) diff --git a/atest/connection.robot b/atest/connection.robot index e16ba0e..4c77a99 100644 --- a/atest/connection.robot +++ b/atest/connection.robot @@ -14,12 +14,12 @@ ${TRACE_FILE} ${CURDIR}/x3270.trace *** Test Cases *** Test Connection With Extra Args List ${extra_args} Create List -trace -tracefile ${TRACE_FILE} - Open Connection ${host} extra_args=${extra_args} + Open Connection ${HOST} extra_args=${extra_args} Sleep 0.5 s File Should Exist ${TRACE_FILE} Test Connection With Argfile - Open Connection ${host} extra_args=${ARGFILE} + Open Connection ${HOST} extra_args=${ARGFILE} Sleep 0.5 s File Should Exist ${TRACE_FILE} diff --git a/atest/mainframe.robot b/atest/mainframe.robot index 9be603e..6f9de27 100644 --- a/atest/mainframe.robot +++ b/atest/mainframe.robot @@ -3,7 +3,7 @@ Documentation These tests verify that all keywords are working correctly a ... To run all the tests, you will need to create a user in the https://www.pub400.com/ website, ... this will affect the last test "Test With Login" -Library ../Mainframe3270/ run_on_failure_keyword=None +Library ../Mainframe3270/ Library Dialogs Library OperatingSystem Library String @@ -11,7 +11,6 @@ Resource pub400_variables.robot Suite Setup Open Mainframe Suite Teardown Close Mainframe -Test Teardown Run Keyword If Test Failed Fatal Error *** Test Cases *** @@ -64,7 +63,7 @@ Test With Login *** Keywords *** Open Mainframe - Open Connection ${host} + Open Connection ${HOST} Sleep 3s Close Mainframe @@ -72,63 +71,63 @@ Close Mainframe Sleep 1s Initial Setting - Create Directory ${folder} - Empty Directory ${folder} - set screenshot folder ${folder} + Create Directory ${FOLDER} + Empty Directory ${FOLDER} + set screenshot folder ${FOLDER} Change Wait Time 0.4 Change Wait Time After Write 0.4 Sleep 1s Test Wait Until String - Wait Until String ${welcome_title} timeout=4 + Wait Until String ${WELCOME_TITLE} timeout=4 Test Page Should Contain All Strings - Page Should Contain All Strings ${list_strings} - Page Should Contain All Strings ${list_strings_wrong_case} ignore_case=${True} + Page Should Contain All Strings ${LIST_STRINGS} + Page Should Contain All Strings ${LIST_STRINGS_WRONG_CASE} ignore_case=${True} Test Page Should Contain Any String - Page Should Contain Any String ${list_strings_right_in_the_first} - Page Should Contain Any String ${list_strings_right_in_the_second} - Page Should Contain Any String ${list_strings_right_in_the_third} - Page Should Contain Any String ${list_strings_right_in_the_first_wrong_case} ignore_case=${True} - Page Should Contain Any String ${list_strings_right_in_the_second_wrong_case} ignore_case=${True} - Page Should Contain Any String ${list_strings_right_in_the_third_wrong_case} ignore_case=${True} + Page Should Contain Any String ${LIST_STRINGS_RIGHT_IN_THE_FIRST} + Page Should Contain Any String ${LIST_STRINGS_RIGHT_IN_THE_SECOND} + Page Should Contain Any String ${LIST_STRINGS_RIGHT_IN_THE_THIRD} + Page Should Contain Any String ${LIST_STRINGS_RIGHT_IN_THE_FIRST_WRONG_CASE} ignore_case=${True} + Page Should Contain Any String ${LIST_STRINGS_RIGHT_IN_THE_SECOND_WRONG_CASE} ignore_case=${True} + Page Should Contain Any String ${LIST_STRINGS_RIGHT_IN_THE_THIRD_WRONG_CASE} ignore_case=${True} Test Page Should Contain Match - Page Should Contain Match ${text_match} - Page Should Contain Match ${text_match_wrong_case} ignore_case=${True} + Page Should Contain Match ${TEXT_MATCH} + Page Should Contain Match ${TEXT_MATCH_WRONG_CASE} ignore_case=${True} Test Page Should Contain String X Times - Page Should Contain String X Times ${text_to_count} 2 - Page Should Contain String X Times ${text_to_count_wrong_case} 3 ignore_case=${True} + Page Should Contain String X Times ${TEXT_TO_COUNT} 2 + Page Should Contain String X Times ${TEXT_TO_COUNT_WRONG_CASE} 3 ignore_case=${True} Test Page Should Match Regex - Page Should Match Regex ${valid_regex} + Page Should Match Regex ${VALID_REGEX} Test Page Should Not Match Regex - Page Should Not Match Regex ${invalid_regex} + Page Should Not Match Regex ${INVALID_REGEX} Test Page Should Not Contain All Strings - Page Should Not Contain All Strings ${list_strings_not_existants} - Page Should Not Contain All Strings ${list_strings_not_existants_ignore_case} ignore_case=${True} + Page Should Not Contain All Strings ${LIST_STRINGS_NON_EXISTENT} + Page Should Not Contain All Strings ${LIST_STRINGS_NON_EXITENT_IGNORE_CASE} ignore_case=${True} Test Page Should Not Contain Any String - Page Should Not Contain Any String ${list_strings_right_in_the_first_wrong_case} - Page Should Not Contain Any String ${list_strings_right_in_the_second_wrong_case} - Page Should Not Contain Any String ${list_strings_right_in_the_third_wrong_case} - Page Should Not Contain Any String ${list_strings_not_existants_ignore_case} ignore_case=${True} + Page Should Not Contain Any String ${LIST_STRINGS_RIGHT_IN_THE_FIRST_WRONG_CASE} + Page Should Not Contain Any String ${LIST_STRINGS_RIGHT_IN_THE_SECOND_WRONG_CASE} + Page Should Not Contain Any String ${LIST_STRINGS_RIGHT_IN_THE_THIRD_WRONG_CASE} + Page Should Not Contain Any String ${LIST_STRINGS_NON_EXITENT_IGNORE_CASE} ignore_case=${True} Test Page Should Not Contain Match - Page Should Not Contain Match ${text_not_match} - Page Should Not Contain Match ${text_not_match_wrong_case} ignore_case=${True} + Page Should Not Contain Match ${TEXT_NOT_MATCH} + Page Should Not Contain Match ${TEXT_NOT_MATCH_WRONG_CASE} ignore_case=${True} Test Page Should Not Contain String - Page Should Not Contain String ${welcome_wrong_case} - Page Should Not Contain String ${string_not_existant} ignore_case=${True} + Page Should Not Contain String ${WELCOME_WRONG_CASE} + Page Should Not Contain String ${STRING_NON_EXISTENT} ignore_case=${True} Test Read ${read_text} Read 1 10 48 - Should Be Equal As Strings ${welcome_title} ${read_text} + Should Be Equal As Strings ${WELCOME_TITLE} ${read_text} Test Read All Screen ${screen_content} Read All Screen @@ -137,53 +136,53 @@ Test Read All Screen Should Not Contain ${screen_content} xyz Test Write Bare - Write Bare ${write_text} + Write Bare ${WRITE_TEXT} ${read_text} Read 5 25 4 Take Screenshot - Should Be Equal As Strings ${write_text} ${read_text} + Should Be Equal As Strings ${WRITE_TEXT} ${read_text} Sleep 1s Test Write Bare In Position - Write Bare In Position ${write_text_utf8} 5 30 + Write Bare In Position ${WRITE_TEXT_UTF8} 5 30 ${read_text} Read 5 30 4 Take Screenshot - Should Be Equal As Strings ${write_text_utf8} ${read_text} + Should Be Equal As Strings ${WRITE_TEXT_UTF8} ${read_text} Sleep 1s Test Delete Char Delete Char 5 25 ${read_text} Read 5 25 8 Take Screenshot - Should Be Equal As Strings ${text_after_delete_char} ${read_text} + Should Be Equal As Strings ${TEXT_AFTER_DELETE_CHAR} ${read_text} Sleep 1s Test Delete Field Delete Field ${read_text} Read 5 25 8 Take Screenshot - Should Be Equal As Strings ${text_after_delete_field} ${read_text} + Should Be Equal As Strings ${TEXT_AFTER_DELETE_FIELD} ${read_text} Sleep 1s Test Move Next Field Move Next Field - Write Bare ${write_text} + Write Bare ${WRITE_TEXT} ${read_text} Read 5 25 4 - Should Be Equal As Strings ${text_after_move_next_field} ${read_text} + Should Be Equal As Strings ${TEXT_AFTER_MOVE_NEXT_FIELD} ${read_text} Sleep 1s Test Move Previous Field # Send two Move Previous Field because the first only put the cursor int he beginning of the password field Move Previous Field Move Previous Field - Write Bare ${write_text} + Write Bare ${WRITE_TEXT} ${read_text} Read 5 25 4 - Should Be Equal As Strings ${write_text} ${read_text} + Should Be Equal As Strings ${WRITE_TEXT} ${read_text} Sleep 1s Test Send Enter Wait Field Detected - Page Should Contain String ${welcome} - Page Should Contain String ${welcome_wrong_case} ignore_case=${TRUE} + Page Should Contain String ${WELCOME} + Page Should Contain String ${WELCOME_WRONG_CASE} ignore_case=${TRUE} Delete Field ${user} Get Value From User Write user ${password} Get Value From User Write user password @@ -192,18 +191,18 @@ Test Send Enter write bare ${password} send enter ${value} read 1 33 15 - should be equal as strings ${main_menu} ${value} + should be equal as strings ${MAIN_MENU} ${value} take screenshot Test Send PF write 1 Wait Field Detected take screenshot - Page Should Contain String ${user_task} + Page Should Contain String ${USER_TASK} send PF 12 Wait Field Detected take screenshot - Page Should Contain String ${main_menu} + Page Should Contain String ${MAIN_MENU} write 90 Wait Field Detected take screenshot @@ -212,76 +211,86 @@ Test Send PF Exception Test Read Wait Field Detected ${read_text} Read 1 10 21 - Run Keyword And Expect Error ${welcome_text_expected_error} Should Be Equal As Strings ${welcome_title} + Run Keyword And Expect Error ${WELCOME_TEXT_EXPECTED_ERROR} Should Be Equal As Strings ${WELCOME_TITLE} ... ${read_text} - Run Keyword And Expect Error ${x_axis_exceed_expected_error} Read 4 48 34 - Run Keyword And Expect Error ${x_axis_exceed_expected_error} Read 4 81 1 - Run Keyword And Expect Error ${y_axis_exceed_expected_error} Read 25 48 34 + Run Keyword And Expect Error ${X_AXIS_EXCEEDED_EXPECTED_ERROR} Read 4 48 34 + Run Keyword And Expect Error ${X_AXIS_EXCEEDED_EXPECTED_ERROR} Read 4 81 1 + Run Keyword And Expect Error ${Y_AXIS_EXCEEDED_EXPECTED_ERROR} Read 25 48 34 Exception Test Write In Position - Run Keyword And Expect Error ${x_axis_exceed_expected_error} Write In Position ${write_text} 10 81 - Run Keyword And Expect Error ${y_axis_exceed_expected_error} Write In Position ${write_text} 25 10 + Run Keyword And Expect Error + ... ${X_AXIS_EXCEEDED_EXPECTED_ERROR} + ... Write In Position + ... ${WRITE_TEXT} + ... 10 + ... 81 + Run Keyword And Expect Error + ... ${Y_AXIS_EXCEEDED_EXPECTED_ERROR} + ... Write In Position + ... ${WRITE_TEXT} + ... 25 + ... 10 Exception Test Write Bare In Position - Run Keyword And Expect Error ${x_axis_exceed_expected_error} Write Bare In Position ${write_text} 10 + Run Keyword And Expect Error ${X_AXIS_EXCEEDED_EXPECTED_ERROR} Write Bare In Position ${WRITE_TEXT} 10 ... 81 - Run Keyword And Expect Error ${y_axis_exceed_expected_error} Write Bare In Position ${write_text} 25 + Run Keyword And Expect Error ${Y_AXIS_EXCEEDED_EXPECTED_ERROR} Write Bare In Position ${WRITE_TEXT} 25 ... 10 Exception Test Page Should Contain String - Verify String Not Found Page Should Contain String ${welcome_wrong_case} - Verify String Not Found Page Should Contain String ${string_not_existant} ignore_case=${True} + Verify String Not Found Page Should Contain String ${WELCOME_WRONG_CASE} + Verify String Not Found Page Should Contain String ${STRING_NON_EXISTENT} ignore_case=${True} Exception Test Page Should Contain All Strings - Verify String Not Found In List Page Should Contain All Strings ${list_strings_wrong_case_in_the_first} 1 + Verify String Not Found In List Page Should Contain All Strings ${LIST_STRINGS_WRONG_CASE_IN_THE_FIRST} 1 Verify String Not Found In List ... Page Should Contain All Strings - ... ${list_strings_wrong_case_in_the_second} + ... ${LIST_STRINGS_WRONG_CASE_IN_THE_SECONDS} ... 2 - Verify String Not Found In List Page Should Contain All Strings ${list_strings_wrong_case_in_the_third} 3 - Verify String Not Found In List Page Should Contain All Strings ${list_strings_wrong_in_the_first} 1 + Verify String Not Found In List Page Should Contain All Strings ${LIST_STRINGS_WRONG_CASE_IN_THE_THIRD} 3 + Verify String Not Found In List Page Should Contain All Strings ${LIST_STRINGS_WRONG_IN_THE_FIRST} 1 ... ignore_case=${True} - Verify String Not Found In List Page Should Contain All Strings ${list_strings_wrong_in_the_second} 2 + Verify String Not Found In List Page Should Contain All Strings ${LIST_STRINGS_WRONG_IN_THE_SECOND} 2 ... ignore_case=${True} - Verify String Not Found In List Page Should Contain All Strings ${list_strings_wrong_in_the_third} 3 + Verify String Not Found In List Page Should Contain All Strings ${LIST_STRINGS_WRONG_IN_THE_THIRD} 3 ... ignore_case=${True} Exception Test Page Should Contain Any String - Verify List Not Found Page Should Contain Any String ${list_strings_all_wrong_case} - Verify List Not Found Page Should Contain Any String ${list_strings_not_existants_ignore_case} + Verify List Not Found Page Should Contain Any String ${LIST_STRINGS_ALL_WRONG_CASE} + Verify List Not Found Page Should Contain Any String ${LIST_STRINGS_NON_EXITENT_IGNORE_CASE} ... ignore_case=${True} Exception Test Page Should Contain Match - Verify Pattern Not Found Page Should Contain Match ${text_not_match_wrong_case} - Verify Pattern Not Found Page Should Contain Match ${string_not_existant} ignore_case=${True} + Verify Pattern Not Found Page Should Contain Match ${TEXT_NOT_MATCH_WRONG_CASE} + Verify Pattern Not Found Page Should Contain Match ${STRING_NON_EXISTENT} ignore_case=${True} Exception Test Page Should Contain String X Times - Verify String Does Not Appear X Times Page Should Contain String X Times ${text_to_count} 1 2 - Verify String Does Not Appear X Times Page Should Contain String X Times ${text_to_count_wrong_case} 1 + Verify String Does Not Appear X Times Page Should Contain String X Times ${TEXT_TO_COUNT} 1 2 + Verify String Does Not Appear X Times Page Should Contain String X Times ${TEXT_TO_COUNT_WRONG_CASE} 1 ... 3 ignore_case=${True} Exception Test Page Should Match Regex - Verify Pattern Not Found Page Should Match Regex ${invalid_regex} + Verify Pattern Not Found Page Should Match Regex ${INVALID_REGEX} Exception Test Page Should Not Contain String - Verify String Found Page Should Not Contain String ${welcome} - Verify String Found Page Should Not Contain String ${welcome_wrong_case} ignore_case=${True} + Verify String Found Page Should Not Contain String ${WELCOME} + Verify String Found Page Should Not Contain String ${WELCOME_WRONG_CASE} ignore_case=${True} Exception Test Page Should Not Contain All Strings - Verify List Found Page Should Not Contain All Strings ${list_strings_right_in_the_first} 1 - Verify List Found Page Should Not Contain All Strings ${list_strings_right_in_the_second} 2 - Verify List Found Page Should Not Contain All Strings ${list_strings_right_in_the_third} 3 + Verify List Found Page Should Not Contain All Strings ${LIST_STRINGS_RIGHT_IN_THE_FIRST} 1 + Verify List Found Page Should Not Contain All Strings ${LIST_STRINGS_RIGHT_IN_THE_SECOND} 2 + Verify List Found Page Should Not Contain All Strings ${LIST_STRINGS_RIGHT_IN_THE_THIRD} 3 Exception Test Page Should Not Contain Any String - Verify List Found Page Should Not Contain Any String ${list_strings_right_in_the_first} 1 - Verify List Found Page Should Not Contain Any String ${list_strings_right_in_the_second} 2 - Verify List Found Page Should Not Contain Any String ${list_strings_right_in_the_third} 3 + Verify List Found Page Should Not Contain Any String ${LIST_STRINGS_RIGHT_IN_THE_FIRST} 1 + Verify List Found Page Should Not Contain Any String ${LIST_STRINGS_RIGHT_IN_THE_SECOND} 2 + Verify List Found Page Should Not Contain Any String ${LIST_STRINGS_RIGHT_IN_THE_THIRD} 3 Exception Test Wait Until String - Verify Wait Until String Wait Until String ${string_not_existant} + Verify Wait Until String Wait Until String ${STRING_NON_EXISTENT} Exception Test Wait Until String With Timeout - Verify Wait Until String With Timeout Wait Until String ${string_not_existant} timeout=2 + Verify Wait Until String With Timeout Wait Until String ${STRING_NON_EXISTENT} timeout=2 Verify String Not Found [Arguments] ${keyword} ${string} ${ignore_case}=${False} @@ -314,7 +323,7 @@ Verify String Does Not Appear X Times [Arguments] ${keyword} ${string} ${wrong_number_of_times} ${right_number_of_times} ${ignore_case}=${False} ${expected_error} Set Variable ... The string "${string}" was not found "${wrong_number_of_times}" times, it appears "${right_number_of_times}" times - Run Keyword And Expect Error ${expected_error} ${keyword} ${text_to_count} 1 + Run Keyword And Expect Error ${expected_error} ${keyword} ${TEXT_TO_COUNT} 1 ... ignore_case=${ignore_case} Verify String Found diff --git a/atest/pub400_variables.robot b/atest/pub400_variables.robot index 582e84e..7e552c8 100644 --- a/atest/pub400_variables.robot +++ b/atest/pub400_variables.robot @@ -1,53 +1,53 @@ *** Variables *** -${host} pub400.com -${folder} ${CURDIR}${/}screenshots +${HOST} pub400.com +${FOLDER} ${CURDIR}${/}screenshots # Text to write -${write_text} TEST -${write_text_utf8} _ëçá +${WRITE_TEXT} TEST +${WRITE_TEXT_UTF8} _ëçá # Texts in the Mainframe -${welcome} Welcome to PUB400.COM -${welcome_title} Welcome to PUB400.COM * your public IBM i server -${main_menu} IBM i Main Menu -${user_task} User Tasks -${text_match} *PUB???.COM* -${text_to_count} PUB400 -${text_not_match} *PUB???400.COM* +${WELCOME} Welcome to PUB400.COM +${WELCOME_TITLE} Welcome to PUB400.COM * your public IBM i server +${MAIN_MENU} IBM i Main Menu +${USER_TASK} User Tasks +${TEXT_MATCH} *PUB???.COM* +${TEXT_TO_COUNT} PUB400 +${TEXT_NOT_MATCH} *PUB???400.COM* # Texts after write -${text_after_delete_char} EST _ëçá -${text_after_delete_field} ${SPACE * 8} -${text_after_move_next_field} ${SPACE * 4} +${TEXT_AFTER_DELETE_CHAR} EST _ëçá +${TEXT_AFTER_DELETE_FIELD} ${SPACE * 8} +${TEXT_AFTER_MOVE_NEXT_FIELD} ${SPACE * 4} # Texts in the Mainframe with wrong case -${welcome_title_wrong_case} WELCOME TO PUB400.COM * YOUR PUBLIC IBM I SERVER -${welcome_wrong_case} WELCOME TO PUB400.COM -${text_match_wrong_case} *pub???.com* -${text_to_count_wrong_case} pub400 -${text_not_match_wrong_case} *pub???400.com* +${WELCOME_TITLE_WRONG_CASE} WELCOME TO PUB400.COM * YOUR PUBLIC IBM I SERVER +${WELCOME_WRONG_CASE} WELCOME TO PUB400.COM +${TEXT_MATCH_WRONG_CASE} *pub???.com* +${TEXT_TO_COUNT_WRONG_CASE} pub400 +${TEXT_NOT_MATCH_WRONG_CASE} *pub???400.com* # Regex -${valid_regex} PUB\\d{3} -${invalid_regex} PUB\\d{4} +${VALID_REGEX} PUB\\d{3} +${INVALID_REGEX} PUB\\d{4} # List strings -@{list_strings} Server name Subsystem Display name -@{list_strings_right_in_the_first} Server name WRONGSTRING WRONGSTRING -@{list_strings_right_in_the_second} WRONGSTRING Subsystem WRONGSTRING -@{list_strings_right_in_the_third} WRONGSTRING WRONGSTRING Display name -@{list_strings_not_existants} SERVER NAME SUBSYSTEM DISPLAY NAME +@{LIST_STRINGS} Server name Subsystem Display name +@{LIST_STRINGS_RIGHT_IN_THE_FIRST} Server name WRONGSTRING WRONGSTRING +@{LIST_STRINGS_RIGHT_IN_THE_SECOND} WRONGSTRING Subsystem WRONGSTRING +@{LIST_STRINGS_RIGHT_IN_THE_THIRD} WRONGSTRING WRONGSTRING Display name +@{LIST_STRINGS_NON_EXISTENT} SERVER NAME SUBSYSTEM DISPLAY NAME # List strings wrong case -@{list_strings_wrong_case} SERVER NAME SUBSYSTEM DISPLAY NAME -@{list_strings_right_in_the_first_wrong_case} SERVER NAME WRONGSTRING WRONGSTRING -@{list_strings_right_in_the_second_wrong_case} WRONGSTRING SUBSYSTEM WRONGSTRING -@{list_strings_right_in_the_third_wrong_case} WRONGSTRING WRONGSTRING DISPLAY NAME -@{list_strings_not_existants_ignore_case} WRONGSTRING WRONGSTRING WRONGSTRING +@{LIST_STRINGS_WRONG_CASE} SERVER NAME SUBSYSTEM DISPLAY NAME +@{LIST_STRINGS_RIGHT_IN_THE_FIRST_WRONG_CASE} SERVER NAME WRONGSTRING WRONGSTRING +@{LIST_STRINGS_RIGHT_IN_THE_SECOND_WRONG_CASE} WRONGSTRING SUBSYSTEM WRONGSTRING +@{LIST_STRINGS_RIGHT_IN_THE_THIRD_WRONG_CASE} WRONGSTRING WRONGSTRING DISPLAY NAME +@{LIST_STRINGS_NON_EXITENT_IGNORE_CASE} WRONGSTRING WRONGSTRING WRONGSTRING # Text not existent in mainframe -${string_not_existant} WRONGSTRING +${STRING_NON_EXISTENT} WRONGSTRING # Expected errors -${welcome_text_expected_error} ${welcome_title} != ${welcome} -${x_axis_exceed_expected_error} You have exceeded the x-axis limit of the mainframe screen -${y_axis_exceed_expected_error} You have exceeded the y-axis limit of the mainframe screen +${WELCOME_TEXT_EXPECTED_ERROR} ${WELCOME_TITLE} != ${WELCOME} +${X_AXIS_EXCEEDED_EXPECTED_ERROR} You have exceeded the x-axis limit of the mainframe screen +${Y_AXIS_EXCEEDED_EXPECTED_ERROR} You have exceeded the y-axis limit of the mainframe screen # list of wrong strings -@{list_strings_wrong_case_in_the_first} SERVER NAME Subsystem Display name -@{list_strings_wrong_case_in_the_second} Server name SUBSYSTEM Display name -@{list_strings_wrong_case_in_the_third} Server name Subsystem DISPLAY NAME -@{list_strings_wrong_in_the_first} WRONGSTRING Subsystem Display name -@{list_strings_wrong_in_the_second} Server name WRONGSTRING Display name -@{list_strings_wrong_in_the_third} Server name Subsystem WRONGSTRING -@{list_strings_all_wrong_case} SERVER NAME SUBSYSTEM DISPLAY NAME +@{LIST_STRINGS_WRONG_CASE_IN_THE_FIRST} SERVER NAME Subsystem Display name +@{LIST_STRINGS_WRONG_CASE_IN_THE_SECONDS} Server name SUBSYSTEM Display name +@{LIST_STRINGS_WRONG_CASE_IN_THE_THIRD} Server name Subsystem DISPLAY NAME +@{LIST_STRINGS_WRONG_IN_THE_FIRST} WRONGSTRING Subsystem Display name +@{LIST_STRINGS_WRONG_IN_THE_SECOND} Server name WRONGSTRING Display name +@{LIST_STRINGS_WRONG_IN_THE_THIRD} Server name Subsystem WRONGSTRING +@{LIST_STRINGS_ALL_WRONG_CASE} SERVER NAME SUBSYSTEM DISPLAY NAME diff --git a/atest/run_on_failure/custom_keyword_on_import.robot b/atest/run_on_failure/custom_keyword_on_import.robot index c35e8e7..9e85315 100644 --- a/atest/run_on_failure/custom_keyword_on_import.robot +++ b/atest/run_on_failure/custom_keyword_on_import.robot @@ -1,36 +1,35 @@ *** Settings *** Library ../../Mainframe3270/ run_on_failure_keyword=Custom Run On Failure Keyword Library OperatingSystem +Resource ../pub400_variables.robot Suite Setup Open Mainframe Suite Teardown Close Mainframe *** Variables *** -${custom_file} ${CURDIR}${/}output.txt -${host} pub400.com -${not_found_string} 4%$3123 +${CUSTOM_FILE} ${CURDIR}${/}output.txt *** Test Cases *** Should Run Custom Keyword Cause Error - File Should Exist ${custom_file} - [Teardown] Remove File ${custom_file} + File Should Exist ${CUSTOM_FILE} + [Teardown] Remove File ${CUSTOM_FILE} *** Keywords *** Open Mainframe - Open Connection ${host} + Open Connection ${HOST} Sleep 3 seconds Cause Error Run Keyword And Expect Error - ... The string "${not_found_string}" was not found - ... Page Should Contain String ${not_found_string} + ... The string "${STRING_NON_EXISTENT}" was not found + ... Page Should Contain String ${STRING_NON_EXISTENT} Custom Run On Failure Keyword - Create File ${custom_file} An error ocurred + Create File ${CUSTOM_FILE} An error ocurred Close Mainframe Close Connection diff --git a/atest/run_on_failure/none_on_import.robot b/atest/run_on_failure/none_on_import.robot index 06c5fdc..891b082 100644 --- a/atest/run_on_failure/none_on_import.robot +++ b/atest/run_on_failure/none_on_import.robot @@ -1,33 +1,27 @@ *** Settings *** Library ../../Mainframe3270/ run_on_failure_keyword=None Library OperatingSystem +Resource ../pub400_variables.robot Suite Setup Open Mainframe Suite Teardown Close Mainframe -*** Variables *** -${custom_file} ${CURDIR}${/}output.txt -${host} pub400.com -${not_found_string} 4%$3123 - - *** Test Cases *** None Should Run On Failure - Register Run On Failure Keyword None Cause Error File Should Not Exist ${CURDIR}/*.html *** Keywords *** Open Mainframe - Open Connection ${host} + Open Connection ${HOST} Sleep 3 seconds Cause Error Run Keyword And Expect Error - ... The string "${not_found_string}" was not found - ... Page Should Contain String ${not_found_string} + ... The string "${STRING_NON_EXISTENT}" was not found + ... Page Should Contain String ${STRING_NON_EXISTENT} Close Mainframe Close Connection diff --git a/atest/run_on_failure/run_on_failure.robot b/atest/run_on_failure/run_on_failure.robot index 98a31a8..62d4517 100644 --- a/atest/run_on_failure/run_on_failure.robot +++ b/atest/run_on_failure/run_on_failure.robot @@ -1,15 +1,14 @@ *** Settings *** Library ../../Mainframe3270/ img_folder=${CURDIR} Library OperatingSystem +Resource ../pub400_variables.robot Suite Setup Open Mainframe Suite Teardown Close Mainframe *** Variables *** -${custom_file} ${CURDIR}${/}output.txt -${host} pub400.com -${not_found_string} 4%$3123 +${CUSTOM_FILE} ${CURDIR}${/}output.txt *** Test Cases *** @@ -21,8 +20,8 @@ Takes Screenshot On Failure Register Custom Keyword To Run On Failure Register Run On Failure Keyword Custom Run On Failure Keyword Cause Error - File Should Exist ${custom_file} - [Teardown] Remove File ${custom_file} + File Should Exist ${CUSTOM_FILE} + [Teardown] Remove File ${CUSTOM_FILE} Register None To Run On Failure Register Run On Failure Keyword None @@ -32,16 +31,16 @@ Register None To Run On Failure *** Keywords *** Open Mainframe - Open Connection ${host} + Open Connection ${HOST} Sleep 3 seconds Cause Error Run Keyword And Expect Error - ... The string "${not_found_string}" was not found - ... Page Should Contain String ${not_found_string} + ... The string "${STRING_NON_EXISTENT}" was not found + ... Page Should Contain String ${STRING_NON_EXISTENT} Custom Run On Failure Keyword - Create File ${custom_file} An error ocurred + Create File ${CUSTOM_FILE} An error ocurred Close Mainframe Close Connection From 816b65f233f6f590902446758234be85a13a3193 Mon Sep 17 00:00:00 2001 From: Robin Matz Date: Wed, 20 Jul 2022 07:38:58 +0200 Subject: [PATCH 3/5] Split test cases --- atest/mainframe.robot | 262 +++++++++++++++++------------------------- 1 file changed, 107 insertions(+), 155 deletions(-) diff --git a/atest/mainframe.robot b/atest/mainframe.robot index 6f9de27..98ceda4 100644 --- a/atest/mainframe.robot +++ b/atest/mainframe.robot @@ -9,74 +9,94 @@ Library OperatingSystem Library String Resource pub400_variables.robot -Suite Setup Open Mainframe -Suite Teardown Close Mainframe +Suite Setup Suite Setup +Suite Teardown Suite Teardown *** Test Cases *** -Exception Test - [Setup] Initial Setting - Exception Test Read - Exception Test Write In Position - Exception Test Write Bare In Position - Exception Test Page Should Contain String - Exception Test Page Should Contain All Strings - Exception Test Page Should Contain Any String - Exception Test Page Should Contain Match - Exception Test Page Should Contain String X Times - Exception Test Page Should Match Regex - Exception Test Page Should Not Contain String - Exception Test Page Should Not Contain All Strings - Exception Test Page Should Not Contain Any String - Exception Test Wait Until String - Exception Test Wait Until String With Timeout - -Test Without Login - [Setup] Initial Setting +Exception Test Read Wait Field Detected - Test Wait Until String - take screenshot - Test Page Should Contain All Strings - Test Page Should Contain Any String - Test Page Should Contain Match - Test Page Should Contain String X Times - Test Page Should Match Regex - Test Page Should Not Match Regex - Test Page Should Not Contain All Strings - Test Page Should Not Contain Any String - Test Page Should Not Contain Match - Test Page Should Not Contain String - Test Read - Test Read All Screen - Test Write Bare - Test Write Bare In Position - Test Delete Char - Test Delete Field - Test Move Next Field - Test Move Previous Field - -Test With Login - [Tags] no-ci - Test Send Enter - Test Send PF + ${read_text} Read 1 10 21 + Run Keyword And Expect Error ${WELCOME_TEXT_EXPECTED_ERROR} Should Be Equal As Strings ${WELCOME_TITLE} + ... ${read_text} + Run Keyword And Expect Error ${X_AXIS_EXCEEDED_EXPECTED_ERROR} Read 4 48 34 + Run Keyword And Expect Error ${X_AXIS_EXCEEDED_EXPECTED_ERROR} Read 4 81 1 + Run Keyword And Expect Error ${Y_AXIS_EXCEEDED_EXPECTED_ERROR} Read 25 48 34 +Exception Test Write In Position + Run Keyword And Expect Error + ... ${X_AXIS_EXCEEDED_EXPECTED_ERROR} + ... Write In Position + ... ${WRITE_TEXT} + ... 10 + ... 81 + Run Keyword And Expect Error + ... ${Y_AXIS_EXCEEDED_EXPECTED_ERROR} + ... Write In Position + ... ${WRITE_TEXT} + ... 25 + ... 10 -*** Keywords *** -Open Mainframe - Open Connection ${HOST} - Sleep 3s +Exception Test Write Bare In Position + Run Keyword And Expect Error ${X_AXIS_EXCEEDED_EXPECTED_ERROR} Write Bare In Position ${WRITE_TEXT} 10 + ... 81 + Run Keyword And Expect Error ${Y_AXIS_EXCEEDED_EXPECTED_ERROR} Write Bare In Position ${WRITE_TEXT} 25 + ... 10 -Close Mainframe - Close Connection - Sleep 1s +Exception Test Page Should Contain String + Verify String Not Found Page Should Contain String ${WELCOME_WRONG_CASE} + Verify String Not Found Page Should Contain String ${STRING_NON_EXISTENT} ignore_case=${True} -Initial Setting - Create Directory ${FOLDER} - Empty Directory ${FOLDER} - set screenshot folder ${FOLDER} - Change Wait Time 0.4 - Change Wait Time After Write 0.4 - Sleep 1s +Exception Test Page Should Contain All Strings + Verify String Not Found In List Page Should Contain All Strings ${LIST_STRINGS_WRONG_CASE_IN_THE_FIRST} 1 + Verify String Not Found In List + ... Page Should Contain All Strings + ... ${LIST_STRINGS_WRONG_CASE_IN_THE_SECONDS} + ... 2 + Verify String Not Found In List Page Should Contain All Strings ${LIST_STRINGS_WRONG_CASE_IN_THE_THIRD} 3 + Verify String Not Found In List Page Should Contain All Strings ${LIST_STRINGS_WRONG_IN_THE_FIRST} 1 + ... ignore_case=${True} + Verify String Not Found In List Page Should Contain All Strings ${LIST_STRINGS_WRONG_IN_THE_SECOND} 2 + ... ignore_case=${True} + Verify String Not Found In List Page Should Contain All Strings ${LIST_STRINGS_WRONG_IN_THE_THIRD} 3 + ... ignore_case=${True} + +Exception Test Page Should Contain Any String + Verify List Not Found Page Should Contain Any String ${LIST_STRINGS_ALL_WRONG_CASE} + Verify List Not Found Page Should Contain Any String ${LIST_STRINGS_NON_EXITENT_IGNORE_CASE} + ... ignore_case=${True} + +Exception Test Page Should Contain Match + Verify Pattern Not Found Page Should Contain Match ${TEXT_NOT_MATCH_WRONG_CASE} + Verify Pattern Not Found Page Should Contain Match ${STRING_NON_EXISTENT} ignore_case=${True} + +Exception Test Page Should Contain String X Times + Verify String Does Not Appear X Times Page Should Contain String X Times ${TEXT_TO_COUNT} 1 2 + Verify String Does Not Appear X Times Page Should Contain String X Times ${TEXT_TO_COUNT_WRONG_CASE} 1 + ... 4 ignore_case=${True} + +Exception Test Page Should Match Regex + Verify Pattern Not Found Page Should Match Regex ${INVALID_REGEX} + +Exception Test Page Should Not Contain String + Verify String Found Page Should Not Contain String ${WELCOME} + Verify String Found Page Should Not Contain String ${WELCOME_WRONG_CASE} ignore_case=${True} + +Exception Test Page Should Not Contain All Strings + Verify List Found Page Should Not Contain All Strings ${LIST_STRINGS_RIGHT_IN_THE_FIRST} 1 + Verify List Found Page Should Not Contain All Strings ${LIST_STRINGS_RIGHT_IN_THE_SECOND} 2 + Verify List Found Page Should Not Contain All Strings ${LIST_STRINGS_RIGHT_IN_THE_THIRD} 3 + +Exception Test Page Should Not Contain Any String + Verify List Found Page Should Not Contain Any String ${LIST_STRINGS_RIGHT_IN_THE_FIRST} 1 + Verify List Found Page Should Not Contain Any String ${LIST_STRINGS_RIGHT_IN_THE_SECOND} 2 + Verify List Found Page Should Not Contain Any String ${LIST_STRINGS_RIGHT_IN_THE_THIRD} 3 + +Exception Test Wait Until String + Verify Wait Until String Wait Until String ${STRING_NON_EXISTENT} + +Exception Test Wait Until String With Timeout + Verify Wait Until String With Timeout Wait Until String ${STRING_NON_EXISTENT} timeout=2 Test Wait Until String Wait Until String ${WELCOME_TITLE} timeout=4 @@ -99,7 +119,7 @@ Test Page Should Contain Match Test Page Should Contain String X Times Page Should Contain String X Times ${TEXT_TO_COUNT} 2 - Page Should Contain String X Times ${TEXT_TO_COUNT_WRONG_CASE} 3 ignore_case=${True} + Page Should Contain String X Times ${TEXT_TO_COUNT_WRONG_CASE} 4 ignore_case=${True} Test Page Should Match Regex Page Should Match Regex ${VALID_REGEX} @@ -180,117 +200,49 @@ Test Move Previous Field Sleep 1s Test Send Enter + [Tags] no-ci Wait Field Detected Page Should Contain String ${WELCOME} Page Should Contain String ${WELCOME_WRONG_CASE} ignore_case=${TRUE} Delete Field ${user} Get Value From User Write user ${password} Get Value From User Write user password - write bare in position ${user} 5 25 + Write Bare In Position ${user} 5 25 Move Next Field - write bare ${password} - send enter - ${value} read 1 33 15 - should be equal as strings ${MAIN_MENU} ${value} - take screenshot + Write Bare ${password} + Send Enter + ${value} Read 1 33 15 + Should Be Equal As Strings ${MAIN_MENU} ${value} + Take Screenshot Test Send PF - write 1 + [Tags] no-ci + Write 1 Wait Field Detected - take screenshot + Take Screenshot Page Should Contain String ${USER_TASK} - send PF 12 + Send PF 12 Wait Field Detected - take screenshot + Take Screenshot Page Should Contain String ${MAIN_MENU} - write 90 - Wait Field Detected - take screenshot - # ------- - -Exception Test Read + Write 90 Wait Field Detected - ${read_text} Read 1 10 21 - Run Keyword And Expect Error ${WELCOME_TEXT_EXPECTED_ERROR} Should Be Equal As Strings ${WELCOME_TITLE} - ... ${read_text} - Run Keyword And Expect Error ${X_AXIS_EXCEEDED_EXPECTED_ERROR} Read 4 48 34 - Run Keyword And Expect Error ${X_AXIS_EXCEEDED_EXPECTED_ERROR} Read 4 81 1 - Run Keyword And Expect Error ${Y_AXIS_EXCEEDED_EXPECTED_ERROR} Read 25 48 34 - -Exception Test Write In Position - Run Keyword And Expect Error - ... ${X_AXIS_EXCEEDED_EXPECTED_ERROR} - ... Write In Position - ... ${WRITE_TEXT} - ... 10 - ... 81 - Run Keyword And Expect Error - ... ${Y_AXIS_EXCEEDED_EXPECTED_ERROR} - ... Write In Position - ... ${WRITE_TEXT} - ... 25 - ... 10 - -Exception Test Write Bare In Position - Run Keyword And Expect Error ${X_AXIS_EXCEEDED_EXPECTED_ERROR} Write Bare In Position ${WRITE_TEXT} 10 - ... 81 - Run Keyword And Expect Error ${Y_AXIS_EXCEEDED_EXPECTED_ERROR} Write Bare In Position ${WRITE_TEXT} 25 - ... 10 - -Exception Test Page Should Contain String - Verify String Not Found Page Should Contain String ${WELCOME_WRONG_CASE} - Verify String Not Found Page Should Contain String ${STRING_NON_EXISTENT} ignore_case=${True} - -Exception Test Page Should Contain All Strings - Verify String Not Found In List Page Should Contain All Strings ${LIST_STRINGS_WRONG_CASE_IN_THE_FIRST} 1 - Verify String Not Found In List - ... Page Should Contain All Strings - ... ${LIST_STRINGS_WRONG_CASE_IN_THE_SECONDS} - ... 2 - Verify String Not Found In List Page Should Contain All Strings ${LIST_STRINGS_WRONG_CASE_IN_THE_THIRD} 3 - Verify String Not Found In List Page Should Contain All Strings ${LIST_STRINGS_WRONG_IN_THE_FIRST} 1 - ... ignore_case=${True} - Verify String Not Found In List Page Should Contain All Strings ${LIST_STRINGS_WRONG_IN_THE_SECOND} 2 - ... ignore_case=${True} - Verify String Not Found In List Page Should Contain All Strings ${LIST_STRINGS_WRONG_IN_THE_THIRD} 3 - ... ignore_case=${True} - -Exception Test Page Should Contain Any String - Verify List Not Found Page Should Contain Any String ${LIST_STRINGS_ALL_WRONG_CASE} - Verify List Not Found Page Should Contain Any String ${LIST_STRINGS_NON_EXITENT_IGNORE_CASE} - ... ignore_case=${True} - -Exception Test Page Should Contain Match - Verify Pattern Not Found Page Should Contain Match ${TEXT_NOT_MATCH_WRONG_CASE} - Verify Pattern Not Found Page Should Contain Match ${STRING_NON_EXISTENT} ignore_case=${True} - -Exception Test Page Should Contain String X Times - Verify String Does Not Appear X Times Page Should Contain String X Times ${TEXT_TO_COUNT} 1 2 - Verify String Does Not Appear X Times Page Should Contain String X Times ${TEXT_TO_COUNT_WRONG_CASE} 1 - ... 3 ignore_case=${True} - -Exception Test Page Should Match Regex - Verify Pattern Not Found Page Should Match Regex ${INVALID_REGEX} - -Exception Test Page Should Not Contain String - Verify String Found Page Should Not Contain String ${WELCOME} - Verify String Found Page Should Not Contain String ${WELCOME_WRONG_CASE} ignore_case=${True} - -Exception Test Page Should Not Contain All Strings - Verify List Found Page Should Not Contain All Strings ${LIST_STRINGS_RIGHT_IN_THE_FIRST} 1 - Verify List Found Page Should Not Contain All Strings ${LIST_STRINGS_RIGHT_IN_THE_SECOND} 2 - Verify List Found Page Should Not Contain All Strings ${LIST_STRINGS_RIGHT_IN_THE_THIRD} 3 + Take Screenshot -Exception Test Page Should Not Contain Any String - Verify List Found Page Should Not Contain Any String ${LIST_STRINGS_RIGHT_IN_THE_FIRST} 1 - Verify List Found Page Should Not Contain Any String ${LIST_STRINGS_RIGHT_IN_THE_SECOND} 2 - Verify List Found Page Should Not Contain Any String ${LIST_STRINGS_RIGHT_IN_THE_THIRD} 3 -Exception Test Wait Until String - Verify Wait Until String Wait Until String ${STRING_NON_EXISTENT} +*** Keywords *** +Suite Setup + Open Connection ${HOST} + Create Directory ${FOLDER} + Empty Directory ${FOLDER} + Set Screenshot Folder ${FOLDER} + Change Wait Time 0.4 + Change Wait Time After Write 0.4 + Sleep 3s -Exception Test Wait Until String With Timeout - Verify Wait Until String With Timeout Wait Until String ${STRING_NON_EXISTENT} timeout=2 +Suite Teardown + Close Connection + Sleep 1s Verify String Not Found [Arguments] ${keyword} ${string} ${ignore_case}=${False} From 3300215570f12309d4014b6c5c146e33e000e078 Mon Sep 17 00:00:00 2001 From: Robin Matz Date: Wed, 20 Jul 2022 20:52:23 +0200 Subject: [PATCH 4/5] Consistent use of f-strings for log and error messages --- Mainframe3270/x3270.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/Mainframe3270/x3270.py b/Mainframe3270/x3270.py index 4770881..a4efbb4 100644 --- a/Mainframe3270/x3270.py +++ b/Mainframe3270/x3270.py @@ -309,7 +309,7 @@ def send_PF(self, PF: str) -> None: Example: | Send PF | 3 | """ - self.mf.exec_command(("PF(" + PF + ")").encode("utf-8")) + self.mf.exec_command(("PF({0})").format(PF).encode("utf-8")) time.sleep(self.wait) @keyword("Write") @@ -423,7 +423,7 @@ def page_should_contain_string( | Page Should Contain String | someTHING | ignore_case=True | | Page Should Contain String | something | error_message=New error message | """ - message = 'The string "' + txt + '" was not found' + message = f'The string "{txt}" was not found' if error_message: message = error_message if ignore_case: @@ -431,7 +431,7 @@ def page_should_contain_string( result = self._search_string(txt, ignore_case) if not result: raise Exception(message) - logger.info('The string "' + txt + '" was found') + logger.info(f'The string "{txt}" was found') @keyword("Page Should Not Contain String") def page_should_not_contain_string( @@ -448,7 +448,7 @@ def page_should_not_contain_string( | Page Should Not Contain String | someTHING | ignore_case=True | | Page Should Not Contain String | something | error_message=New error message | """ - message = 'The string "' + txt + '" was found' + message = f'The string "{txt}" was found' if error_message: message = error_message if ignore_case: @@ -475,7 +475,7 @@ def page_should_contain_any_string( | Page Should Contain Any String | ${list_of_string} | ignore_case=True | | Page Should Contain Any String | ${list_of_string} | error_message=New error message | """ - message = 'The strings "' + str(list_string) + '" were not found' + message = f'The strings "{list_string}" were not found' if error_message: message = error_message if ignore_case: @@ -558,7 +558,7 @@ def page_should_not_contain_all_strings( result = self._search_string(string, ignore_case) if result: if message is None: - message = 'The string "' + string + '" was found' + message = f'The string "{string}" was found' raise Exception(message) @keyword("Page Should Contain String X Times") @@ -591,7 +591,7 @@ def page_should_contain_string_x_times( if message is None: message = f'The string "{txt}" was not found "{number}" times, it appears "{number_of_times}" times' raise Exception(message) - logger.info('The string "' + txt + '" was found "' + str(number) + '" times') + logger.info(f'The string "{txt}" was found "{number}" times') @keyword("Page Should Match Regex") def page_should_match_regex(self, regex_pattern: str) -> None: @@ -605,7 +605,7 @@ def page_should_match_regex(self, regex_pattern: str) -> None: """ page_text = self._read_all_screen() if not re.findall(regex_pattern, page_text, re.MULTILINE): - raise Exception('No matches found for "' + regex_pattern + '" pattern') + raise Exception(f'No matches found for "{regex_pattern}" pattern') @keyword("Page Should Not Match Regex") def page_should_not_match_regex(self, regex_pattern: str) -> None: @@ -619,9 +619,7 @@ def page_should_not_match_regex(self, regex_pattern: str) -> None: """ page_text = self._read_all_screen() if re.findall(regex_pattern, page_text, re.MULTILINE): - raise Exception( - 'There are matches found for "' + regex_pattern + '" pattern' - ) + raise Exception(f'There are matches found for "{regex_pattern}" pattern') @keyword("Page Should Contain Match") def page_should_contain_match( @@ -655,7 +653,7 @@ def page_should_contain_match( result = matcher.match(all_screen) if not result: if message is None: - message = 'No matches found for "' + txt + '" pattern' + message = f'No matches found for "{txt}" pattern' raise Exception(message) @keyword("Page Should Not Contain Match") @@ -690,7 +688,7 @@ def page_should_not_contain_match( result = matcher.match(all_screen) if result: if message is None: - message = 'There are matches found for "' + txt + '" pattern' + message = f'There are matches found for "{txt}" pattern' raise Exception(message) def _read_all_screen(self) -> str: @@ -713,11 +711,11 @@ def _compare_all_list_with_screen_text( result = self._search_string(string, ignore_case) if not should_match and result: if message is None: - message = 'The string "' + string + '" was found' + message = f'The string "{string}" was found' raise Exception(message) elif should_match and not result: if message is None: - message = 'The string "' + string + '" was not found' + message = f'The string "{string}" was not found' raise Exception(message) @staticmethod From 0630d4073c7582cfbe7aa25fd25c93815476097c Mon Sep 17 00:00:00 2001 From: Robin Matz Date: Wed, 20 Jul 2022 21:09:55 +0200 Subject: [PATCH 5/5] fail-fast: false --- .github/workflows/run-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 50fdc3d..59de5b7 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -12,6 +12,7 @@ jobs: matrix: python-version: [3.7, 3.10.0] os: [ubuntu-latest, windows-latest] + fail-fast: false steps: - name: Checkout repository