def get_browser(self): """ Return the browser type specified in the data Examples: | Get Browser | """ return test_data.get_variable(test_data.GlobalProperty.Browser)
def _get_browser_status(): """ _get_browser_status Description : Function used for getting the browser status to verify browser already opened or not. """ status = test_data.get_variable(test_data.GlobalProperty.BrowserOpened) if status is None: return False return status
def download_file(link_locator, destination_folder=None): """Download a file from a link URL Arguments: link_locator - the locator of the link which should contain an href attribute destination_folder - the optional destination location of the downloaded file """ # get selenium2library reference s2l = get_s2l() # get the download URL from the link url = s2l._element_find(link_locator, True, True).get_attribute("href") # if the folder is not specified, default to the current execution # directory if destination_folder is None: destination_folder = test_data.get_variable("EXECDIR") # create the destination path if it doesn't exist if not os.path.exists(destination_folder): os.makedirs(destination_folder) # obtain the cookies and session ID from Selenium, copy the cookies into a # dict, and issue the request cookies = {} all_cookies = s2l._cache.current.get_cookies() for s_cookie in all_cookies: cookies[s_cookie["name"]] = s_cookie["value"] # perform the request r = requests.get(url, cookies=cookies, headers={'auth': cookies['token']}, verify=False) # validate the status if r.status_code != 200: raise FatalError("File download status code was '{0}'".format( r.status_code)) # get file info file_length = long(r.headers['content-length']) filename = r.headers['content-disposition'].split("; ")[1].split( "=")[1].strip('"') local_path = join(destination_folder, filename) # if the file exists, then append (1) while os.path.exists(local_path): tok = list(os.path.splitext(local_path)) tok[0] += "(1)" local_path = join(destination_folder, "".join(tok)) # download the file logger._debug("Downloading '{0}' to {1} - ({2} bytes)".format( filename, local_path, file_length)) try: lf = open(local_path, 'wb') for chunk in r.iter_content(chunk_size=1024): if chunk: # filter out keep-alive new chunks lf.write(chunk) lf.flush() lf.close() # validate the file size local_file_length = os.path.getsize(local_path) if local_file_length != file_length: raise FatalError( "Download file size doesn't match. Should be {0}. Was {1}". format(file_length, local_file_length)) else: logger._debug("Successfully downloaded {0} ({1} bytes)".format( local_path, local_file_length)) except: raise FatalError("Failed to download '{0}' to '{1}'".format( filename, local_path))
def get_logged_user(): """ get_logged_user Description : Function used for retrieving the logged in user. If no user is logged in, it will return None. """ return test_data.get_variable(test_data.GlobalProperty.UiLoggedIn)
def create_fcoe_network(*net_obj): """ Create FCoE Network Arguments: name* -- Name of FCoE network as a string. vlan -- VLAN ID string. Set only if vlan_tag is 'Tagged'. maxbandswdth -- Maximum bandwidth. Should be greater than 'preferredbw' argument. Defaults to 10 Gb/s. preferredbw -- Preferred Bandwidth. Defaults to 2.5 Gb/s. san -- Associated SAN. * Required Arguments Example: <myNetworks> <network name="300" vlan="300" maxbandwdth="10" san="wpstsw9_FID120-10:00:00:27:f8:2e:e8:98"/> </myNetworks> """ s2l = ui_lib.get_s2l() if not ui_lib.wait_for_element(FusionNetworksPage.ID_PAGE_LABEL): navigate() logger._log_to_console_and_log_file("Create FCoE network") if isinstance(net_obj, test_data.DataObj): net_obj = [net_obj] elif isinstance(net_obj, tuple): net_obj = list(net_obj[0]) ui_lib.wait_for_element_and_click( FusionNetworksPage.ID_LINK_CREATE_NETWORK) ui_lib.wait_for_element(FusionNetworksPage.ID_INPUT_NETWORK_NAME) for net in net_obj: logger._log_to_console_and_log_file("") # Set network Name ui_lib.wait_for_element_and_input_text( FusionNetworksPage.ID_INPUT_NETWORK_NAME, net.name) # Select Ethernet Type s2l.select_checkbox(FusionNetworksPage.ID_RADIO_FCOE_TYPE) # Associating SAN with network for automation of zoning on the networks if not (net.san).upper() == "": ui_lib.wait_for_element_and_click( FusionNetworksPage.ID_COMBO_ASSOCIATE_SAN) CreateNetworks.input_select_associate_with_san(net.san) else: logger._log_to_console_and_log_file("SAN not specified") if net.has_property("vlan"): ui_lib.wait_for_element_and_input_text( FusionNetworksPage.ID_INPUT_NETWORK_VLAND_ID, net.vlan) else: ui_lib.fail_test("Vlan ID not specified.") # Set Preferred bandwidth if net.has_property('preferredbw'): net.preferredbw = float(net.preferredbw) if not ((net.preferredbw >= BW_MIN) and (net.preferredbw <= BW_MAX)): ui_lib.fail_test( "Invalid Preferred Bandwidth value specified (%s). Should be between %s and %s" % (net.preferredbw, BW_MIN, BW_MAX)) else: ui_lib.wait_for_element_and_input_text( FusionNetworksPage.ID_INPUT_NETWORK_PREF_BANDWIDTH, str(net.preferredbw)) else: # Use Default Bandwidth value net.preferredbw = float(DEFAULT_PREFERRED_BW) # Set Max bandwidth if net.has_property('maxbandwdth'): net.maxbandwdth = float(net.maxbandwdth) if not ((net.maxbandwdth >= BW_MIN) and (net.maxbandwdth <= BW_MAX)): ui_lib.fail_test( "Invalid Max Bandwidth value specified (%s). Should be between %s and %s" % (net.maxbandwdth, BW_MIN, BW_MAX)) elif not net.maxbandwdth >= net.preferredbw: ui_lib.fail_test( "Invalid Max Bandwidth value specified (%s). Should be greater than Preferred Bandwidth (%s)" % (net.maxbandwdth, net.preferredbw)) else: ui_lib.wait_for_element_and_input_text( FusionNetworksPage.ID_INPUT_NETWORK_MAXS_BANDWIDTH, str(net.maxbandwdth)) # Click on the create plus button s2l.click_button(FusionNetworksPage.ID_BTN_CREATE_NETWORK_PLUS) s2l.page_should_not_contain("Failed to add fcoe network") if s2l._page_contains("Unable to add fcoe network"): ui_lib.fail_test("Unable to add fcoe network '{0}': {1}".format( net.name, s2l._get_text( FusionNetworksPage.ID_CREATE_NETWORK_MESSAGE_DETAILS))) else: logger._log_to_console_and_log_file( "Successfully created FCOE network %s" % net.name) ui_lib.wait_for_condition(lambda: s2l._get_value( FusionNetworksPage.ID_INPUT_NETWORK_NAME) == "", fail_if_false=True) # Close Network Dialog s2l.click_button(FusionNetworksPage.ID_BTN_CLOSE_NETWORK) ui_lib.wait_for_element_remove(FusionNetworksPage.ID_CREATE_NETWORK_DIALOG) # perform validation if required if test_data.get_variable("Validate"): validate_network_exists(net_obj, fail_if_false=False)