Best Python code snippet using robotframework-appiumlibrary_python
PageFunction_XML.py
Source: PageFunction_XML.py
...20 self.function_name = function_name21 self.element_location = element_location22 def get_function_name(self):23 return self.function_name24 def get_element_location(self):25 return self.element_location26def ReadXMlData(xmlPath, parent):27 '''读åé
ç½®æ件ä¸çä¿¡æ¯ï¼å¹¶è¿åæ¯ä¸ªé¡¹ä¸ºä¸ä¸ª(name,element_location)çå表'''28 dom = xmlParser.parse(xmlPath)29 db = dom.documentElement30 data_list = []31 itemlist = db.getElementsByTagName(parent)32 for item in itemlist:33 it = ElementClass(item.getAttribute('Function_name'), item.getAttribute('Element_location'))34 data_list.append(it)35 return data_list36class MakeFunction(Base.Page):37 '''å建å
ç´ æä½æ¹æ³'''38 def make_function_click_by_xpath(self, element_location):39 def function_click_by_xpath():40 self.find_element(By.XPATH, element_location).click()41 return function_click_by_xpath42 def make_function_click_by_class_name(self, element_location):43 def function_click_by_class_name():44 self.find_element(By.CLASS_NAME, element_location).click()45 return function_click_by_class_name46 def make_function_send_keys(self,element_location):47 def function_send_keys(message):48 self.find_element(By.XPATH, element_location).send_keys(message)49 return function_send_keys50 def make_function_time_widget1(self,element_location):51 def function_time_widget(id_name, message):52 js = "document.getElementById('" + id_name + "').removeAttribute('readonly');"53 self.driver.execute_script(js)54 self.find_element(By.XPATH, element_location).send_keys(message)55 self.find_element(By.XPATH, element_location).click()56 return function_time_widget57 def make_function_time_widget2(self,element_location):58 def function_time_widget(id_name, message):59 js = "document.getElementById('" + id_name + "').removeAttribute('readonly');"60 self.driver.execute_script(js)61 self.find_element(By.XPATH, element_location).send_keys(message)62 return function_time_widget63 def make_function_hint(self, element_location):64 def function_hint():65 return self.find_element(By.XPATH, element_location).text 66 return function_hint67class FunctionFactory():68 '''åè½å·¥å'''69 def __init__(self, driver, xmlpath):70 self.FunctionMap = {}71 self.driver = driver72 self.InitClickByXpath(xmlpath,"FUNCTION_CLICK_BY_XPATH")73 self.InitClickByClassName(xmlpath, "FUNCTION_CLICK_BY_CLASS_NAME")74 self.InitSendMessage(xmlpath, "FUNCTION_SEND")75 self.InitTimeWidget1(xmlpath, "FUNCTION_TIME_WDIGET1")76 self.InitTimeWidget2(xmlpath, "FUNCTION_TIME_WDIGET2")77 self.InitHint(xmlpath, "FUNCTION_HINT")78 def InitClickByXpath(self, xmlpath, Parent):79 #åå§åç¹å»äºä»¶ï¼å¹¶ä¿åå¨FuncMapä¸80 listclickbyxpath = ReadXMlData(xmlpath, Parent)81 for list1 in listclickbyxpath:82 self.FunctionMap[list1.get_function_name()] = MakeFunction(self.driver).make_function_click_by_xpath(list1.get_element_location())83 def InitClickByClassName(self, xmlpath, Parent):84 #åå§åç¹å»äºä»¶ï¼å¹¶ä¿åå¨FuncMapä¸85 listclickbyclassname = ReadXMlData(xmlpath, Parent)86 for list1 in listclickbyclassname:87 self.FunctionMap[list1.get_function_name()] = MakeFunction(self.driver).make_function_click_by_class_name(list1.get_element_location())88 def InitSendMessage(self, xmlpath, Parent):89 #åå§åä¿¡æ¯è¾å
¥äºä»¶ï¼å¹¶ä¿åå¨FuncMapä¸90 listsSend = ReadXMlData(xmlpath, Parent)91 for list1 in listsSend:92 self.FunctionMap[list1.get_function_name()] = MakeFunction(self.driver).make_function_send_keys(list1.get_element_location())93 def InitTimeWidget1(self, xmlpath, Parent):94 #åå§åæ¶é´æ§ä»¶äºä»¶ï¼å¹¶ä¿åå¨FuncMapä¸95 listTimeWidget1 = ReadXMlData(xmlpath, Parent)96 for list1 in listTimeWidget1:97 self.FunctionMap[list1.get_function_name()] = MakeFunction(self.driver).make_function_time_widget1(list1.get_element_location())98 def InitTimeWidget2(self, xmlpath, Parent):99 #åå§åæ¶é´æ§ä»¶äºä»¶ï¼å¹¶ä¿åå¨FuncMapä¸100 listTimeWidget2 = ReadXMlData(xmlpath, Parent)101 for list1 in listTimeWidget2:102 self.FunctionMap[list1.get_function_name()] = MakeFunction(self.driver).make_function_time_widget2(list1.get_element_location())103 def InitHint(self, xmlpath, Parent):104 #åå§åå
ç´ éªè¯äºä»¶ï¼å¹¶ä¿åå¨FuncMapä¸105 listhint = ReadXMlData(xmlpath, Parent)106 for list1 in listhint:107 self.FunctionMap[list1.get_function_name()] = MakeFunction(self.driver).make_function_hint(list1.get_element_location())108 def RunClick(self, funcname):109 '''è¿è¡ç¹å»äºä»¶'''110 element = self.FunctionMap.get(funcname)111 element()112 def RunSendKeys(self, funcname, message):113 '''è¿è¡ä¿¡æ¯è¾å
¥äºä»¶'''114 element = self.FunctionMap.get(funcname)115 element(message)116 def RunTimeWidget(self, funcname, id_name, message):117 '''è¿è¡æ¶é´æ§ä»¶äºä»¶'''118 element = self.FunctionMap.get(funcname)119 element(id_name, message)120 def RunHint(self, funcname):121 '''è¿è¡å
ç´ éªè¯äºä»¶'''...
operate_yaml.py
Source: operate_yaml.py
...21 if self.data.get_find_locator(i) == 'normal':22 """è°ç¨actionç±»ä¸çæ¹æ³å®ç°å
ç´ æä½"""23 if self.data.get_return(i) == "single":24 if self.data.get_operate(i) == "send_keys":25 el = self.action.find_element(self.data.get_type(i), self.data.get_element_location(i))26 content = self.data.get_content(i)27 else:28 el = self.action.find_element(self.data.get_type(i), self.data.get_element_location(i))29 elif self.data.get_return(i) == "more":30 el = self.action.find_elements(self.data.get_type(i), self.data.get_element_location(i))31 elif self.data.get_find_locator(i) == 'android_uiautomator':32 if self.data.get_return(i) == "single":33 if self.data.get_operate(i) == "send_keys":34 el = self.action.find_byUiautormator(self.data.get_type(i), \35 self.data.get_element_location(i))36 content = self.data.get_content(i)37 else:38 el = self.action.find_byUiautormator(self.data.get_type(i), \39 self.data.get_element_location(i))40 elif self.data.get_return(i) == "more":41 el = self.action.find_elements_byUiautormator(self.data.get_type(i), \42 self.data.get_element_location(i))43 # else:44 # print("è¾å
¥çå
ç´ æè¿°ä¸è·åå°çæ°æ®ä¸ä¸è´")45 return el, content46 else:47 return "yamlæ件å
æ°æ®ä¸ºç©ºï¼"48# if __name__ == '__main__':49# data = operate_yaml(file_path).operate_yaml("请è¾å
¥å§å")50# print(type(data))...
Check out the latest blogs from LambdaTest on this topic:
Traditional software testers must step up if they want to remain relevant in the Agile environment. Agile will most probably continue to be the leading form of the software development process in the coming years.
Building a website is all about keeping the user experience in mind. Ultimately, it’s about providing visitors with a mind-blowing experience so they’ll keep coming back. One way to ensure visitors have a great time on your site is to add some eye-catching text or image animations.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Even though several frameworks are available in the market for automation testing, Selenium is one of the most renowned open-source frameworks used by experts due to its numerous features and benefits.
When software developers took years to create and introduce new products to the market is long gone. Users (or consumers) today are more eager to use their favorite applications with the latest bells and whistles. However, users today don’t have the patience to work around bugs, errors, and design flaws. People have less self-control, and if your product or application doesn’t make life easier for users, they’ll leave for a better solution.
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!!