Skip to content

Commit

Permalink
#42 Element not found and Element found handling restructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
Nepitwin committed Jan 29, 2022
1 parent 728e869 commit 5a2f1e3
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 44 deletions.
25 changes: 11 additions & 14 deletions atests/Element.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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}
Expand All @@ -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}
Expand Down
3 changes: 0 additions & 3 deletions atests/ErrorHandling.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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 ***
Expand Down
4 changes: 1 addition & 3 deletions atests/Window.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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}
16 changes: 13 additions & 3 deletions atests/util/Common.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
12 changes: 10 additions & 2 deletions src/FlaUILibrary/flaui/module/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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"]),
Expand Down Expand Up @@ -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):
"""
Expand Down
29 changes: 10 additions & 19 deletions src/FlaUILibrary/keywords/element.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from robotlibcore import keyword

from FlaUILibrary.flaui.module.element import Element


Expand All @@ -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 <XPATH> |
| ${RESULT} Element Should Exist <XPATH> |
"""
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 <XPATH> |
| ${RESULT} Element Should Not Exist <XPATH> |
"""
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):
Expand Down Expand Up @@ -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`.
Expand All @@ -251,7 +243,6 @@ def wait_until_element_is_hidden(self, identifier, retries=10, msg=None):
| Wait Until Element Is Hidden <XPATH> <RETRIES=10> |
| Wait Until Element Is Hidden <XPATH> <RETRIES=10> <MSG> |
"""
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)
Expand Down

0 comments on commit 5a2f1e3

Please sign in to comment.