Best Python code snippet using localstack_python
page_object.py
Source:page_object.py
1from selenium.webdriver.remote.webelement import WebElement2from selenium.webdriver.support import expected_conditions3from selenium.webdriver.support.ui import WebDriverWait4from locators import EnvironmentsLocators5from ui.pages.base_page import BasePage6from ui.main.constants import DEFAULT_PAGE_TIMEOUT7class Environments(BasePage):8 def wait_for_page_load(self):9 """10 Wait for the page to be fully loaded11 """12 WebDriverWait(self.browser, DEFAULT_PAGE_TIMEOUT).until(13 expected_conditions.presence_of_element_located(14 EnvironmentsLocators.ENVIRONMENTS_TITLE),15 'Environments page failed to load'16 )17 def get_environments_title(self):18 """19 Get Environments title20 :return: Environments title21 :rtype: WebElement22 """23 return self.browser.find_element(*EnvironmentsLocators.ENVIRONMENTS_TITLE)24 def get_environments_subheading(self):25 """26 Get Environments subheading27 :return: Environment subheading28 :rtype: WebElement29 """30 return self.browser.find_element(*EnvironmentsLocators.ENVIRONMENTS_SUBHEADING)31 def get_realm_box_by_name(self, name):32 """33 Get realm box34 :param name: name of the desired realm35 :type name: str36 :return: realm box37 :rtype: WebElement38 """39 return self.browser.find_element(*EnvironmentsLocators.get_realm_box_locator_by_name(name))40 def get_realm_heading_by_name(self, name):41 """42 Get realm heading43 :param name: name of the desired realm44 :type name: str45 :return: realm heading46 :rtype: WebElement47 """48 return self.browser.find_element(*EnvironmentsLocators.get_realm_heading_locator_by_name(name))49 def click_realm_heading_by_name(self, name):50 """51 Click realm heading52 """53 button = self.get_realm_heading_by_name(name)54 button.click()55 def get_realm_status_by_name(self, name):56 """57 Get realm status58 :param name: name of the desired realm59 :type name: str60 :return: realm status61 :rtype: WebElement62 """63 return self.browser.find_element(*EnvironmentsLocators.get_realm_status_locator_by_name(name))64 def get_realm_last_published_span_by_name(self, name):65 """66 Get realm last published span67 :param name: realm's name68 :type name: str69 :return: realm's last published span70 :rtype: WebElement71 """72 return self.browser.find_element(*EnvironmentsLocators.get_realm_last_published_span_locator_by_name(name))73 def get_realm_last_published_catalog_by_name(self, realm, catalog_code):74 """75 Get realm's last published catalog76 :param realm: name of the realm77 :type realm: str78 :param catalog_code: name of the catalog79 :type catalog_code: str80 :return: realm's last published catalog81 :rtype: WebElement82 """83 return self.browser.find_element(*EnvironmentsLocators.get_realm_last_published_catalog_by_name(84 realm,85 catalog_code86 ))87 def get_realm_last_published_catalog_title_by_name(self, realm, catalog_code):88 """89 Get realm's last published catalog's title90 :param realm: name of the realm91 :type realm: str92 :param catalog_code: name of the catalog93 :type catalog_code: str94 :return: realm's last published catalog's title95 :rtype: WebElement96 """97 return self.browser.find_element(*EnvironmentsLocators.get_realm_last_published_catalog_title_by_name(98 realm,99 catalog_code100 ))101 def get_realm_no_published_catalog_by_name(self, realm):102 """103 Get realm's no published catalog span104 :param realm: name of the realm105 :type realm: str106 :return: realm's no published catalog span107 :rtype: WebElement108 """109 return self.browser.find_element(*EnvironmentsLocators.get_realm_no_published_catalog_by_name(realm))110 def get_details_heading(self):111 """112 Get an appropriate heading for details table after clicking on specific realm box113 :return: details table heading114 :rtype: WebElement115 """116 return self.browser.find_element(*EnvironmentsLocators.DETAILS_HEADING)117 def get_details_status(self):118 """119 Get server status for details table120 :return: details server status121 :rtype: WebElement122 """123 return self.browser.find_element(*EnvironmentsLocators.DETAILS_STATUS)124 def get_details_catalogs_list(self):125 """126 Get an appropriate catalogs list in the details table after clicking on specific realm box127 :return: details table catalogs list128 :rtype: WebElement129 """130 return self.browser.find_elements(*EnvironmentsLocators.DETAILS_CATALOGS_LIST)131 def get_details_catalogs_header(self):132 """133 Get the catalogs header in the details table134 :return: details table catalogs header135 :rtype: WebElement136 """137 return self.browser.find_element(*EnvironmentsLocators.DETAILS_CATALOGS_HEADER)138 def get_details_last_published_button(self):139 """140 Get the last published button in the details table141 :return: details table last published button142 :rtype: WebElement143 """144 return self.browser.find_element(*EnvironmentsLocators.DETAILS_LAST_PUBLISHED_BUTTON)145 def get_details_catalog(self, catalog_code, publish_version, index):146 """147 Get a specific catalog in the details table148 :param catalog_code: name of the catalog149 :type catalog_code: str150 :param publish_version: publish version of the catalog151 :type publish_version: int152 :param index: row of the details table153 :type index: int154 :return: catalog in the details table155 :rtype: WebElement156 """157 return self.browser.find_element(*EnvironmentsLocators.get_details_catalog_by_name(158 catalog_code,159 publish_version,160 index161 ))162 def get_details_catalog_title(self, catalog_code, publish_version):163 """164 Get the title of a specific catalog in the details table165 :param catalog_code: name of the catalog166 :type catalog_code: str167 :param publish_version: publish version of the catalog168 :type publish_version: int169 :return: title of a catalog in the details table170 :rtype: WebElement171 """172 return self.browser.find_element(*EnvironmentsLocators.get_details_catalog_title_by_name(173 catalog_code,174 publish_version175 ))176 def get_details_catalog_actions_menu(self, catalog_code, publish_version, index):177 """178 Get the actions menu of a specific catalog in the details table179 :param catalog_code: name of the catalog180 :type catalog_code: str181 :param publish_version: publish version of the catalog182 :type publish_version: int183 :param index: row of the details table184 :type index: int185 :return: actions menu of a catalog in the details table186 :rtype: WebElement187 """188 return self.browser.find_element(*EnvironmentsLocators.get_details_catalog_actions_menu_by_name(189 catalog_code,190 publish_version,191 index192 ))193 def click_details_catalog_actions_menu(self, catalog_code, publish_version, index):194 """195 Click the actions menu button of a specific catalog in the details table196 :param catalog_code: name of the catalog197 :type catalog_code: str198 :param publish_version: publish version of the catalog199 :type publish_version: int200 :param index: row of the details table201 :type index: int202 """203 button = self.get_details_catalog_actions_menu(catalog_code, publish_version, index)204 button.click()205 def get_details_close_button(self):206 """207 Get the close button in the details table208 :return: details table close button209 :rtype: WebElement210 """211 return self.browser.find_element(*EnvironmentsLocators.DETAILS_CLOSE_BUTTON)212 def click_details_close_button(self):213 """214 Click the close button in the details table215 """216 button = self.get_details_close_button()...
locators.py
Source:locators.py
1from selenium.webdriver.common.by import By2class EnvironmentsLocators(object):3 ENVIRONMENTS_TITLE = (By.ID, 'environments_top_bar_heading')4 ENVIRONMENTS_SUBHEADING = (By.ID, 'environments_top_bar_sub_heading_top')5 DETAILS_HEADING = (By.ID, 'details_header')6 DETAILS_STATUS = (By.ID, 'details_sub_header')7 DETAILS_CATALOGS_LIST = (By.ID, 'details_list')8 DETAILS_CATALOGS_HEADER = (By.ID, 'details_catalog_list_header')9 DETAILS_LAST_PUBLISHED_BUTTON = (By.XPATH, "//button[@class='diagram__orderButton___1VIoW']")10 DETAILS_CLOSE_BUTTON = (By.XPATH, "//button[@class='diagram__closeButton___3gQpB']")11 @staticmethod12 def get_realm_box_locator_by_name(name):13 """14 Get the locator for the realm box based on the display name15 :param name: realm name shown on the box16 :type name: str17 :return: locator for the realm's box18 :rtype: (By, str)19 """20 return By.ID, "box_{}".format(name)21 @staticmethod22 def get_realm_heading_locator_by_name(name):23 """24 Get the locator for the realm heading based on the display name25 :param name: realm name shown on the box26 :type name: str27 :return: locator for the realm's heading on the box28 :rtype: (By, str)29 """30 return By.ID, "heading_span_{}".format(name)31 @staticmethod32 def get_realm_status_locator_by_name(name):33 """34 Get the locator for the realm status based on the display name35 :param name: realm name shown on the box36 :type name: str37 :return: locator for the realm's status on the box38 :rtype: (By, str)39 """40 return By.ID, "subheading_server_status_{}".format(name)41 @staticmethod42 def get_realm_last_published_span_locator_by_name(name):43 """44 Get the locator for the realm last published span45 :param name: realm name46 :type name: str47 :return: locator for the realm's last published span on the box48 :rtype: (By, str)49 """50 return By.ID, 'subheading_span_last_published_{}'.format(name)51 @staticmethod52 def get_realm_last_published_catalog_by_name(realm, catalog_code):53 """54 Get the locator for the realm last published catalog55 :param realm: realm name56 :type realm: str57 :param catalog_code: name of the catalog58 :type catalog_code: str59 :return: locator of the last published catalog for the realm60 :rtype: (By, str)61 """62 return By.ID, 'subheading_code_{}_{}'.format(catalog_code, realm)63 @staticmethod64 def get_realm_last_published_catalog_title_by_name(realm, catalog_code):65 """66 Get the locator for the realm last published catalog's title67 :param realm: realm name68 :type realm: str69 :param catalog_code: name of the catalog70 :type catalog_code: str71 :return: locator of the last published catalog's title for the realm72 :rtype: (By, str)73 """74 return By.ID, 'subheading_title_{}_{}'.format(catalog_code, realm)75 @staticmethod76 def get_realm_no_published_catalog_by_name(realm):77 """78 Get the locator for the realm no published catalog span79 :param realm: realm name80 :type realm: str81 :return: locator of the no published catalog span82 :rtype: (By, str)83 """84 return By.ID, 'subheading_span_no_catalogs_{}'.format(realm)85 @staticmethod86 def get_details_catalog_by_name(catalog_code, publish_version, index):87 """88 Get the locator for a specific details table catalog89 :param catalog_code: name of the catalog90 :type catalog_code: str91 :param publish_version: publish version of the catalog92 :type publish_version: int93 :param index: row of the details table94 :type index: int95 :return: locator of a catalog in the details table list96 :rtype: (By, str)97 """98 return By.ID, 'subheading_code_{}_{}_{}'.format(catalog_code, index, publish_version)99 @staticmethod100 def get_details_catalog_title_by_name(catalog_code, publish_version):101 """102 Get locator for a specific details table catalog's table103 :param catalog_code: name of the catalog104 :type catalog_code: str105 :param publish_version: publish version of the catalog106 :type publish_version: int107 :return: locator of a catalog's title in the details table list108 :rtype: (By, str)109 """110 return By.ID, 'subheading_title_{}_{}'.format(catalog_code, publish_version)111 @staticmethod112 def get_details_catalog_actions_menu_by_name(catalog_code, publish_version, index):113 """114 Get the locator for a specific details table catalog's actions menu115 :param catalog_code: name of the catalog116 :type catalog_code: str117 :param publish_version: publish version of the catalog118 :type publish_version: int119 :param index: row of the details table120 :type index: int121 :return: locator of a catalog's actions menu in the details table list122 :rtype: (By, str)123 """...
deploy_service.py
Source:deploy_service.py
...9import time10import urllib11s3 = boto3.client('s3')12_lambda = boto3.client('lambda')13def publish_version(metadata):14 try:15 _lambda.publish_version(16 FunctionName=metadata['name'],17 Description=metadata['metadata'])18 except Exception, e:19 raise Exception("Error while trying to publish a new version - {0}".format(20 e))21def update_lambda_code(metadata):22 try:23 _lambda.update_function_code(24 FunctionName=metadata['name'],25 S3Bucket=metadata['bucket'],26 S3Key=metadata['object'],27 Publish=metadata['publish'])28 except Exception, e:29 raise Exception("Error while trying to update a new version - {0}".format(30 e))31 publish_version(metadata)32def get_metadata(bucket, obj):33 try:34 print(obj)35 print(bucket)36 ret = s3.head_object(37 Bucket=bucket,38 Key=obj39 )40 metadata = ret['Metadata']['description']41 return metadata42 except Exception, e:43 raise Exception("Error while trying to gather object metadata - {0}".format(44 e))45def lambda_handler(event, context):...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!