How to use _current_application method in robotframework-appiumlibrary

Best Python code snippet using robotframework-appiumlibrary_python

CustomAndroidCrosswalk.py

Source:CustomAndroidCrosswalk.py Github

copy

Full Screen

...26 self._debug('Opened application with session id %s' % application.session_id)27 return self._cache.register(application, alias)28########################################29 def input_and_submit(self, id, text):30 driver = self._current_application()31 if text == '' or id == '':32 return False33 else:34 try:35 element = driver.find_element_by_id(id)36 element.clear()37 element.send_keys(text)38 driver.press_keycode(66)39 except:40 print('[input_and_submit] id error')41########################################42 def input_and_send(self, id, text):43 driver = self._current_application()44 if text == '' or id == '':45 return False46 else:47 try:48 element = driver.find_element_by_id(id)49 element.clear()50 send_key = element.send_keys(text)51 #return send_key52 except:53 print('[input_and_send] id error')54########################################55 def press_enter(self):56 driver = self._current_application()57 chain = ActionChains(driver)58 chain.send_keys(u'\ue007').perform()59 #http://selenium-python.readthedocs.org/en/latest/api.html60########################################61 def press_return(self):62 driver = self._current_application()63 chain = ActionChains(driver)64 chain.send_keys(u'\ue006').perform()65########################################66 def press_back(self):67 driver = self._current_application()68 chain = ActionChains(driver)69 chain.send_keys(u'\ue100').perform()70########################################71 def page_down(self):72 driver = self._current_application()73 chain = ActionChains(driver)74 chain.send_keys(u'\ue015').perform()75 chain.send_keys(u'\ue00f').perform()76 #\uE00E = up77 #\uE00F = down78########################################79 def page_flick(self, start_locator, end_locator):80 driver = self._current_application()81 el1 = self._element_find(start_locator, True, True)82 el2 = self._element_find(end_locator, True, True)83 action = TouchActions(driver)84 action.long_press(el1).move_to(el2).release().perform()85########################################86 def input_web_element(self, locator, text):87 element = self._element_find(locator, True, True)88 element.send_keys(text)89########################################90 def switch_to_webview(self, text):91 driver = self._current_application()92 driver.switch_to.context(text)93########################################94 def switch_to_currentwebview(self):95 driver = self._current_application()96 currentwebview = driver.contexts.last97 driver.switch_to.context(currentwebview)98########################################99 def restart_chromedriver(self):100 os.system("ps -ef | grep /Users/fenni/Desktop/Fenni/Automation/Patch_Chromedriver/out/Release/chromedriver | grep -v grep |grep -e '--port=9515\(\s.*\)\?$' | awk '{ print $2 }' | xargs kill -15")101 time.sleep(20)102########################################103 def switch_to_frame(self, text):104 driver = self._current_application()105 driver.switch_to.frame(text)106########################################107 def switch_to_native(self):108 driver = self._current_application()109 driver.switch_to.context('NATIVE_APP')110########################################111 def paste(self):112 #element = self._element_find(locator, True, True)113 #element.send_keys(text)114 #element.send_keys(Keys.CONTROL, 'v') #paste115 #driver = self._current_application()116 chain = ActionChains(driver)117 chain.send_keys(u'\ue03d', u'\ue009', 'v').perform()118########################################119 def print_status(self):120 driver = self._current_application()121 print(driver.current_activity)122 print(driver.context)123 print(driver.contexts)124########################################125 def wait_for_element_id(self, text):126 driver = self._current_application()127 wait_second = 0128 if text == '':129 return False130 while wait_second >= 0:131 try:132 if text != '':133 element = driver.find_element_by_id(text)134 is_find = 1135 break136 except:137 element = None138 wait_second += 1139 time.sleep(1)140 print('Wait for element id finished!')141 if is_find == 1:142 return 1143 else:144 return 0145########################################146 def find_for_element_id(self, text):147 driver = self._current_application()148 wait_second = 0149 if text == '':150 return False151 while wait_second >= 0:152 try:153 if text != '':154 element = driver.find_element_by_id(text)155 if element:156 is_find = 1157 break158 else:159 is_find = 0160 break161 except:162 element = None163 print('element = none!')164 is_find = 0165 break166 print('Find for element id finished!')167 if is_find == 1:168 return 1169 else:170 return 0171########################################172 def wait_for_element_id_disappear(self, text):173 driver = self._current_application()174 wait_second = 0175 if text == '':176 return False177 while wait_second >= 0:178 try:179 if text != '':180 element = driver.find_element_by_id(text)181 if element:182 is_disappear = 0183 wait_second += 1184 time.sleep(1)185 else:186 is_disappear = 1187 break188 except:189 element = None190 is_disappear = 1191 break192 print('Wait for element id disappeared!')193 if is_disappear == 1:194 return 1195 else:196 return 0197########################################198 def tap_element(self, xpath):199 driver = self._current_application()200 element = driver.find_element_by_xpath(xpath)...

