Skip to content

Commit

Permalink
Better _is_element_present plus 'Select Elements From Menu' (#146)
Browse files Browse the repository at this point in the history
* Testing

* Testing

* Cleanup

* cleanup

* more tests

* more

* fix coverage

* remove unneeded count increment

* new docs, increment version.py

* added test

* doc update

* remove unused import

* remove duplicate tests
  • Loading branch information
Wolfe1 committed Oct 28, 2020
1 parent c13437b commit a37d789
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/APILibraryDocumentation.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/DesktopLibraryDocumentation.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/GUILibraryDocumentation.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/MobileLibraryDocumentation.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/SOAPLibraryDocumentation.html
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@
jQuery.extend({highlight:function(e,t,n,r){if(e.nodeType===3){var i=e.data.match(t);if(i){var s=document.createElement(n||"span");s.className=r||"highlight";var o=e.splitText(i.index);o.splitText(i[0].length);var u=o.cloneNode(true);s.appendChild(u);o.parentNode.replaceChild(s,o);return 1}}else if(e.nodeType===1&&e.childNodes&&!/(script|style)/i.test(e.tagName)&&!(e.tagName===n.toUpperCase()&&e.className===r)){for(var a=0;a<e.childNodes.length;a++){a+=jQuery.highlight(e.childNodes[a],t,n,r)}}return 0}});jQuery.fn.unhighlight=function(e){var t={className:"highlight",element:"span"};jQuery.extend(t,e);return this.find(t.element+"."+t.className).each(function(){var e=this.parentNode;e.replaceChild(this.firstChild,this);e.normalize()}).end()};jQuery.fn.highlight=function(e,t){var n={className:"highlight",element:"span",caseSensitive:false,wordsOnly:false};jQuery.extend(n,t);if(e.constructor===String){e=[e]}e=jQuery.grep(e,function(e,t){return e!=""});e=jQuery.map(e,function(e,t){return e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")});if(e.length==0){return this}var r=n.caseSensitive?"":"i";var i="("+e.join("|")+")";if(n.wordsOnly){i="\\b"+i+"\\b"}var s=new RegExp(i,r);return this.each(function(){jQuery.highlight(this,s,n.element,n.className)})}
</script>
<script type="text/javascript">
libdoc = {"all_tags":[],"contains_tags":false,"doc":"<p>Zoomba SOAP Library\x3c/p>\n<p>This class is the base Library used to generate automated SOAP Tests in the Zoomba Automation Framework.\x3c/p>","generated":"2020-10-20 15:38:09","inits":[],"keywords":[{"args":["action=None","soap_object=None"],"doc":"<p>Call Soap Method. Calls soap method with list object\x3c/p>\n<p>action: (string) SOAP Action to be called.\x3c/p>\n<p>soap_object: (list) Soap Object in list format, list must be ordered wrt schema\x3c/p>","matched":true,"name":"Call Soap Method With List Object","shortdoc":"Call Soap Method. Calls soap method with list object ","tags":[]},{"args":["action=None","**soap_object"],"doc":"<p>Call Soap Method with dictionary object. Calls soap method\x3c/p>\n<p>action: (string) SOAP Action to be called.\x3c/p>\n<p>soap_object: (dict) Soap Object in dict format, dict must contain all required parts of schema object.\x3c/p>","matched":true,"name":"Call Soap Method With Object","shortdoc":"Call Soap Method with dictionary object. Calls soap method ","tags":[]},{"args":["soap_response=None"],"doc":"<p>Convert Soap Response To Dictionary: This keyword builds a dictionary from the sudsLibrary response\x3c/p>\n<p>json_actual_response: (request response object) The response from an API.\x3c/p>\n<p>return: There is no actual returned output, other than error messages when comparisons fail.\x3c/p>","matched":true,"name":"Convert Soap Response To Json","shortdoc":"Convert Soap Response To Dictionary: This keyword builds a dictionary from the sudsLibrary response","tags":[]},{"args":["host=None","endpoint=None","alias=None","**kwargs"],"doc":"<p>Create Soap Session. This Keyword utilizes the WSDL to create a soap client.\x3c/p>\n<p>host: (string) The host url.\x3c/p>\n<p>endpoint: (string) SOAP API endpoint containing the actions to be referenced.\x3c/p>\n<p>**kwargs: (optional) Parameters that could be included to add options to client creation. Current supported parameters are:\x3c/p>\n<p>set_location: http address\x3c/p>","matched":true,"name":"Create Soap Session","shortdoc":"Create Soap Session. This Keyword utilizes the WSDL to create a soap client.","tags":[]},{"args":["host=None","endpoint=None","alias=None","**kwargs"],"doc":"<p>Create Soap Session. This Keyword utilizes the WSDL and directly accesses calls from sudsLibrary.\x3c/p>\n<p>host: (string) The host url.\x3c/p>\n<p>endpoint: (string) SOAP API endpoint containing the actions to be referenced.\x3c/p>\n<p>alias: (string} Sets the alias for the SudsLibrary Framework **kwargs: (optional) Parameters that could be included to add options to client creation. Current supported parameters are:\x3c/p>\n<p>set_location: http address\x3c/p>","matched":true,"name":"Create Soap Session And Fix Wsdl","shortdoc":"Create Soap Session. This Keyword utilizes the WSDL and directly accesses calls from sudsLibrary.","tags":[]},{"args":["host=None","endpoint=None","alias=None","set_location=None","fix=False"],"doc":"<p>Create Soap Session and Set Location. In addition to the client creation, this keyword sets the location as specified.\x3c/p>\n<p>host: (string) The host url.\x3c/p>\n<p>endpoint: (string) SOAP API endpoint containing the actions to be referenced.\x3c/p>\n<p>set_location: (string) If set will overwrite the WSDL location with specified address.\x3c/p>\n<p>If set to None will replace location with host and endpoint specified\x3c/p>","matched":true,"name":"Create Soap Session And Set Location","shortdoc":"Create Soap Session and Set Location. In addition to the client creation, this keyword sets the location as specified.","tags":[]},{"args":["wsdl_type=None","object_dict=None"],"doc":"<p>Create Wsdl Objects. This Keyword utilizes the WSDL to create a WSDL object based on the information provided.\x3c/p>\n<p>wsdl_type: (string) Wsdl object to be created.\x3c/p>\n<p>object_dict: (dict) Python Dictionary containing values and nested dictionaries with construction similar to wsdl defined objects.\x3c/p>\n<p>return: (response object) Returns the SOAP client object.\x3c/p>","matched":true,"name":"Create Wsdl Objects","shortdoc":"Create Wsdl Objects. This Keyword utilizes the WSDL to create a WSDL object based on the information provided.","tags":[]}],"name":"SOAP_Library","named_args":true,"scope":"TEST","version":"2.5.4"};
libdoc = {"all_tags":[],"contains_tags":false,"doc":"<p>Zoomba SOAP Library\x3c/p>\n<p>This class is the base Library used to generate automated SOAP Tests in the Zoomba Automation Framework.\x3c/p>","generated":"2020-10-28 09:21:59","inits":[],"keywords":[{"args":["action=None","soap_object=None"],"doc":"<p>Call Soap Method. Calls soap method with list object\x3c/p>\n<p>action: (string) SOAP Action to be called.\x3c/p>\n<p>soap_object: (list) Soap Object in list format, list must be ordered wrt schema\x3c/p>","matched":true,"name":"Call Soap Method With List Object","shortdoc":"Call Soap Method. Calls soap method with list object ","tags":[]},{"args":["action=None","**soap_object"],"doc":"<p>Call Soap Method with dictionary object. Calls soap method\x3c/p>\n<p>action: (string) SOAP Action to be called.\x3c/p>\n<p>soap_object: (dict) Soap Object in dict format, dict must contain all required parts of schema object.\x3c/p>","matched":true,"name":"Call Soap Method With Object","shortdoc":"Call Soap Method with dictionary object. Calls soap method ","tags":[]},{"args":["soap_response=None"],"doc":"<p>Convert Soap Response To Dictionary: This keyword builds a dictionary from the sudsLibrary response\x3c/p>\n<p>json_actual_response: (request response object) The response from an API.\x3c/p>\n<p>return: There is no actual returned output, other than error messages when comparisons fail.\x3c/p>","matched":true,"name":"Convert Soap Response To Json","shortdoc":"Convert Soap Response To Dictionary: This keyword builds a dictionary from the sudsLibrary response","tags":[]},{"args":["host=None","endpoint=None","alias=None","**kwargs"],"doc":"<p>Create Soap Session. This Keyword utilizes the WSDL to create a soap client.\x3c/p>\n<p>host: (string) The host url.\x3c/p>\n<p>endpoint: (string) SOAP API endpoint containing the actions to be referenced.\x3c/p>\n<p>**kwargs: (optional) Parameters that could be included to add options to client creation. Current supported parameters are:\x3c/p>\n<p>set_location: http address\x3c/p>","matched":true,"name":"Create Soap Session","shortdoc":"Create Soap Session. This Keyword utilizes the WSDL to create a soap client.","tags":[]},{"args":["host=None","endpoint=None","alias=None","**kwargs"],"doc":"<p>Create Soap Session. This Keyword utilizes the WSDL and directly accesses calls from sudsLibrary.\x3c/p>\n<p>host: (string) The host url.\x3c/p>\n<p>endpoint: (string) SOAP API endpoint containing the actions to be referenced.\x3c/p>\n<p>alias: (string} Sets the alias for the SudsLibrary Framework **kwargs: (optional) Parameters that could be included to add options to client creation. Current supported parameters are:\x3c/p>\n<p>set_location: http address\x3c/p>","matched":true,"name":"Create Soap Session And Fix Wsdl","shortdoc":"Create Soap Session. This Keyword utilizes the WSDL and directly accesses calls from sudsLibrary.","tags":[]},{"args":["host=None","endpoint=None","alias=None","set_location=None","fix=False"],"doc":"<p>Create Soap Session and Set Location. In addition to the client creation, this keyword sets the location as specified.\x3c/p>\n<p>host: (string) The host url.\x3c/p>\n<p>endpoint: (string) SOAP API endpoint containing the actions to be referenced.\x3c/p>\n<p>set_location: (string) If set will overwrite the WSDL location with specified address.\x3c/p>\n<p>If set to None will replace location with host and endpoint specified\x3c/p>","matched":true,"name":"Create Soap Session And Set Location","shortdoc":"Create Soap Session and Set Location. In addition to the client creation, this keyword sets the location as specified.","tags":[]},{"args":["wsdl_type=None","object_dict=None"],"doc":"<p>Create Wsdl Objects. This Keyword utilizes the WSDL to create a WSDL object based on the information provided.\x3c/p>\n<p>wsdl_type: (string) Wsdl object to be created.\x3c/p>\n<p>object_dict: (dict) Python Dictionary containing values and nested dictionaries with construction similar to wsdl defined objects.\x3c/p>\n<p>return: (response object) Returns the SOAP client object.\x3c/p>","matched":true,"name":"Create Wsdl Objects","shortdoc":"Create Wsdl Objects. This Keyword utilizes the WSDL to create a WSDL object based on the information provided.","tags":[]}],"name":"SOAP_Library","named_args":true,"scope":"TEST","version":"2.5.5"};
</script>
<title></title>
</head>
Expand Down
12 changes: 9 additions & 3 deletions samples/DesktopTests.robot
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ Send Keys Keyword Test
Send Keys 24 \ue025 2 \ue007
Page Should Contain Text 26

Send Keys with Modifier (Ctrl + v)
Send Keys \ue009 v \ue009
Wait Until Element Contains accessibility_id=CalculatorResults Display is Invalid input
Send Keys with Modifier (Alt + 2)
Send Keys \ue00A 2 \ue00A
Wait Until Page Contains Element Name=Scientific Calculator mode
Send Keys \ue00A 1 \ue00A
Wait Until Page Contains Element Name=Standard Calculator mode

Send Keys To Element Keyword Test
Send Keys To Element name=Display is 0 24 \ue025 2 \ue007
Expand All @@ -118,6 +120,10 @@ Select Element From Combobox Test
Wait Until Page Contains Element accessibility_id=TogglePaneButton
Select Element From ComboBox accessibility_id=TogglePaneButton accessibility_id=Standard

Select Elements From Menu Test
Select Elements From Menu name=Two name=Three name=Four
Wait Until Element Contains accessibility_id=CalculatorResults 234

Switch To Desktop Test
Close Application
Switch Application Desktop
Expand Down
60 changes: 57 additions & 3 deletions src/Zoomba/DesktopLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from robot.libraries.BuiltIn import BuiltIn
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.action_chains import ActionChains
from time import sleep
from time import sleep, time
from robot import utils

try:
AppiumCommon = importlib.import_module('Helpers.AppiumCommon', package='Helpers')
Expand Down Expand Up @@ -121,7 +122,7 @@ def get_keyword_names(self):
'mouse_over_and_context_click_element', 'mouse_over_by_offset', 'drag_and_drop',
'drag_and_drop_by_offset', 'send_keys', 'send_keys_to_element',
'capture_page_screenshot', 'save_appium_screenshot', 'select_element_from_combobox',
'driver_setup', 'driver_teardown',
'driver_setup', 'driver_teardown', 'select_elements_from_menu',
# External Libraries
'clear_text', 'click_button', 'click_element', 'close_all_applications',
'close_application', 'element_attribute_should_match', 'element_should_be_disabled',
Expand Down Expand Up @@ -605,6 +606,30 @@ def select_element_from_combobox(self, list_locator, element_locator, skip_to_de
self.click_element(element_locator)
self.switch_application(original_index)

@keyword("Select Elements From Menu")
def select_elements_from_menu(self, *args):
"""Selects N number of elements in the order they are given. This is useful for working
though a nested menu listing of elements.
On failure this keyword wil attempt to select the elements from the desktop session due to
the nature of some pop-out menus in Windows."""
count = 0
try:
for each in args:
self.click_element(each)
count += 1
except NoSuchElementException:
original_index = self._cache.current_index
self.switch_application('Desktop')
for each in args[count:]:
try:
self.click_element(each)
except NoSuchElementException:
self._wait_until_page_contains_element(each, self.get_appium_timeout())
self.click_element(each)
count += 1
self.switch_application(original_index)

# Private
def _move_to_element(self, actions, element, x_offset=0, y_offset=0):
if x_offset != 0 or y_offset != 0:
Expand Down Expand Up @@ -654,6 +679,23 @@ def _element_find(self, locator, first_only, *kwargs):
return driver.find_elements_by_accessibility_id(criteria)
zoomba.fail("Element locator with prefix '" + prefix + "' is not supported")

def _is_element_present(self, locator):
prefix, criteria = self._parse_locator(locator)
driver = self._current_application()
if prefix is None:
if criteria.startswith('//'):
return len(driver.find_elements_by_xpath(criteria)) > 0
return len(driver.find_elements_by_accessibility_id(criteria)) > 0
if prefix == 'name':
return len(driver.find_elements_by_name(criteria)) > 0
if prefix == 'class':
return len(driver.find_elements_by_class_name(criteria)) > 0
if prefix == 'xpath':
return len(driver.find_elements_by_xpath(criteria)) > 0
if prefix == 'accessibility_id':
return len(driver.find_elements_by_accessibility_id(criteria)) > 0
zoomba.fail("Element locator with prefix '" + prefix + "' is not supported")

def _parse_locator(self, locator):
prefix = None
criteria = locator
Expand All @@ -672,4 +714,16 @@ def _wait_until_page_contains_element(self, locator, timeout=None, error=None):
"""Internal version to avoid duplicate screenshots"""
if not error:
error = "Element '%s' did not appear in <TIMEOUT>" % locator
self._wait_until(timeout, error, self._element_find, locator, True)
self._wait_until(timeout, error, self._is_element_present, locator)

# Overrides to prevent expensive log_source call
def _wait_until_no_error(self, timeout, wait_func, *args):
timeout = utils.timestr_to_secs(timeout) if timeout is not None else self._timeout_in_secs
max_time = time() + timeout
while True:
timeout_error = wait_func(*args)
if not timeout_error:
return
if time() > max_time:
raise AssertionError(timeout_error)
sleep(0.2)

0 comments on commit a37d789

Please sign in to comment.