Skip to content

Commit baf90e9

Browse files
authored
#197 offscreen new keywords (#198)
1 parent c98f3b3 commit baf90e9

File tree

6 files changed

+120
-0
lines changed

6 files changed

+120
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
77

88
## [Unreleased][]
99

10+
### Added
11+
12+
- [#197](https://github.com/GDATASoftwareAG/robotframework-flaui/issues/197) New Keywords
13+
- Element Should Be Offscreen
14+
- Element Should Not Be Offscreen
15+
1016
### Bugfix
1117

1218
- [#195](https://github.com/GDATASoftwareAG/robotframework-flaui/issues/195) click open bugfix

atests/Element.robot

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ ${XPATH_ELEMENT} ${MAIN_WINDOW_SIMPLE_CONTROLS}/Text[@Name='Test
2121
${XPATH_ENABLE_ELEMENT} ${MAIN_WINDOW_SIMPLE_CONTROLS}/Button[@AutomationId='EnableButton']
2222
${XPATH_DISABLED_ELEMENT} ${MAIN_WINDOW_SIMPLE_CONTROLS}/Button[@AutomationId='DisabledButton']
2323
${XPATH_OFFSCREEN_ELEMENT} ${MAIN_WINDOW_SIMPLE_CONTROLS}/Text[@AutomationId='OffscreenTextBlock']
24+
${XPATH_SCROLL_DATAGRID} ${MAIN_WINDOW_COMPLEX_CONTROLS}/Pane[@ClassName='ScrollViewer']/Group[@Name='Large List with Scroll']/DataGrid[@AutomationId='LargeListView']
2425
2526
${XPATH_MFC_APP_MENU_FILE} ${MAIN_WINDOW_MFC}/Pane[@AutomationId='59419']/Pane[@AutomationId='59398']/MenuItem[@Name='File']
2627
@@ -310,3 +311,26 @@ Wait Until Element Exist Timeout Is Reached By Wrong Number
310311
${EXP_ERR_MSG} Format String ${EXP_ERR_MSG_VALUE_SHOULD_BE_A_NUMBER} "I'm not a number"
311312
${ERR_MSG} Run Keyword And Expect Error * Wait Until Element Exist ${MAIN_WINDOW} "I'm not a number"
312313
Should Be Equal As Strings ${EXP_ERR_MSG} ${ERR_MSG}
314+
315+
Element Should Be Offscreen
316+
[Setup] Open Complex Tab
317+
Element Should Be Offscreen ${XPATH_SCROLL_DATAGRID}/DataItem[4]
318+
319+
Element Should Be Offscreen Error
320+
[Setup] Open Complex Tab
321+
${EXP_ERR_MSG} Format String ${EXP_ERR_MSG_ELEMENT_NOT_OFFSCREEN} ${XPATH_SCROLL_DATAGRID}/Header
322+
${ERR_MSG} Run Keyword And Expect Error * Element Should Be Offscreen ${XPATH_SCROLL_DATAGRID}/Header
323+
Should Be Equal As Strings ${EXP_ERR_MSG} ${ERR_MSG}
324+
325+
Element Should Not Be Offscreen
326+
[Setup] Open Complex Tab
327+
Element Should Not Be Offscreen ${XPATH_SCROLL_DATAGRID}/Header
328+
329+
Element Should Not Be Offscreen Error
330+
[Setup] Open Complex Tab
331+
${EXP_ERR_MSG} Format String ${EXP_ERR_MSG_ELEMENT_OFFSCREEN} ${XPATH_SCROLL_DATAGRID}/DataItem[4]
332+
${ERR_MSG} Run Keyword And Expect Error
333+
... *
334+
... Element Should Not Be Offscreen
335+
... ${XPATH_SCROLL_DATAGRID}/DataItem[4]
336+
Should Be Equal As Strings ${EXP_ERR_MSG} ${ERR_MSG}

atests/util/Error.resource

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ ${EXP_ERR_MSG_ELEMENT_NOT_FOCUSABLE} FlaUiError: Element '{0}' is not
1717
${EXP_ERR_MSG_ELEMENT_EXISTS} FlaUiError: Element '{0}' exists
1818
${EXP_ERR_MSG_ELEMENT_DOES_NOT_EXISTS} FlaUiError: Element '{0}' does not exist
1919
${EXP_ERR_MSG_ELEMENT_OFFSCREEN} FlaUiError: Element '{0}' is offscreen
20+
${EXP_ERR_MSG_ELEMENT_NOT_OFFSCREEN} FlaUiError: Element '{0}' is not offscreen
2021
${EXP_ERR_MSG_ELEMENT_VISIBLE} FlaUiError: Element '{0}' is visible
2122
${EXP_ERR_MSG_ELEMENT_NOT_VISIBLE} FlaUiError: Element '{0}' is not visible
2223
${EXP_ERR_MSG_ELEMENT_NOT_ENABLED} FlaUiError: Element '{0}' is not enabled

src/FlaUILibrary/flaui/exception/flauierror.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class FlaUiError(AttributeError):
1919
ElementExists = "Element '{}' exists"
2020
ElementNotExists = "Element '{}' does not exist"
2121
ElementIsOffscreen = "Element '{}' is offscreen"
22+
ElementNotOffscreen = "Element '{}' is not offscreen"
2223
ElementVisible = "Element '{}' is visible"
2324
ElementNotVisible = "Element '{}' is not visible"
2425
ElementNotEnabled = "Element '{}' is not enabled"

src/FlaUILibrary/flaui/module/element.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class Action(Enum):
4444
ELEMENT_SHOULD_NOT_EXIST = "ELEMENT_SHOULD_NOT_EXIST"
4545
ELEMENT_SHOULD_BE_ENABLED = "ELEMENT_SHOULD_BE_ENABLED"
4646
ELEMENT_SHOULD_BE_DISABLED = "ELEMENT_SHOULD_BE_DISABLED"
47+
ELEMENT_SHOULD_BE_OFFSCREEN = "ELEMENT_SHOULD_BE_OFFSCREEN"
48+
ELEMENT_SHOULD_NOT_BE_OFFSCREEN = "ELEMENT_SHOULD_NOT_BE_OFFSCREEN"
4749
WAIT_UNTIL_ELEMENT_IS_OFFSCREEN = "WAIT_UNTIL_ELEMENT_IS_OFFSCREEN"
4850
WAIT_UNTIL_ELEMENT_IS_ENABLED = "WAIT_UNTIL_ELEMENT_IS_ENABLED"
4951
WAIT_UNTIL_ELEMENT_EXIST = "WAIT_UNTIL_ELEMENT_EXIST"
@@ -110,6 +112,10 @@ def execute_action(self, action: Action, values: Container):
110112
lambda: self._element_should_be_enabled(values["xpath"]),
111113
self.Action.ELEMENT_SHOULD_BE_DISABLED:
112114
lambda: self._element_should_be_disabled(values["xpath"]),
115+
self.Action.ELEMENT_SHOULD_BE_OFFSCREEN:
116+
lambda: self._element_should_be_offscreen(values["xpath"]),
117+
self.Action.ELEMENT_SHOULD_NOT_BE_OFFSCREEN:
118+
lambda: self._element_should_not_be_offscreen(values["xpath"]),
113119
self.Action.ELEMENT_SHOULD_EXIST:
114120
lambda: self._element_should_exist(values["xpath"], values["use_exception"]),
115121
self.Action.ELEMENT_SHOULD_NOT_EXIST:
@@ -337,6 +343,38 @@ def _element_should_be_disabled(self, xpath: str):
337343
if enabled:
338344
raise FlaUiError(FlaUiError.ElementNotDisabled.format(xpath))
339345

346+
def _element_should_be_offscreen(self, xpath: str):
347+
"""
348+
Checks if the element with the given xpath is offscreen
349+
350+
Args:
351+
xpath (string): XPath identifier from element.
352+
353+
Raises:
354+
FlaUiError: If node could not be found from xpath.
355+
FlaUiError: If node by xpath is not offscreen.
356+
"""
357+
offscreen = self._element_is_offscreen(xpath)
358+
359+
if not offscreen:
360+
raise FlaUiError(FlaUiError.ElementNotOffscreen.format(xpath))
361+
362+
def _element_should_not_be_offscreen(self, xpath: str):
363+
"""
364+
Checks if the element with the given xpath not offscreen
365+
366+
Args:
367+
xpath (string): XPath identifier from element.
368+
369+
Raises:
370+
FlaUiError: If node could not be found from xpath.
371+
FlaUiError: If node by xpath is offscreen.
372+
"""
373+
offscreen = self._element_is_offscreen(xpath)
374+
375+
if offscreen:
376+
raise FlaUiError(FlaUiError.ElementIsOffscreen.format(xpath))
377+
340378
def _wait_until_element_is_offscreen(self, xpath: str, retries: int):
341379
"""Waits until element is offscreen or timeout occurred.
342380

src/FlaUILibrary/keywords/element.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,56 @@ def is_element_offscreen(self, identifier, msg=None):
256256
Element.create_value_container(xpath=identifier, msg=msg),
257257
msg)
258258

259+
@keyword
260+
def element_should_be_offscreen(self, identifier, msg=None):
261+
"""
262+
Checks if element is offscreen.
263+
264+
XPaths syntax is explained in `XPath locator`.
265+
266+
Possible FlaUI-Errors:
267+
| Element could not be found by xpath |
268+
| Element <XPATH> is not offscreen |
269+
270+
Arguments:
271+
| Argument | Type | Description |
272+
| identifier | string | XPath identifier from element |
273+
| msg | string | Custom error message |
274+
275+
Example:
276+
| Element Should Be Offscreen <XPATH> |
277+
278+
"""
279+
module = self._container.create_or_get_module()
280+
module.action(Element.Action.ELEMENT_SHOULD_BE_OFFSCREEN,
281+
Element.create_value_container(xpath=identifier, msg=msg),
282+
msg)
283+
284+
@keyword
285+
def element_should_not_be_offscreen(self, identifier, msg=None):
286+
"""
287+
Checks if element is not offscreen.
288+
289+
XPaths syntax is explained in `XPath locator`.
290+
291+
Possible FlaUI-Errors:
292+
| Element could not be found by xpath |
293+
| Element <XPATH> is offscreen |
294+
295+
Arguments:
296+
| Argument | Type | Description |
297+
| identifier | string | XPath identifier from element |
298+
| msg | string | Custom error message |
299+
300+
Example:
301+
| Element Should Not Be Offscreen <XPATH> |
302+
303+
"""
304+
module = self._container.create_or_get_module()
305+
module.action(Element.Action.ELEMENT_SHOULD_NOT_BE_OFFSCREEN,
306+
Element.create_value_container(xpath=identifier, msg=msg),
307+
msg)
308+
259309
@keyword
260310
def element_should_be_enabled(self, identifier, msg=None):
261311
"""

0 commit comments

Comments
 (0)