Full Screen

Full Screen

customappium.py

Source:customappium.py Github

copy

Full Screen

...6from robot.libraries.BuiltIn import BuiltIn7@keyword(name="Switch Frame By Id")8def switch_frame_by_id(frame_locator: str):9 appium_library: AppiumLibrary = BuiltIn().get_library_instance('AppiumLibrary')10 driver: webdriver = appium_library._current_application()11 if driver is None:12 print("driver not initialised")13 else:14 frame_element = driver.find_element(MobileBy.ID, "pgsIframe")15 print(frame_element)16 driver.switch_to.frame(frame_element)17@keyword(name="Switch Frame By XPath")18def switch_frame_by_xpath(frame_locator: str):19 appium_library: AppiumLibrary = BuiltIn().get_library_instance('AppiumLibrary')20 driver: webdriver = appium_library._current_application()21 if driver is None:22 print("driver not initialised")23 else:24 frame_element = driver.find_element_by_xpath(frame_locator)25 driver.switch_to.frame(frame_element)26@keyword(name="Switch To Default Frame")27def switch_to_default_frame():28 appium_library: AppiumLibrary = BuiltIn().get_library_instance('AppiumLibrary')29 driver: webdriver = appium_library._current_application()30 if driver is None:31 print("driver not initialised")32 else:33 driver.switch_to.default_content()34@keyword(name="Scroll To Element")35def scroll_element_into_view(element: webelement):36 appium_library: AppiumLibrary = BuiltIn().get_library_instance('AppiumLibrary')37 driver: webdriver = appium_library._current_application()38 if driver is None:39 print("driver not initialised")40 else:41 driver.execute_script("arguments[0].scrollIntoView();", element)42@keyword(name="Click Element Using JS")43def click_element(element: webelement):44 appium_library: AppiumLibrary = BuiltIn().get_library_instance('AppiumLibrary')45 driver: webdriver = appium_library._current_application()46 if driver is None:47 print("driver not initialised")48 else:49 driver.execute_script("arguments[0].click();", element)50@keyword(name="Mouse Over On Element")51def hover_on_element(element: webelement):52 appium_library: AppiumLibrary = BuiltIn().get_library_instance('AppiumLibrary')53 driver: webdriver = appium_library._current_application()54 if driver is None:55 print("driver not initialised")56 else:...

Full Screen

Full Screen

custom.py

Source:custom.py Github

copy

Full Screen

...5from selenium.webdriver.common.by import By6from selenium.webdriver.support import expected_conditions as EC7class custom(AppiumLibrary):8 def get_driver_instance(self):9 return self._current_application()10 def CustomWithAccessibilityID(self, element)->None:11 #wait for element in DOM12 self._current_application().implicitly_wait(3)13 #wait for condition of Element (make )14 WebDriverWait(self._current_application(), 10).until(EC.presence_of_element_located((MobileBy.ACCESSIBILITY_ID, element)))15 el = self._current_application().find_element(MobileBy.ACCESSIBILITY_ID,element)16 el.click()17 print(el)18 def CheckAppState(self,packageName):19 return self._current_application().query_app_state(packageName)...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run robotframework-appiumlibrary automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful