Best Python code snippet using robotframework-appiumlibrary_python
CustomLib.py
Source:CustomLib.py
...30 self.select_from_list_by_index(select, str(index))31 @keyword32 def search_component_in_component_list_by_title_name(self, name):33 i = 034 componentList = self.get_webelements("css:#list-table tr")35 while len(componentList) < 2:36 time.sleep(0.5)37 componentList = self.get_webelements("css:#list-table tr")38 if i == 5:39 self.failure_occurred()40 break41 else:42 i = i + 143 for element in componentList:44 if (len(element.find_elements_by_css_selector("p.text")) > 0):45 if (self.get_text(element.find_element_by_css_selector("p.text")) == name):46 return element47 self.failure_occurred()48 @keyword49 def return_child_element_from_parent(self, element, query):50 if(str(query).__contains__("css:")):51 query = str(query).replace("css:", "")52 print(query)53 return element.find_element_by_css_selector(query)54 @keyword55 def input_filter_description(self):56 cond = "input"57 while len(self.get_webelements("css:input[name='chose-opt']")) == 0:58 if len(self.get_webelements("css:select[name='chose-opt']")) > 0:59 cond = "select"60 break61 time.sleep(0.5)62 if (cond.__eq__("input")):63 self.input_text('css:.make-filter input[name="chose-opt"]', "Filter description")64 else:65 self.select_from_list_random('css:.make-filter select[name="chose-opt"]')66 @keyword67 def wait_until_element_loses_attribute(self, locator, attribute):68 i = 069 while str(self.get_element_attribute(locator, attribute)).__eq__("true"):70 time.sleep(0.5)71 if i == 5:72 self.failure_occurred()73 break74 i = i + 175 76 @keyword77 def say_no_to_register_highlight_to_a_page(self):78 if(str(self.get_location()).__contains__("carousel-form")):79 self.wait_until_element_is_visible("css:#modalReplaceHl")80 self.click_element("css:.no-replace")81 82 @keyword83 def return_random_element_with_selector_from_list(self, selector):84 i = 085 elementList = self.get_webelements(selector)86 while len(elementList) <= 1:87 time.sleep(0.5)88 elementList = self.get_webelements(selector)89 if i == 5:90 self.failure_occurred()91 break92 i = i + 193 index = randint(1, len(elementList) - 1)94 return elementList[index]95 96 @keyword97 def return_element_with_selector_from_list_by_index(self, selector, index):98 i = 099 elementList = self.get_webelements(selector)100 while len(elementList) <= 1:101 time.sleep(0.5)102 elementList = self.get_webelements(selector)103 if i == 5:104 self.failure_occurred()105 break106 i = i + 1107 return elementList[int(index)]108 109 @keyword110 def element_list_should_be_equals_or_higher_then_length(self, selector, length):111 elementList = self.get_webelements(selector)112 if(len(elementList) >= int(length)):113 print("validation passed: list length equals or higher then sended length")114 else:115 self.failure_occurred()116 @keyword117 def return_highlight_carousel_from_page_creation_page(self):118 i = 0119 while len(self.get_webelements("css:#source-carousel tr")) < 0:120 time.sleep(0.5)121 if i == 5:122 self.failure_occurred()123 break124 i = i + 1125 carouselsList = self.get_webelements("css:#source-carousel tr")126 for carousel in carouselsList:127 if(self.get_text(carousel.find_element_by_css_selector("span.type")).__contains__("Hero")):128 print("achei highlight")129 return carousel130 print("nao achei highlight")131 self.failure_occurred()132 133 @keyword134 def drag_comom_carousel_into_phone_viewer(self, carouselCont):135 i = 0136 while len(self.get_webelements("css:#source-carousel tr")) < 0:137 time.sleep(0.5)138 if i == 5:139 self.failure_occurred()140 break141 i = i + 1142 carouselsList = self.get_webelements("css:#source-carousel tr")143 for carousel in carouselsList:144 if(self.get_text(carousel.find_element_by_css_selector("span.type")).__contains__("Hero")):145 carouselsList.remove(carousel)146 i = 0147 while i < int(carouselCont):148 index = randint(0, len(carouselsList) - 1)149 self.drag_and_drop(carouselsList[index], "css:tfoot .area-new-carrossel")150 carouselsList.remove(carouselsList[index])151 i = i + 1152 time.sleep(0.2)153 154 @keyword155 def return_parent_element_from_child(self, selector):156 self.wait_until_page_contains_element(selector)157 return self.get_webelement(selector).find_element_by_xpath('parent::*')158 159 @keyword160 def select_content_by_number(self, contentCont):161 i = 1162 lim = 0163 contentList = self.get_webelements("css:.filme-item .ck-mark")164 while len(self.get_webelements("css:.filme-item .ck-mark")) <= 1:165 time.sleep(0.5)166 lim = lim + 1167 if lim == 5:168 self.failure_occurred()169 break170 contentList = self.get_webelements("css:.filme-item .ck-mark")171 for content in contentList:172 self.click_element(content)173 if(int(contentCont) == i):174 break175 else:176 i = i + 1177 178 @keyword179 def return_content_in_catalog_by_title(self, title):180 i = 0181 while len(self.get_webelements("css:.filme-item")) < 1:182 time.sleep(0.5)183 i = i + 1184 if i == 5:185 self.failure_occurred()186 break187 contentList = self.get_webelements("css:.filme-item")188 for content in contentList:189 contentTitle = self.get_text(content.find_element_by_css_selector("h4"))190 if title.__eq__(contentTitle):191 return content192 193 @keyword194 def list_should_contain(self, listValues, param):195 if not(listValues.__contains__(param)):196 self.failure_occurred()197 198 @keyword199 def return_all_values_from_select(self, select):200 element = self.get_webelement(select)201 listValues = []...
tasks.py
Source:tasks.py
...39 browser.wait_until_element_is_visible(TABLE_SELECTOR, TIMEOUT)40 browser.select_from_list_by_label(TABLE_SELECTOR, "All")41 browser.wait_until_page_does_not_contain_element(SECOND_PAGE, TIMEOUT)42 browser.execute_javascript("document.querySelector('.dataTables_scrollBody').scrollTop=1500")43 uii = [browser.get_text(elem) for elem in browser.get_webelements(UII_COLUMN)]44 bureau = [browser.get_text(elem) for elem in browser.get_webelements(BUREAU_COLUMN)]45 total = [browser.get_text(elem) for elem in browser.get_webelements(TOTAL_COLUMN)]46 title = [browser.get_text(elem) for elem in browser.get_webelements(TITLE_COLUMN)]47 type = [browser.get_text(elem) for elem in browser.get_webelements(TYPE_COLUMN)]48 rating = [browser.get_text(elem) for elem in browser.get_webelements(RATING_COLUMN)]49 num_of_projects = [browser.get_text(elem) for elem in browser.get_webelements(NUM_COLUMN)]50 return {"UII": uii, "Bureau": bureau, "Total": total, "Title": title, "Type": type, "Rating": rating,51 "# of Projects": num_of_projects}52def get_agencies_names():53 browser.wait_until_element_is_visible(DEPT_NAME)54 names = [browser.get_text(elem) for elem in browser.get_webelements(DEPT_NAME)]55 return names56def get_agencies_totals():57 browser.wait_until_element_is_visible(DEPT_VALUE)58 values = [browser.get_text(elem) for elem in browser.get_webelements(DEPT_VALUE)]59 return values60def write_depts_data_to_excel(agencies=None, totals=None, path=DEFAULT_XLS_PATH):61 try:62 xls.create_workbook(path)63 data = table.create_table({"Departments": agencies, "Totals": totals})64 xls.append_rows_to_worksheet(data, header=True)65 xls.save_workbook()66 finally:67 xls.close_workbook()68def download_available_pdfs():69 browser.set_download_directory(DOWNLOADS_DIR)70 urls = [browser.get_element_attribute(elem, "href") for elem in browser.get_webelements(UII_COLUMN_URLS)]71 for url in urls:72 browser.open_available_browser(url)73 browser.click_element_when_visible(PDF_LINK)74def write_individual_investments_data(data=None, path=DEFAULT_XLS_PATH):75 try:76 xls.open_workbook(path)77 xls.create_worksheet("Individual Investments")78 data = table.create_table(data)79 xls.append_rows_to_worksheet(data, header=True)80 xls.save_workbook()81 finally:82 xls.close_workbook()83def main():84 try:...
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!!