diff options
author | Edan Binshtok <eb578m@intl.att.com> | 2017-11-19 11:50:50 +0200 |
---|---|---|
committer | Edan Binshtok <eb578m@intl.att.com> | 2017-11-19 11:51:04 +0200 |
commit | 71891b3040605103397ffa7fb349215eced3a2c3 (patch) | |
tree | 22dda04edd1b8ee0d0de2a6a260d6d60e42cba25 /services/frontend/base_actions | |
parent | 433a8256e31f755f5e236491bbe39d3db24d6d6d (diff) |
Pep8 another fixes
Add more fixes to pep8
Issue-ID: VVP-25
Change-Id: Icc3bd3977ced2b537c858a9801e04a6bf6d1db05
Signed-off-by: Edan Binshtok <eb578m@intl.att.com>
Diffstat (limited to 'services/frontend/base_actions')
-rw-r--r-- | services/frontend/base_actions/__init__.py | 4 | ||||
-rw-r--r-- | services/frontend/base_actions/click.py | 36 | ||||
-rw-r--r-- | services/frontend/base_actions/enter.py | 114 | ||||
-rw-r--r-- | services/frontend/base_actions/get.py | 36 | ||||
-rw-r--r-- | services/frontend/base_actions/wait.py | 80 |
5 files changed, 169 insertions, 101 deletions
diff --git a/services/frontend/base_actions/__init__.py b/services/frontend/base_actions/__init__.py index 30d7152..32b601a 100644 --- a/services/frontend/base_actions/__init__.py +++ b/services/frontend/base_actions/__init__.py @@ -1,5 +1,5 @@ - -# ============LICENSE_START========================================== + +# ============LICENSE_START========================================== # org.onap.vvp/test-engine # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. diff --git a/services/frontend/base_actions/click.py b/services/frontend/base_actions/click.py index 00470b7..561b2f7 100644 --- a/services/frontend/base_actions/click.py +++ b/services/frontend/base_actions/click.py @@ -1,5 +1,5 @@ - -# ============LICENSE_START========================================== + +# ============LICENSE_START========================================== # org.onap.vvp/test-engine # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -51,7 +51,8 @@ class Click: Wait.page_has_loaded() Wait.id(element_id) session.ice_driver.find_element_by_id(element_id).click() - except Exception as e: # If failed - count the failure and add the error to list of errors. + # If failed - count the failure and add the error to list of errors. + except Exception as e: errorMsg = "Failed to click_on on ID " + element_id raise Exception(errorMsg, e) @@ -62,18 +63,21 @@ class Click: Wait.page_has_loaded() Wait.name(element_name) session.ice_driver.find_element_by_name(element_name).click() - except Exception as e: # If failed - count the failure and add the error to list of errors. + # If failed - count the failure and add the error to list of errors. + except Exception as e: errorMsg = "Failed to click_on on ID " + element_name raise Exception(errorMsg, e) - + @staticmethod def link_text(link_inner_text, wait_for_page=False): try: if wait_for_page: Wait.page_has_loaded() Wait.link_text(link_inner_text) - session.ice_driver.find_element_by_link_text(link_inner_text).click() - except Exception as e: # If failed - count the failure and add the error to list of errors. + session.ice_driver.find_element_by_link_text( + link_inner_text).click() + # If failed - count the failure and add the error to list of errors. + except Exception as e: errorMsg = "Failed to click_on on LINK TEXT " + link_inner_text raise Exception(errorMsg, e) @@ -83,8 +87,10 @@ class Click: if wait_for_page: Wait.page_has_loaded() Wait.css(element_css) - session.ice_driver.find_element_by_css_selector(element_css).click() - except Exception as e: # If failed - count the failure and add the error to list of errors. + session.ice_driver.find_element_by_css_selector( + element_css).click() + # If failed - count the failure and add the error to list of errors. + except Exception as e: errorMsg = "Failed to click_on on CSS Selector " + element_css raise Exception(errorMsg, e) @@ -95,7 +101,8 @@ class Click: Wait.page_has_loaded() Wait.xpath(element_xpath) session.ice_driver.find_element_by_xpath(element_xpath).click() - except Exception as e: # If failed - count the failure and add the error to list of errors. + # If failed - count the failure and add the error to list of errors. + except Exception as e: errorMsg = "Failed to click_on on XPATH " + element_xpath raise Exception(errorMsg, e) @@ -104,5 +111,10 @@ class Click: ns = session.ice_driver.find_element_by_id("step-description-1") ActionChains(session.ice_driver).move_to_element(ns).perform() Wait.css(source_css) - source_element = session.ice_driver.find_element_by_css_selector(source_css) - ActionChains(session.ice_driver).drag_and_drop_by_offset(source_element, xoffset, yoffset).perform() + source_element = session.ice_driver.find_element_by_css_selector( + source_css) + ActionChains( + session.ice_driver).drag_and_drop_by_offset( + source_element, + xoffset, + yoffset).perform() diff --git a/services/frontend/base_actions/enter.py b/services/frontend/base_actions/enter.py index 4577a3d..2a6992d 100644 --- a/services/frontend/base_actions/enter.py +++ b/services/frontend/base_actions/enter.py @@ -1,5 +1,5 @@ - -# ============LICENSE_START========================================== + +# ============LICENSE_START========================================== # org.onap.vvp/test-engine # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -45,85 +45,117 @@ from services.session import session logger = LoggingServiceFactory.get_logger() + + class Enter: - + @staticmethod def text_by_name(attr_name_value, typed_text, wait_for_page=False): - try: # Send keys to element in UI, by name locator (e.g. type something in text box). + # Send keys to element in UI, by name locator (e.g. type something in + # text box). + try: if wait_for_page: Wait.page_has_loaded() Wait.name(attr_name_value) session.ice_driver.find_element_by_name(attr_name_value).clear() - session.ice_driver.find_element_by_name(attr_name_value).send_keys(typed_text[:-1]) + session.ice_driver.find_element_by_name( + attr_name_value).send_keys(typed_text[:-1]) time.sleep(session.wait_until_time_pause) - session.ice_driver.find_element_by_name(attr_name_value).send_keys(typed_text[-1:]) - except Exception as e: # If failed - count the failure and add the error to list of errors. - errorMsg = "Failed to type " + typed_text + " in text box" + session.ice_driver.find_element_by_name( + attr_name_value).send_keys(typed_text[-1:]) + # If failed - count the failure and add the error to list of errors. + except Exception as e: + errorMsg = "Failed to type " + typed_text + " in text box" raise Exception(errorMsg, e) - + @staticmethod def text_by_xpath(attr_xpath_value, typed_text, wait_for_page=False): - try: # Send keys to element in UI, by name locator (e.g. type something in text box). + # Send keys to element in UI, by name locator (e.g. type something in + # text box). + try: if wait_for_page: Wait.page_has_loaded() Wait.xpath(attr_xpath_value) session.ice_driver.find_element_by_xpath(attr_xpath_value).clear() - session.ice_driver.find_element_by_xpath(attr_xpath_value).send_keys(typed_text[:-1]) + session.ice_driver.find_element_by_xpath( + attr_xpath_value).send_keys(typed_text[:-1]) time.sleep(session.wait_until_time_pause) - session.ice_driver.find_element_by_xpath(attr_xpath_value).send_keys(typed_text[-1:]) - except Exception as e: # If failed - count the failure and add the error to list of errors. - errorMsg = "Failed to type " + typed_text + " in text box" + session.ice_driver.find_element_by_xpath( + attr_xpath_value).send_keys(typed_text[-1:]) + # If failed - count the failure and add the error to list of errors. + except Exception: + errorMsg = "Failed to type " + typed_text + " in text box" raise Exception(errorMsg, attr_xpath_value) - + @staticmethod def text_by_id(attr_id_value, typed_text, wait_for_page=False): - try: # Send keys to element in UI, by ID locator (e.g. type something in text box). + # Send keys to element in UI, by ID locator (e.g. type something in + # text box). + try: if wait_for_page: Wait.page_has_loaded() Wait.id(attr_id_value) session.ice_driver.find_element_by_id(attr_id_value).clear() - session.ice_driver.find_element_by_id(attr_id_value).send_keys(typed_text[:-1]) + session.ice_driver.find_element_by_id( + attr_id_value).send_keys(typed_text[:-1]) time.sleep(session.wait_until_time_pause) - session.ice_driver.find_element_by_id(attr_id_value).send_keys(typed_text[-1:]) - except Exception as e: # If failed - count the failure and add the error to list of errors. - errorMsg = "Failed to type " + typed_text + " in text box" + session.ice_driver.find_element_by_id( + attr_id_value).send_keys(typed_text[-1:]) + # If failed - count the failure and add the error to list of errors. + except Exception: + errorMsg = "Failed to type " + typed_text + " in text box" raise Exception(errorMsg, attr_id_value) - + @staticmethod def clear(attr_id_value): try: Wait.id(attr_id_value) session.ice_driver.find_element_by_id(attr_id_value).clear() - except Exception as e: - errorMsg = "Failed to clear text box" + except Exception: + errorMsg = "Failed to clear text box" raise Exception(errorMsg, attr_id_value) - + @staticmethod def text_by_css(attr_css_value, typed_text, wait_for_page=False): - try: # Send keys to element in UI, by CSS locator (e.g. type something in text box). + # Send keys to element in UI, by CSS locator (e.g. type something in + # text box). + try: if wait_for_page: Wait.page_has_loaded() Wait.css(attr_css_value) - session.ice_driver.find_element_by_css_selector(attr_css_value).clear() - session.ice_driver.find_element_by_css_selector(attr_css_value).send_keys(typed_text[:-1]) + session.ice_driver.find_element_by_css_selector( + attr_css_value).clear() + session.ice_driver.find_element_by_css_selector( + attr_css_value).send_keys(typed_text[:-1]) time.sleep(session.wait_until_time_pause) - session.ice_driver.find_element_by_css_selector(attr_css_value).send_keys(typed_text[-1:]) - except Exception as e: # If failed - count the failure and add the error to list of errors. - errorMsg = "Failed to type " + typed_text + " in text box" + session.ice_driver.find_element_by_css_selector( + attr_css_value).send_keys(typed_text[-1:]) + # If failed - count the failure and add the error to list of errors. + except Exception: + errorMsg = "Failed to type " + typed_text + " in text box" raise Exception(errorMsg, attr_css_value) - + @staticmethod - def text_by_link_text(attr_link_text_value, typed_text, wait_for_page=False): - try: # Send keys to element in UI, by name locator (e.g. type something in text box). + def text_by_link_text( + attr_link_text_value, + typed_text, + wait_for_page=False): + # Send keys to element in UI, by name locator (e.g. type something in + # text box). + try: if wait_for_page: Wait.page_has_loaded() Wait.link_text(attr_link_text_value) - session.ice_driver.find_element_by_link_text(attr_link_text_value).clear() - session.ice_driver.find_element_by_link_text(attr_link_text_value).send_keys(typed_text[:-1]) + session.ice_driver.find_element_by_link_text( + attr_link_text_value).clear() + session.ice_driver.find_element_by_link_text( + attr_link_text_value).send_keys(typed_text[:-1]) time.sleep(session.wait_until_time_pause) - session.ice_driver.find_element_by_link_text(attr_link_text_value).send_keys(typed_text[-1:]) - except Exception as e: # If failed - count the failure and add the error to list of errors. - errorMsg = "Failed to type " + typed_text + " in text box" + session.ice_driver.find_element_by_link_text( + attr_link_text_value).send_keys(typed_text[-1:]) + # If failed - count the failure and add the error to list of errors. + except Exception: + errorMsg = "Failed to type " + typed_text + " in text box" raise Exception(errorMsg, attr_link_text_value) @staticmethod @@ -132,8 +164,10 @@ class Enter: if wait_for_page: Wait.page_has_loaded() session.ice_driver.execute_script( - "var element = angular.element(document.querySelector('" + selector + "')); element.scope()." + - property_name + " = new Date('" + str(datetime.today().isoformat()) + "')") + "var element = angular.element(document." + + "querySelector('" + selector + "')); element.scope()." + + property_name + " = new Date('" + + str(datetime.today().isoformat()) + "')") except Exception as e: errorMsg = "Failed to select date with datePicker." raise Exception(errorMsg, str(e)) diff --git a/services/frontend/base_actions/get.py b/services/frontend/base_actions/get.py index 5fb801a..0eb7959 100644 --- a/services/frontend/base_actions/get.py +++ b/services/frontend/base_actions/get.py @@ -51,7 +51,7 @@ class Get: Wait.id(attr_id_value) return session.ice_driver.find_element_by_id(attr_id_value).text # If failed - count the failure and add the error to list of errors. - except Exception as e: + except Exception: errorMsg = "Failed to get text of element " + attr_id_value raise Exception(errorMsg, attr_id_value) @@ -61,9 +61,10 @@ class Get: if wait_for_page: Wait.page_has_loaded() Wait.css(attr_css_value) - return session.ice_driver.find_element_by_css_selector(attr_css_value).text + return session.ice_driver.find_element_by_css_selector( + attr_css_value).text # If failed - count the failure and add the error to list of errors. - except Exception as e: + except Exception: errorMsg = "Failed to get text of element " + attr_css_value raise Exception(errorMsg, attr_css_value) @@ -74,7 +75,7 @@ class Get: return session.ice_driver.find_element_by_css_selector( "#" + attr_id_value + ".wysiwyg-textarea") # If failed - count the failure and add the error to list of errors. - except Exception as e: + except Exception: errorMsg = "Failed to get element by id " + attr_id_value raise Exception(errorMsg, attr_id_value) @@ -82,9 +83,10 @@ class Get: def by_name(attr_name_value): try: Wait.name(attr_name_value) - return session.ice_driver.find_element_by_name(attr_name_value).text + return session.ice_driver.find_element_by_name( + attr_name_value).text # If failed - count the failure and add the error to list of errors. - except Exception as e: + except Exception: errorMsg = "Failed to get text of element " + attr_name_value raise Exception(errorMsg, attr_name_value) @@ -92,9 +94,10 @@ class Get: def by_xpath(attr_name_value): try: Wait.xpath(attr_name_value) - return session.ice_driver.find_element_by_xpath(attr_name_value).text + return session.ice_driver.find_element_by_xpath( + attr_name_value).text # If failed - count the failure and add the error to list of errors. - except Exception as e: + except Exception: errorMsg = "Failed to get text of element " + attr_name_value raise Exception(errorMsg, attr_name_value) @@ -104,8 +107,9 @@ class Get: if wait_for_page: Wait.page_has_loaded() Wait.name(attr_name_value) - return session.ice_driver.find_element_by_name(attr_name_value).get_attribute("value") - except Exception as e: + return session.ice_driver.find_element_by_name( + attr_name_value).get_attribute("value") + except Exception: errorMsg = "Failed to get value by name:" + attr_name_value raise Exception(errorMsg, attr_name_value) @@ -113,8 +117,9 @@ class Get: def meta_order_by_id(attr_id_value): try: Wait.id(attr_id_value) - return session.ice_driver.find_element_by_id(attr_id_value).get_attribute("meta-order") - except Exception as e: + return session.ice_driver.find_element_by_id( + attr_id_value).get_attribute("meta-order") + except Exception: errorMsg = "Failed to get meta order by id:" + attr_id_value raise Exception(errorMsg, attr_id_value) @@ -124,8 +129,9 @@ class Get: if wait_for_page: Wait.page_has_loaded() Wait.id(attr_id_value) - return session.ice_driver.find_element_by_id(attr_id_value).is_selected() - except Exception as e: + return session.ice_driver.find_element_by_id( + attr_id_value).is_selected() + except Exception: errorMsg = "Failed to get if it's selected by id:" + attr_id_value raise Exception(errorMsg, attr_id_value) @@ -138,6 +144,6 @@ class Get: return Helper.internal_assert_boolean_true_false( session.ice_driver.find_element_by_id( attr_id_value).get_attribute("value"), "on") - except Exception as e: + except Exception: errorMsg = "Failed to get if it's selected by id:" + attr_id_value raise Exception(errorMsg, attr_id_value) diff --git a/services/frontend/base_actions/wait.py b/services/frontend/base_actions/wait.py index a699917..4434bb1 100644 --- a/services/frontend/base_actions/wait.py +++ b/services/frontend/base_actions/wait.py @@ -58,12 +58,12 @@ class Wait: try: # Wait 4 seconds for element and compare to expected result. if wait_for_page: Wait.page_has_loaded() - WebDriverWait(session.ice_driver, session.wait_until_retires).until( + WebDriverWait( + session.ice_driver, session.wait_until_retires).until( expected_conditions.text_to_be_present_in_element( - (By.XPATH, xpath), text) - ) + (By.XPATH, xpath), text)) # If failed - count the failure and add the error to list of errors. - except: + except Exception: error_msg = "Text - " + text + " not found in xPath " + xpath raise Exception(error_msg, xpath) @@ -72,12 +72,12 @@ class Wait: try: # Wait 4 seconds for element and compare to expected result. if wait_for_page: Wait.page_has_loaded() - WebDriverWait(session.ice_driver, session.wait_until_retires).until( + WebDriverWait( + session.ice_driver, session.wait_until_retires).until( expected_conditions.text_to_be_present_in_element( - (By.ID, element_id), text) - ) + (By.ID, element_id), text)) # If failed - count the failure and add the error to list of errors. - except: + except Exception: error_msg = "Text - " + text + " not found in ID " + element_id raise Exception(error_msg, element_id) @@ -86,10 +86,10 @@ class Wait: try: # Wait 4 seconds for element and compare to expected result. if wait_for_page: Wait.page_has_loaded() - WebDriverWait(session.ice_driver, session.wait_until_retires).until( + WebDriverWait( + session.ice_driver, session.wait_until_retires).until( expected_conditions.text_to_be_present_in_element( - (By.CSS_SELECTOR, css), text) - ) + (By.CSS_SELECTOR, css), text)) # If failed - count the failure and add the error to list of errors. except Exception as e: error_msg = "Text - " + text + " not found in CSS - " + css @@ -100,10 +100,10 @@ class Wait: try: # Wait 4 seconds for element and compare to expected result. if wait_for_page: Wait.page_has_loaded() - WebDriverWait(session.ice_driver, session.wait_until_retires).until( + WebDriverWait( + session.ice_driver, session.wait_until_retires).until( expected_conditions.text_to_be_present_in_element( - (By.NAME, name), text) - ) + (By.NAME, name), text)) # If failed - count the failure and add the error to list of errors. except Exception as e: error_msg = "Text - " + text + " not found by NAME - " + name @@ -114,7 +114,8 @@ class Wait: try: # Wait 4 seconds for element and compare to expected result. if wait_for_page: Wait.page_has_loaded() - WebDriverWait(session.ice_driver, session.wait_until_retires).until( + WebDriverWait(session.ice_driver, + session.wait_until_retires).until( expected_conditions.visibility_of_element_located( (By.ID, element_id)) ) @@ -128,10 +129,10 @@ class Wait: try: # Wait 4 seconds for element and compare to expected result. if wait_for_page: Wait.page_has_loaded() - WebDriverWait(session.ice_driver, session.wait_until_retires).until( + WebDriverWait( + session.ice_driver, session.wait_until_retires).until( expected_conditions.visibility_of_element_located( - (By.CSS_SELECTOR, element_css)) - ) + (By.CSS_SELECTOR, element_css))) # If failed - count the failure and add the error to list of errors. except Exception as e: error_msg = "Didn't find CSS Selector " + element_css @@ -142,7 +143,8 @@ class Wait: try: # Wait 4 seconds for element and compare to expected result. if wait_for_page: Wait.page_has_loaded() - WebDriverWait(session.ice_driver, session.wait_until_implicit_time).until( + WebDriverWait(session.ice_driver, + session.wait_until_implicit_time).until( expected_conditions.visibility_of_element_located( (By.CSS_SELECTOR, element_css)) ) @@ -157,10 +159,10 @@ class Wait: try: if wait_for_page: Wait.page_has_loaded() - WebDriverWait(session.ice_driver, session.wait_until_retires).until( + WebDriverWait( + session.ice_driver, session.wait_until_retires).until( expected_conditions.visibility_of_element_located( - (By.LINK_TEXT, link_inner_text)) - ) + (By.LINK_TEXT, link_inner_text))) # If failed - count the failure and add the error to list of errors. except Exception as e: error_msg = "Didn't find LINK TEXT " + link_inner_text @@ -171,10 +173,10 @@ class Wait: try: if wait_for_page: Wait.page_has_loaded() - WebDriverWait(session.ice_driver, session.wait_until_retires).until( + WebDriverWait( + session.ice_driver, session.wait_until_retires).until( expected_conditions.visibility_of_element_located( - (By.NAME, element_name)) - ) + (By.NAME, element_name))) # If failed - count the failure and add the error to list of errors. except Exception as e: error_msg = "Didn't find NAME " + element_name @@ -185,10 +187,10 @@ class Wait: try: if wait_for_page: Wait.page_has_loaded() - WebDriverWait(session.ice_driver, session.wait_until_retires).until( + WebDriverWait( + session.ice_driver, session.wait_until_retires).until( expected_conditions.visibility_of_element_located( - (By.XPATH, element_xpath)) - ) + (By.XPATH, element_xpath))) # If failed - count the failure and add the error to list of errors. except Exception as e: error_msg = "Didn't find XPath " + element_xpath @@ -199,14 +201,17 @@ class Wait: for _ in range(Constants.FEConstants.RETRIES_NUMBER): try: httpRequests = session.ice_driver.execute_script( - 'return window.angular ? window.angular.element("body").injector().get("$http").pendingRequests.length : 1;') + 'return window.angular ? window.angular.element("body").' + + 'injector().get("$http").pendingRequests.length : 1;') if(str(httpRequests) == "0"): time.sleep(session.wait_until_time_pause) return logger.debug( - "Checking if {} page is loaded. ".format(session.ice_driver.current_url)) + "Checking if {} page is loaded. ".format( + session.ice_driver.current_url)) time.sleep(session.wait_until_time_pause) except Exception as exception: + time.sleep(session.wait_until_time_pause) continue raise Exception("Page loading took too much time") @@ -266,7 +271,10 @@ class Wait: return True else: raise Exception( - "id_to_dissappear " + id_element + " num of retries = " + str(i)) + "id_to_dissappear " + + id_element + + " num of retries = " + + str(i)) @staticmethod def name_to_dissappear(name_element, wait_for_page=False): @@ -292,7 +300,10 @@ class Wait: return True else: raise Exception( - "name_to_dissappear " + name_element + " num of retries = " + str(i)) + "name_to_dissappear " + + name_element + + " num of retries = " + + str(i)) @staticmethod def css_to_dissappear(css_element): @@ -316,3 +327,8 @@ class Wait: return True else: raise Exception("css_to_dissappear" + css_element) + + @staticmethod + def bucket_to_create(bucket_id): + logger.debug("Waiting for %s bucket to be created" % bucket_id) + time.sleep(session.positive_timeout) |