diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fc198d..9fe3a12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,11 +11,49 @@ This document follows the conventions laid out in [Keep a CHANGELOG][]. - Python.Net 3.0 Support -### Fixxed +### Fixed - Converter bugfix for wrong value convert - Tree module refactoring +### Changed + +- Keyword behaviour changed for Element Should Exist and Element Should Not Exist + - Keywords does not throw a xpath not found exception anymore + - Wait Until Keyword Succeeds combination does not work anymore to check if an ui is displaying after amount of time + - Returns now always True or False + - Keyword throws no exception anymore and error msg attribute is removed + +#### Old Syntax +``` +# This would throw a flaui exception and stop test exeuction +Element Should Exist /WRONG/XPATH + +# Does not work anymire because Element Should Exist +Wait Until Keyword Succeeds Element Should Exist //VALID_XPATH +``` + +#### New Syntax +``` +# Returns now False or True and can be verified afterwards +${RESULT} Element Should Exist /WRONG/XPATH + +# Seperate keyword usage fix the old usage style +Wait Until Keyword Succeeds Element Should Be Visible //VALID_XPATH + +# Or to use Wait Until Element Is Visible +Wait Until Element Is Visible //VALID_XPATH + +### Keywords +Element Should Be Visible + [Arguments] ${xpath} + ${RESULT} Element Should Exist ${xpath} + Run Keyword If ${RESULT}==${False} Fail Element does not exists +``` + +- Wait Until Element Is Hidden does not check anymore if element exists + - No xpath not found exception is called anymore to avoid break tests + ## [Release][1.6.6] [1.6.6][1.6.5-1.6.6] - 2021-09-01 ### Added diff --git a/atests/Element.robot b/atests/Element.robot index a26a39c..a271f68 100644 --- a/atests/Element.robot +++ b/atests/Element.robot @@ -27,15 +27,20 @@ Get Name From Element By XPath Should Be Equal Test Label ${TEXT} Element Should Exist - Element Should Exist ${XPATH_ELEMENT} + ${EXISTS} Element Should Exist ${XPATH_ELEMENT} + Should Be Equal ${EXISTS} ${True} + +Element Should Exist Xpath Not Exists + ${EXISTS} Element Should Exist ${XPATH_NOT_EXISTS} + Should Be Equal ${EXISTS} ${False} Element Should Not Exist - Element Should Not Exist ${XPATH_NOT_EXISTS} + ${NOT_EXISTS} Element Should Not Exist ${XPATH_ELEMENT} + Should Be Equal ${NOT_EXISTS} ${False} -Element Should Not Exist Error - ${EXP_ERR_MSG} Format String ${EXP_ERR_MSG_ELEMENT_EXISTS} ${XPATH_ELEMENT} - ${ERR_MSG} Run Keyword And Expect Error * Element Should Not Exist ${XPATH_ELEMENT} - Should Be Equal As Strings ${EXP_ERR_MSG} ${ERR_MSG} +Element Should Not Exist Xpath Not Exists + ${NOT_EXISTS} Element Should Not Exist ${XPATH_NOT_EXISTS} + Should Be Equal ${NOT_EXISTS} ${TRUE} Name Should Be Name Should Be ${EXP_WINDOW_TITLE} ${MAIN_WINDOW} @@ -61,10 +66,6 @@ Is Element Not Enabled ${IS_ENABLED} Is Element Enabled ${XPATH_DISABLED_ELEMENT} Should Be Equal ${IS_ENABLED} ${FALSE} -Is Element Enabled If Not Exists - ${IS_ENABLED} Is Element Enabled ${XPATH_NOT_EXISTS} - Should Be Equal ${IS_ENABLED} ${FALSE} - Is Element Visible ${IS_VISIBLE} Is Element Visible ${XPATH_ELEMENT} Should Be True ${IS_VISIBLE} @@ -73,10 +74,6 @@ Is Element Visible When Element Is Offscreen And Not Visible ${IS_VISIBLE} Is Element Visible ${XPATH_OFFSCREEN_ELEMENT} Should Be Equal ${IS_VISIBLE} ${False} -Is Element Visible When Element Not Exists - ${IS_VISIBLE} Is Element Visible ${XPATH_NOT_EXISTS} - Should Be Equal ${IS_VISIBLE} ${False} - Element Should Be Visible Element Should Be Visible ${XPATH_ELEMENT} diff --git a/atests/ErrorHandling.robot b/atests/ErrorHandling.robot index 3f926ae..f433e88 100644 --- a/atests/ErrorHandling.robot +++ b/atests/ErrorHandling.robot @@ -26,9 +26,7 @@ Drag And Drop FirstElement Drag And Drop ${EXP_ERR_MSG_XPATH_NOT_FOUND} Drag And Drop SecondElement Drag And Drop ${EXP_ERR_MSG_XPATH_NOT_FOUND} /Window ${XPATH_NOT_EXISTS} Double Click Double Click ${EXP_ERR_MSG_XPATH_NOT_FOUND} ${XPATH_NOT_EXISTS} Element Should Be Visible Element Should Be Visible ${EXP_ERR_MSG_XPATH_NOT_FOUND} ${XPATH_NOT_EXISTS} -Element Should Exist Element Should Exist ${EXP_ERR_MSG_XPATH_NOT_FOUND} ${XPATH_NOT_EXISTS} Element Should Not Be Visible Element Should Not Be Visible ${EXP_ERR_MSG_XPATH_NOT_FOUND} ${XPATH_NOT_EXISTS} -Element Should Not Exist Element Should Not Be Visible ${EXP_ERR_MSG_XPATH_NOT_FOUND} ${XPATH_NOT_EXISTS} Expand TreeItem Expand TreeItem ${EXP_ERR_MSG_XPATH_NOT_FOUND} ${XPATH_NOT_EXISTS} No Such Item Focus Focus ${EXP_ERR_MSG_XPATH_NOT_FOUND} ${XPATH_NOT_EXISTS} Get Checkbox State Get Checkbox State ${EXP_ERR_MSG_XPATH_NOT_FOUND} ${XPATH_NOT_EXISTS} @@ -69,7 +67,6 @@ Select TreeItem Select TreeItem ${EXP_ERR_MSG_XPATH_NOT_FOUND Select Visible TreeItem By Name Select Visible TreeItem By Name ${EXP_ERR_MSG_XPATH_NOT_FOUND} ${XPATH_NOT_EXISTS} No Such Item Set Checkbox State Set Checkbox State ${EXP_ERR_MSG_XPATH_NOT_FOUND} ${XPATH_NOT_EXISTS} ${False} Set Text To Textbox Set Text To Textbox ${EXP_ERR_MSG_XPATH_NOT_FOUND} ${XPATH_NOT_EXISTS} ${XPATH_NOT_EXISTS} -Wait Until Element Is Hidden Wait Until Element Is Hidden ${EXP_ERR_MSG_XPATH_NOT_FOUND} ${XPATH_NOT_EXISTS} 10 Wait Until Element Is Visible Wait Until Element Is Visible ${EXP_ERR_MSG_ELEMENT_NOT_VISIBLE} ${XPATH_NOT_EXISTS} 10 *** Keywords *** diff --git a/atests/Window.robot b/atests/Window.robot index 8c1cbf7..7bd1b31 100644 --- a/atests/Window.robot +++ b/atests/Window.robot @@ -13,6 +13,4 @@ Resource util/XPath.robot Close Window Start Application Close Window ${MAIN_WINDOW} - ${EXP_ERR_MSG} Format String ${EXP_ERR_MSG_XPATH_NOT_FOUND} ${MAIN_WINDOW} - ${ERR_MSG} Run Keyword And Expect Error * Element Should Exist ${MAIN_WINDOW} - Should Be Equal As Strings ${EXP_ERR_MSG} ${ERR_MSG} + Wait Until Element Is Hidden ${MAIN_WINDOW} diff --git a/atests/util/Common.robot b/atests/util/Common.robot index 55a608f..0de7b73 100644 --- a/atests/util/Common.robot +++ b/atests/util/Common.robot @@ -9,7 +9,7 @@ Close Window Application [Arguments] ${xpath}=${MAIN_WINDOW} Run Keyword and Ignore Error Close Application Run Keyword and Ignore Error Close Window ${xpath} - Wait Until Keyword Succeeds 5x 100ms Element Should Not Exist ${xpath} + Wait Until Keyword Succeeds 5x 100ms Window Should Be Closed ${xpath} Stop Application [Arguments] ${xpath}=${MAIN_WINDOW} @@ -19,17 +19,27 @@ Start Application [Arguments] ${application}=${TEST_APP} ${xpath}=${MAIN_WINDOW} ${PID} Launch Application ${application} Should Not Be Equal As Integers ${PID} 0 - Wait Until Keyword Succeeds 10x 200ms Element Should Exist ${xpath} + Wait Until Element Is Visible ${xpath} Focus ${xpath} Start Application With Args [Arguments] ${application}=${TEST_APP} ${xpath}=${MAIN_WINDOW} ${arguments}=${EXP_WINDOW_TITLE} ${PID} Launch Application With Args ${application} ${arguments} Should Not Be Equal As Integers ${PID} 0 - Wait Until Keyword Succeeds 10x 200ms Element Should Exist ${xpath} + Wait Until Keyword Succeeds 5x 1s Window Should Be Exist ${xpath} Focus ${xpath} Open Complex Tab ${XPATH_TAB} Set Variable ${MAIN_WINDOW}/Tab ${TAB_ITEM_LIST_CONTROLS} Set Variable Complex Controls Select Tab Item By Name ${XPATH_TAB} ${TAB_ITEM_LIST_CONTROLS} + +Window Should Be Exist + [Arguments] ${xpath} + ${RESULT} Element Should Exist ${xpath} + Run Keyword If ${RESULT}==${False} Fail Element does not exists + +Window Should Be Closed + [Arguments] ${xpath} + ${RESULT} Element Should Not Exist ${xpath} + Run Keyword If ${RESULT}==${False} Fail Element exists diff --git a/src/FlaUILibrary/flaui/module/element.py b/src/FlaUILibrary/flaui/module/element.py index 3dbe3e0..94f99ae 100644 --- a/src/FlaUILibrary/flaui/module/element.py +++ b/src/FlaUILibrary/flaui/module/element.py @@ -31,6 +31,7 @@ class Action(Enum): IS_ELEMENT_ENABLED = "IS_ELEMENT_ENABLED" NAME_SHOULD_BE = "NAME_SHOULD_BE" NAME_SHOULD_CONTAINS = "NAME_SHOULD_CONTAINS" + ELEMENT_SHOULD_EXIST = "ELEMENT_SHOULD_EXIST" ELEMENT_SHOULD_NOT_EXIST = "ELEMENT_SHOULD_NOT_EXIST" IS_ELEMENT_VISIBLE = "IS_ELEMENT_VISIBLE" ELEMENT_SHOULD_BE_VISIBLE = "ELEMENT_SHOULD_BE_VISIBLE" @@ -110,9 +111,13 @@ def execute_action(self, action: Action, values: Container): * Values ["xpath"] * Returns : None + * Action.ELEMENT_SHOULD_EXIST + * Values ["xpath"] + * Returns : True if element exists otherwise False + * Action.ELEMENT_SHOULD_NOT_EXIST * Values ["xpath"] - * Returns : None + * Returns : True if element not exists otherwise False * Action.WAIT_UNTIL_ELEMENT_IS_HIDDEN * Values ["xpath", "retries"] @@ -140,6 +145,7 @@ def execute_action(self, action: Action, values: Container): self.Action.IS_ELEMENT_VISIBLE: lambda: self._get_element(values["xpath"]).IsOffscreen, self.Action.ELEMENT_SHOULD_BE_VISIBLE: lambda: self._element_should_be_visible(values["xpath"]), self.Action.ELEMENT_SHOULD_NOT_BE_VISIBLE: lambda: self._element_should_not_be_visible(values["xpath"]), + self.Action.ELEMENT_SHOULD_EXIST: lambda: not self._element_should_not_exist(values["xpath"]), self.Action.ELEMENT_SHOULD_NOT_EXIST: lambda: self._element_should_not_exist(values["xpath"]), self.Action.WAIT_UNTIL_ELEMENT_IS_HIDDEN: lambda: self._wait_until_element_is_hidden( values["xpath"], values["retries"]), @@ -243,7 +249,9 @@ def _element_should_not_exist(self, xpath: str): component = desktop.FindFirstByXPath(xpath) if component: - raise FlaUiError(FlaUiError.ElementExists.format(xpath)) + return False + + return True def _element_should_be_visible(self, xpath: str): """ diff --git a/src/FlaUILibrary/keywords/element.py b/src/FlaUILibrary/keywords/element.py index 6485bc3..055162a 100644 --- a/src/FlaUILibrary/keywords/element.py +++ b/src/FlaUILibrary/keywords/element.py @@ -1,5 +1,4 @@ from robotlibcore import keyword - from FlaUILibrary.flaui.module.element import Element @@ -17,48 +16,42 @@ def __init__(self, module): self._module = module @keyword - def element_should_exist(self, identifier, msg=None): + def element_should_exist(self, identifier): """ Checks if element exists. If element exists True will be returned otherwise False. + If element could not be found by xpath False will be returned. XPath syntax is explained in `XPath locator`. - If element could not be found by xpath an error message will be thrown. - Arguments: | Argument | Type | Description | | identifier | string | XPath identifier from element | - | msg | string | Custom error message | Example: - | Element Should Exist | + | ${RESULT} Element Should Exist | """ - self._module.action(Element.Action.GET_ELEMENT, - Element.create_value_container(xpath=identifier, msg=msg), - msg) + return self._module.action(Element.Action.ELEMENT_SHOULD_EXIST, + Element.create_value_container(xpath=identifier)) @keyword - def element_should_not_exist(self, identifier, msg=None): + def element_should_not_exist(self, identifier): """ Checks if element exists. If element exists False will be returned otherwise True. + If element could not be found by xpath True will be returned. XPath syntax is explained in `XPath locator`. - If element could not be found by xpath an error message will be thrown. - Arguments: | Argument | Type | Description | | identifier | string | XPath identifier from element | - | msg | string | Custom error message | Example: - | Element Should Exist | + | ${RESULT} Element Should Not Exist | """ - self._module.action(Element.Action.ELEMENT_SHOULD_NOT_EXIST, - Element.create_value_container(xpath=identifier, msg=msg), - msg) + return self._module.action(Element.Action.ELEMENT_SHOULD_NOT_EXIST, + Element.create_value_container(xpath=identifier)) @keyword def focus(self, identifier, msg=None): @@ -237,7 +230,6 @@ def element_should_not_be_visible(self, identifier, msg=None): def wait_until_element_is_hidden(self, identifier, retries=10, msg=None): """ Waits until element is hidden or timeout was reached. If timeout was reached an FlaUIError occurred. - Checks if element exists before Wait Until Element Is Hidden is called. XPath syntax is explained in `XPath locator`. @@ -251,7 +243,6 @@ def wait_until_element_is_hidden(self, identifier, retries=10, msg=None): | Wait Until Element Is Hidden | | Wait Until Element Is Hidden | """ - self.element_should_exist(identifier, msg) self._module.action(Element.Action.WAIT_UNTIL_ELEMENT_IS_HIDDEN, Element.create_value_container(xpath=identifier, retries=retries), msg)