Best Python code snippet using fMBT_python
test_android.py
Source:test_android.py
1# coding=utf-82"""3@author:songmengyun4@file: test_android.py5@time: 2019/12/256"""7import pytest8import time9import logging10from appium import webdriver11from appium.webdriver.common.touch_action import TouchAction12from selenium.webdriver.support.wait import WebDriverWait13from appium.webdriver.connectiontype import ConnectionType14from collections import namedtuple15from poseidon.ui.mobile.android.init_driver import init_driver16'''17Android 6.0 18å
ååçé¢å19设置ï¼com.android.settings/.Settings20çä¿¡ï¼com.android.messaging/.ui.conversationlist.ConversationListActivity21ç³»ç»æµè§å¨ï¼com.android.browser/.BrowserActivity22è系人ï¼com.android.contacts/.activities.PeopleActivity23è±è¯å£è¯700å¥ï¼com.hj.kouyu700/com.hujiang.browser.JSWebViewActivity24cctalkç»å½é¡µé¢ï¼com.hujiang.cctalk/com.hujiang.browser.view.X5HJWebViewActivity25å®æºå¸åºï¼cn.goapk.market/com.anzhi.market.ui.MainActivity26京ä¸ï¼com.jingdong.app.mall/.main.MainActivity27'''28Device = namedtuple('device_info', ['platformName', 'platformVersion', 'deviceName'])29App = namedtuple('app_info', ['appPackage', 'appActivity'])30class TestAndroid:31 @classmethod32 def setup_class(cls):33 """ setup any state specific to the execution of the given class (which usually contains tests).34 """35 logging.info('setup_class'.center(50, "*"))36 cls.device_and_6 = Device('Android', '6.0', '192.168.57.103:5555') # éè¦è¿æ¥å¹³å°å称ï¼ä¸åºå大å°å37 cls.app_setting = App('com.android.settings', '.Settings') # å¹³å°ççæ¬[5.4.3/5.4/5]38 cls.app_mis = App('com.android.messaging', '.ui.conversationlist.ConversationListActivity') # 设å¤çå称ï¼é便åï¼ä½ä¸è½ä¸ºç©º39 cls.app_anzi = App('cn.goapk.market', 'com.anzhi.market.ui.MainActivity') # éè¦æå¼çåºç¨å称ï¼å¯éè¿ adb shell dumpsys window windows | grep mFocusedApp è·å40 cls.app_lock = App('com.android.settings', '.ChooseLockPattern') # éè¦æå¼ççé¢å称41 @classmethod42 def teardown_class(cls):43 """ teardown any state that was previously setup with a call to setup_class.44 """45 logging.info('teardown_class'.center(50, "*"))46 def setup_method(self, method):47 """ ææcaseåå§åæä½ """48 logging.info('setup_method'.center(50, '*'))49 desired_caps = {50 'platformName': 'Android',51 'deviceName': '192.168.57.103:5555',52 'platformVersion': '6.0',53 'appPackage': 'com.android.settings',54 'appActivity': '.Settings',55 'newCommandTimeout': '120',56 'noSign': True57 }58 self.driver = init_driver(desired_caps, command_executor='http://localhost:4723/wd/hub')59 def teardown_method(self, method):60 logging.info('teardown_method'.center(50, '*'))61 self.driver.quit()62 def test_start_activity(self):63 '''æå¼å
¶ä»appï¼ setup/teardown'''64 time.sleep(3)65 self.driver.start_activity(self.app_mis.appPackage, self.app_mis.appActivity)66 def test_get_package_activity(self):67 '''è·åå½åç¨åºå
ååçé¢å'''68 time.sleep(3)69 # è¾åºå½åç¨åºå
ååçé¢å70 print(self.driver.current_package)71 print(self.driver.current_activity)72 # åæ¢å°ç信页é¢73 desired_caps = dict() # åå§ååå
¸74 desired_caps['platformName'] = self.device_and_6.platformName # éè¦è¿æ¥å¹³å°å称ï¼ä¸åºå大å°å75 desired_caps['platformVersion'] = self.device_and_6.platformVersion # å¹³å°ççæ¬[5.4.3/5.4/5]76 desired_caps['deviceName'] = self.device_and_6.deviceName # 设å¤çå称ï¼é便åï¼ä½ä¸è½ä¸ºç©º77 desired_caps['appPackage'] = self.app_mis.appPackage # éè¦æå¼çåºç¨å称ï¼å¯éè¿ adb shell dumpsys window windows | grep mFocusedApp è·å78 desired_caps['appActivity'] = self.app_mis.appActivity # éè¦æå¼ççé¢å称79 driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)80 time.sleep(3)81 # è¾åºçä¿¡ç¨åºå
ååçé¢å82 print(driver.current_package)83 print(driver.current_activity)84 def test_close_quit_app(self):85 '''å
³éå½åapp/å
³é驱å¨'''86 time.sleep(3)87 # self.driver.close_app()88 print(self.driver.current_package)89 print(self.driver.current_activity)90 print(self.driver.context)91 print(self.driver.contexts)92 print(self.driver.current_context)93 time.sleep(5)94 # self.driver.quit()95 # print(self.driver.current_package)96 # print(self.driver.current_activity)97 def test_install_uninstall_check(self):98 '''å®è£
åå¸è½½app'''99 desired_caps = dict() # åå§ååå
¸100 desired_caps['platformName'] = self.device_and_6.platformName # éè¦è¿æ¥å¹³å°å称ï¼ä¸åºå大å°å101 desired_caps['platformVersion'] = self.device_and_6.platformVersion # å¹³å°ççæ¬[5.4.3/5.4/5]102 desired_caps['deviceName'] = self.device_and_6.deviceName # 设å¤çå称ï¼é便åï¼ä½ä¸è½ä¸ºç©º103 driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)104 time.sleep(3)105 # å¤æå®æºå¸åºæ¯å¦å·²ç»å®ç½®106 if driver.is_app_installed(self.app_anzi.appPackage):107 driver.remove_app(self.app_anzi.appPackage)108 else:109 driver.install_app('/Users/songmengyun/Downloads/testing/appium/anzhishichang_6630.apk')110 time.sleep(3)111 driver.quit()112 def test_background(self):113 '''åå°è¿è¡app'''114 desired_caps = dict() # åå§ååå
¸115 desired_caps['platformName'] = self.device_and_6.platformName # éè¦è¿æ¥å¹³å°å称ï¼ä¸åºå大å°å116 desired_caps['platformVersion'] = self.device_and_6.platformVersion # å¹³å°ççæ¬[5.4.3/5.4/5]117 desired_caps['deviceName'] = self.device_and_6.deviceName # 设å¤çå称ï¼é便åï¼ä½ä¸è½ä¸ºç©º118 desired_caps['appPackage'] = self.app_anzi.appPackage # éè¦æå¼çåºç¨å称119 desired_caps['appActivity'] = self.app_anzi.appActivity # éè¦æå¼ççé¢å称120 driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)121 time.sleep(3)122 # ç½®åå°5s123 driver.background_app(5)124 time.sleep(3)125 driver.quit()126 def test_setting_element(self):127 '''å®ä½1个å
ç´ ï¼è®¾ç½®-ç¹å»æ¾å¤§é-è¾å
¥at-è¿å'''128 desired_caps = dict() # åå§ååå
¸129 desired_caps['platformName'] = self.device_and_6.platformName # éè¦è¿æ¥å¹³å°å称ï¼ä¸åºå大å°å130 desired_caps['platformVersion'] = self.device_and_6.platformVersion # å¹³å°ççæ¬[5.4.3/5.4/5]131 desired_caps['deviceName'] = self.device_and_6.deviceName # 设å¤çå称ï¼é便åï¼ä½ä¸è½ä¸ºç©º132 desired_caps['appPackage'] = self.app_setting.appPackage # éè¦æå¼çåºç¨å称133 desired_caps['appActivity'] = self.app_setting.appActivity # éè¦æå¼ççé¢å称134 driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)135 time.sleep(3)136 # éè¿IDå®ä½æ¾å¤§éæé®ï¼ç¹å»137 search_butoon = driver.find_element_by_id('com.android.settings:id/search')138 search_butoon.click()139 # éè¿CLASSå®ä½è¾å
¥æ¡ï¼è¾å
¥at140 search_box = driver.find_element_by_class_name('android.widget.EditText')141 search_box.send_keys('at')142 # éè¿XPATHå®ä½è¿åæé®ï¼ç¹å»143 driver.find_element_by_xpath("//*[@content-desc='æ¶èµ·']").click()144 time.sleep(5)145 driver.quit()146 def test_setting_elements(self):147 '''å®ä½1ç»å
ç´ ï¼è®¾ç½®-è¾åºææid/titleä¸textçå
容'''148 desired_caps = dict() # åå§ååå
¸149 desired_caps['platformName'] = self.device_and_6.platformName # éè¦è¿æ¥å¹³å°å称ï¼ä¸åºå大å°å150 desired_caps['platformVersion'] = self.device_and_6.platformVersion # å¹³å°ççæ¬[5.4.3/5.4/5]151 desired_caps['deviceName'] = self.device_and_6.deviceName # 设å¤çå称ï¼é便åï¼ä½ä¸è½ä¸ºç©º152 desired_caps['appPackage'] = self.app_setting.appPackage # éè¦æå¼çåºç¨å称153 desired_caps['appActivity'] = self.app_setting.appActivity # éè¦æå¼ççé¢å称154 driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)155 time.sleep(3)156 # éè¿IDè·åresource-id为ï¼com.android.settings:id/titleçå
ç´ ï¼å¹¶æå°æåå
容157 titles_ids = driver.find_elements_by_id('com.android.settings:id/title')158 for title in titles_ids:159 print(title.text)160 print('åå²çº¿'.center(100,'*'))161 # éè¿CLASSè·åclass为ï¼android.widget.TextViewçå
ç´ ï¼å¹¶æå°æåå
容162 titles_class = driver.find_elements_by_class_name('android.widget.TextView')163 for title in titles_class:164 print(title.text)165 print('åå²çº¿'.center(100,'*'))166 # éè¿XPATHè·åææå
å«"设"çå
ç´ ï¼å¹¶æå°æåå
容167 titles_xpath = driver.find_elements_by_xpath("//*[contains(@text,'设')]")168 for title in titles_xpath:169 print(title.text)170 time.sleep(5)171 driver.quit()172 def test_setting_implicitly_wait(self):173 '''å
ç´ çå¾
ï¼éå¼çå¾
'''174 desired_caps = dict() # åå§ååå
¸175 desired_caps['platformName'] = self.device_and_6.platformName # éè¦è¿æ¥å¹³å°å称ï¼ä¸åºå大å°å176 desired_caps['platformVersion'] = self.device_and_6.platformVersion # å¹³å°ççæ¬[5.4.3/5.4/5]177 desired_caps['deviceName'] = self.device_and_6.deviceName # 设å¤çå称ï¼é便åï¼ä½ä¸è½ä¸ºç©º178 desired_caps['appPackage'] = self.app_setting.appPackage # éè¦æå¼çåºç¨å称179 desired_caps['appActivity'] = self.app_setting.appActivity # éè¦æå¼ççé¢å称180 driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)181 # éå¼çå¾
182 driver.implicitly_wait(3)183 print('---åå¤æ¾è¿åè¿è¡ç¹å»')184 driver.find_element_by_xpath("//*[@content-desc='æ¶èµ·']").click()185 print('---ç¹å®äº')186 # time.sleep(5)187 driver.quit()188 def test_setting_webdriverwait(self):189 '''å
ç´ çå¾
ï¼æ¾ç¤ºçå¾
'''190 desired_caps = dict() # åå§ååå
¸191 desired_caps['platformName'] = self.device_and_6.platformName # éè¦è¿æ¥å¹³å°å称ï¼ä¸åºå大å°å192 desired_caps['platformVersion'] = self.device_and_6.platformVersion # å¹³å°ççæ¬[5.4.3/5.4/5]193 desired_caps['deviceName'] = self.device_and_6.deviceName # 设å¤çå称ï¼é便åï¼ä½ä¸è½ä¸ºç©º194 desired_caps['appPackage'] = self.app_setting.appPackage # éè¦æå¼çåºç¨å称195 desired_caps['appActivity'] = self.app_setting.appActivity # éè¦æå¼ççé¢å称196 driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)197 # æ¾ç¤ºçå¾
198 print('---åå¤æ¾è¿åè¿è¡ç¹å»')199 wait = WebDriverWait(driver, 10, 1)200 back_button = wait.until(lambda x:x.find_element_by_xpath("//*[@content-desc='æ¶èµ·']"))201 # back_button = WebDriverWait(driver, 10, 1).until(lambda x:x.find_element_by_xpath("//*[@content-desc='æ¶èµ·']"))202 back_button.click()203 print('---ç¹å®äº')204 driver.quit()205 def test_setting_click_element(self):206 '''å
ç´ çå¾
ï¼æ¾ç¤ºçå¾
'''207 desired_caps = dict() # åå§ååå
¸208 desired_caps['platformName'] = self.device_and_6.platformName # éè¦è¿æ¥å¹³å°å称ï¼ä¸åºå大å°å209 desired_caps['platformVersion'] = self.device_and_6.platformVersion # å¹³å°ççæ¬[5.4.3/5.4/5]210 desired_caps['deviceName'] = self.device_and_6.deviceName # 设å¤çå称ï¼é便åï¼ä½ä¸è½ä¸ºç©º211 desired_caps['appPackage'] = self.app_setting.appPackage # éè¦æå¼çåºç¨å称212 desired_caps['appActivity'] = self.app_setting.appActivity # éè¦æå¼ççé¢å称213 desired_caps['unicodeKeyboard'] = True # è¾å
¥æ¡ä¸æ214 desired_caps['resetKeyboard'] = True215 driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)216 eles = driver.find_elements_by_id('com.android.settings:id/title')217 for ele in eles: # è·åææ¬å
容218 print(ele.text)219 print((ele.get_attribute('enabled')))220 print((ele.get_attribute('clickable')))221 print((ele.get_attribute('focusable')))222 print((ele.get_attribute('name'))) # è·åcontent-descætextå¼223 print((ele.get_attribute('scrollable')))224 print((ele.get_attribute('className'))) # è·åclasså±æ§å¼225 print((ele.get_attribute('resourceId'))) # è·åresource-idå±æ§å¼226 search_buttton = driver.find_element_by_id('com.android.settings:id/search')227 print('æ¾å¤§éä½ç½®ï¼', search_buttton.location) # è·åæ¾å¤§éä½ç½®228 print(search_buttton.location['x'])229 print(search_buttton.location['y'])230 print('æ¾å¤§é大å°ï¼',search_buttton.size) # è·åæ¾å¤§é大å°231 print(search_buttton.size['width'])232 print(search_buttton.size['height'])233 search_buttton.click() # ç¹å»è®¾ç½®-æ¾å¤§éæé®234 input_label = driver.find_element_by_class_name('android.widget.EditText')235 input_label.send_keys('hello') # è¾å
¥"hello"236 time.sleep(2) # æå2ç§237 input_label.clear() # æ¸
空ææææ¬238 time.sleep(3) # æå5ç§239 input_label.send_keys('ä½ å¥½') # è¾å
¥"ä½ å¥½"240 time.sleep(3)241 driver.quit()242 def test_setting_swipe(self):243 '''æ»å¨ï¼æ¨¡æææä»ï¼100ï¼2000ï¼ï¼æ»å¨å°ï¼100ï¼1000ï¼'''244 desired_caps = dict() # åå§ååå
¸245 desired_caps['platformName'] = self.device_and_6.platformName # éè¦è¿æ¥å¹³å°å称ï¼ä¸åºå大å°å246 desired_caps['platformVersion'] = self.device_and_6.platformVersion # å¹³å°ççæ¬[5.4.3/5.4/5]247 desired_caps['deviceName'] = self.device_and_6.deviceName # 设å¤çå称ï¼é便åï¼ä½ä¸è½ä¸ºç©º248 desired_caps['appPackage'] = self.app_setting.appPackage # éè¦æå¼çåºç¨å称249 desired_caps['appActivity'] = self.app_setting.appActivity # éè¦æå¼ççé¢å称250 driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)251 # 模æææä»ï¼100ï¼2000ï¼ï¼æ»å¨å°ï¼100ï¼1000ï¼252 # driver.swipe(100, 1500, 100, 1000)253 # driver.swipe(100, 1000, 100, 500)254 # driver.swipe(100, 500, 100, 0)255 # ä»"æ´å¤"æ»å¨å°"è¯è¨åè¾å
¥æ³"256 time.sleep(3)257 save_button = driver.find_element_by_xpath("//*[@text='æ´å¤']")258 more_button = driver.find_element_by_xpath("//*[@text='åºç¨']")259 driver.scroll(save_button, more_button)260 # ä»"æ´å¤"æ»å¨å°"æå°"261 driver.drag_and_drop(more_button, save_button)262 time.sleep(20)263 driver.quit()264 def test_setting_touch_action_tap(self):265 '''ææè½»æ²æä½ï¼æ¨¡æææ对æ个å
ç´ æåæ æä¸å¹¶å¿«éæ¬èµ·ãæ¯å¦åºå®ç¹å»100ï¼100ä½ç½®'''266 desired_caps = dict() # åå§ååå
¸267 desired_caps['platformName'] = self.device_and_6.platformName # éè¦è¿æ¥å¹³å°å称ï¼ä¸åºå大å°å268 desired_caps['platformVersion'] = self.device_and_6.platformVersion # å¹³å°ççæ¬[5.4.3/5.4/5]269 desired_caps['deviceName'] = self.device_and_6.deviceName # 设å¤çå称ï¼é便åï¼ä½ä¸è½ä¸ºç©º270 desired_caps['appPackage'] = self.app_setting.appPackage # éè¦æå¼çåºç¨å称271 desired_caps['appActivity'] = self.app_setting.appActivity # éè¦æå¼ççé¢å称272 driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)273 waln_button = driver.find_element_by_xpath("//*[@text='WLAN']")274 # è½»æ²"WLAN"275 # 1.å建TouchAction对象 2.è°ç¨tapæ§è¡å¨ä½ 3.使ç¨performæ§è¡å¨ä½276 TouchAction(driver).tap(waln_button).perform()277 time.sleep(3)278 TouchAction(driver).tap(x=200,y=200,count=2).perform()279 time.sleep(5)280 driver.quit()281 def test_setting_touch_action_press_and_release(self):282 '''æä¸åæ¬èµ·æä½ï¼æ¨¡æææä¸ç´æä¸ï¼æ¨¡ææææ¬èµ·'''283 desired_caps = dict() # åå§ååå
¸284 desired_caps['platformName'] = self.device_and_6.platformName # éè¦è¿æ¥å¹³å°å称ï¼ä¸åºå大å°å285 desired_caps['platformVersion'] = self.device_and_6.platformVersion # å¹³å°ççæ¬[5.4.3/5.4/5]286 desired_caps['deviceName'] = self.device_and_6.deviceName # 设å¤çå称ï¼é便åï¼ä½ä¸è½ä¸ºç©º287 desired_caps['appPackage'] = self.app_setting.appPackage # éè¦æå¼çåºç¨å称288 desired_caps['appActivity'] = self.app_setting.appActivity # éè¦æå¼ççé¢å称289 driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)290 waln_button = driver.find_element_by_xpath("//*[@text='WLAN']")291 # æä¸WLANå®è£
ï¼2såæ¬èµ·292 TouchAction(driver).press(waln_button).perform()293 time.sleep(2)294 TouchAction(driver).press(waln_button).release().perform()295 time.sleep(5)296 driver.quit()297 def test_setting_touch_action_wait(self):298 '''çå¾
æä½ï¼æ¨¡æææçå¾
ï¼'''299 desired_caps = dict() # åå§ååå
¸300 desired_caps['platformName'] = self.device_and_6.platformName # éè¦è¿æ¥å¹³å°å称ï¼ä¸åºå大å°å301 desired_caps['platformVersion'] = self.device_and_6.platformVersion # å¹³å°ççæ¬[5.4.3/5.4/5]302 desired_caps['deviceName'] = self.device_and_6.deviceName # 设å¤çå称ï¼é便åï¼ä½ä¸è½ä¸ºç©º303 desired_caps['appPackage'] = self.app_setting.appPackage # éè¦æå¼çåºç¨å称304 desired_caps['appActivity'] = self.app_setting.appActivity # éè¦æå¼ççé¢å称305 driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)306 waln_button = driver.find_element_by_xpath("//*[@text='WLAN']")307 # ç¹å»WLANï¼çå¾
5ç§åï¼åæä¸wiredssidçå¾
2såæ¬èµ·308 TouchAction(driver).tap(waln_button).perform()309 time.sleep(2)310 TouchAction(driver).press(x=228, y=408).wait(2000).release().perform()311 time.sleep(5)312 driver.quit()313 def test_setting_touch_action_long_press(self):314 '''é¿ææä½ï¼æ¨¡æææ对å
ç´ æåæ çé¿ææä½'''315 desired_caps = dict() # åå§ååå
¸316 desired_caps['platformName'] = self.device_and_6.platformName # éè¦è¿æ¥å¹³å°å称ï¼ä¸åºå大å°å317 desired_caps['platformVersion'] = self.device_and_6.platformVersion # å¹³å°ççæ¬[5.4.3/5.4/5]318 desired_caps['deviceName'] = self.device_and_6.deviceName # 设å¤çå称ï¼é便åï¼ä½ä¸è½ä¸ºç©º319 desired_caps['appPackage'] = self.app_setting.appPackage # éè¦æå¼çåºç¨å称320 desired_caps['appActivity'] = self.app_setting.appActivity # éè¦æå¼ççé¢å称321 driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)322 waln_button = driver.find_element_by_xpath("//*[@text='WLAN']")323 # 使ç¨åæ çå½¢å¼ç¹å»WLANï¼çå¾
2såï¼åé¿æä¸wiredssidçä½ç½®æç»2s324 TouchAction(driver).tap(waln_button).perform()325 time.sleep(2)326 TouchAction(driver).long_press(x=228, y=408, duration=2000).release().perform()327 time.sleep(5)328 driver.quit()329 def test_setting_touch_action_move_to(self):330 '''移å¨æä½ï¼æå¿è§£éï¼å
æä¸å移å¨'''331 desired_caps = dict() # åå§ååå
¸332 desired_caps['platformName'] = self.device_and_6.platformName # éè¦è¿æ¥å¹³å°å称ï¼ä¸åºå大å°å333 desired_caps['platformVersion'] = self.device_and_6.platformVersion # å¹³å°ççæ¬[5.4.3/5.4/5]334 desired_caps['deviceName'] = self.device_and_6.deviceName # 设å¤çå称ï¼é便åï¼ä½ä¸è½ä¸ºç©º335 desired_caps['appPackage'] = self.app_lock.appPackage # éè¦æå¼çåºç¨å称336 desired_caps['appActivity'] = self.app_lock.appActivity # éè¦æå¼ççé¢å称337 driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)338 time.sleep(2)339 # æ ¹æ®åæ ä½ç½®æ»å¨å
ç´ 340 TouchAction(driver).press(x=179,y=630).move_to(x=539,y=630)\341 .move_to(x=901,y=630). move_to(x=901,y=989)\342 .move_to(x=542,y=989).move_to(x=901,y=1349).release().perform()343 time.sleep(5)344 driver.quit()345 def test_get_windows_size_and_screenshort(self):346 '''è·åå½å设å¤å辨ç并æªå¾'''347 desired_caps = dict() # åå§ååå
¸348 desired_caps['platformName'] = self.device_and_6.platformName # éè¦è¿æ¥å¹³å°å称ï¼ä¸åºå大å°å349 desired_caps['platformVersion'] = self.device_and_6.platformVersion # å¹³å°ççæ¬[5.4.3/5.4/5]350 desired_caps['deviceName'] = self.device_and_6.deviceName # 设å¤çå称ï¼é便åï¼ä½ä¸è½ä¸ºç©º351 desired_caps['appPackage'] = self.app_setting.appPackage # éè¦æå¼çåºç¨å称352 desired_caps['appActivity'] = self.app_setting.appActivity # éè¦æå¼ççé¢å称353 driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)354 # è·åå½å设å¤çå辨ç355 print(driver.get_window_size())356 # ææºæªå¾357 driver.get_screenshot_as_file("screen.png")358 driver.quit()359 def test_get_set_network_connect(self):360 '''è·åå设置å½åç½ç»'''361 desired_caps = dict() # åå§ååå
¸362 desired_caps['platformName'] = self.device_and_6.platformName # éè¦è¿æ¥å¹³å°å称ï¼ä¸åºå大å°å363 desired_caps['platformVersion'] = self.device_and_6.platformVersion # å¹³å°ççæ¬[5.4.3/5.4/5]364 desired_caps['deviceName'] = self.device_and_6.deviceName # 设å¤çå称ï¼é便åï¼ä½ä¸è½ä¸ºç©º365 desired_caps['appPackage'] = self.app_setting.appPackage # éè¦æå¼çåºç¨å称366 desired_caps['appActivity'] = self.app_setting.appActivity # éè¦æå¼ççé¢å称367 driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)368 # è·åå½åç½ç»ç±»å并æå°369 print(driver.network_connection)370 # 设置å½åç½ç»-é£è¡æ¨¡å¼371 driver.set_network_connection(1)372 # å¤æå½åç½ç»æ¯ä¸æ¯æµé: å¦ææ¯,设置为wifi373 if driver.network_connection == ConnectionType.DATA_ONLY:374 driver.set_network_connection(ConnectionType.WIFI_ONLY)375 if driver.network_connection == ConnectionType.AIRPLANE_MODE:376 driver.set_network_connection(ConnectionType.WIFI_ONLY)377 driver.quit()378 def test_press_keycode(self):379 '''åéé®å°è®¾å¤ï¼æ¨¡ææè¿å/homeé®ççæä½ï¼'''380 # ç¹å»ä¸æ¬¡é³éå é®381 self.driver.press_keycode(24)382 self.driver.press_keycode(24)383 self.driver.press_keycode(24)384 # åç¹å»è¿å385 self.driver.press_keycode(4)386 # åç¹å»ä¸¤æ¬¡é³éå387 self.driver.press_keycode(25)388 self.driver.press_keycode(25)389 def test_open_notifications(self):390 '''æä½ææºéç¥æ '''391 desired_caps = dict() # åå§ååå
¸392 desired_caps['platformName'] = self.device_and_6.platformName # éè¦è¿æ¥å¹³å°å称ï¼ä¸åºå大å°å393 desired_caps['platformVersion'] = self.device_and_6.platformVersion # å¹³å°ççæ¬[5.4.3/5.4/5]394 desired_caps['deviceName'] = self.device_and_6.deviceName # 设å¤çå称ï¼é便åï¼ä½ä¸è½ä¸ºç©º395 desired_caps['appPackage'] = self.app_setting.appPackage # éè¦æå¼çåºç¨å称396 desired_caps['appActivity'] = self.app_setting.appActivity # éè¦æå¼ççé¢å称397 driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)398 # æå¼éç¥æ 399 driver.open_notifications()400 time.sleep(5)401 # å
³ééç¥æ ï¼ä½¿ç¨è¿åé®402 driver.press_keycode(4)...
platform.py
Source:platform.py
1# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License"). You4# may not use this file except in compliance with the License. A copy of5# the License is located at6#7# http://aws.amazon.com/apache2.0/8#9# or in the "license" file accompanying this file. This file is10# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF11# ANY KIND, either express or implied. See the License for the specific12# language governing permissions and limitations under the License.13import re14import pkg_resources15from ebcli.objects.exceptions import EBCLIException16class PlatformVersion(object):17 class UnableToParseArnException(EBCLIException):18 pass19 ARN_PATTERN = re.compile(20 r'^arn:[^:]+:elasticbeanstalk:[^:]+:([^:]*):platform/([^/]+)/(\d+\.\d+\.\d+)$'21 )22 @classmethod23 def is_custom_platform_arn(cls, arn):24 if PlatformVersion.is_valid_arn(arn):25 return PlatformVersion(arn).account_id26 @classmethod27 def is_eb_managed_platform_arn(cls, arn):28 if PlatformVersion.is_valid_arn(arn):29 return not PlatformVersion(arn).account_id30 @classmethod31 def is_valid_arn(cls, arn):32 if not isinstance(arn, str) and not isinstance(arn, bytes):33 return False34 return PlatformVersion.ARN_PATTERN.search(arn)35 @classmethod36 def arn_to_platform(cls, arn):37 match = PlatformVersion.ARN_PATTERN.search(arn)38 if not match:39 raise PlatformVersion.UnableToParseArnException("Unable to parse arn '{}'".format(arn))40 account_id, platform_name, platform_version = match.group(1, 2, 3)41 return account_id, platform_name, platform_version42 @classmethod43 def get_platform_version(cls, arn):44 _, _, platform_version = PlatformVersion.arn_to_platform(arn)45 return platform_version46 @classmethod47 def get_platform_name(cls, arn):48 _, platform_name, _ = PlatformVersion.arn_to_platform(arn)49 return platform_name50 @classmethod51 def get_region_from_platform_arn(cls, arn):52 if cls.is_eb_managed_platform_arn(arn):53 split_string = arn.split(':')54 return split_string[3]55 @classmethod56 def match_with_complete_arn(57 cls,58 platforms,59 input_platform_name60 ):61 for platform in platforms:62 if platform == input_platform_name:63 return PlatformVersion(platform)64 @classmethod65 def match_with_platform_name(66 cls,67 custom_platforms,68 input_platform_name69 ):70 for custom_platform in custom_platforms:71 if PlatformVersion.get_platform_name(custom_platform) == input_platform_name:72 return PlatformVersion(custom_platform)73 def __init__(self, arn):74 self.arn = arn75 account_id, platform_name, platform_version = PlatformVersion.arn_to_platform(arn)76 # For the sake of the CLI a version is the same thing as an ARN77 self.version = self.arn78 self.name = arn79 self.account_id = account_id80 self.platform_version = platform_version81 self.platform_shorthand = platform_name82 def __str__(self):83 return self.version84 def __eq__(self, other):85 if not isinstance(other, PlatformVersion):86 return False87 return self.version == other.version88 def __ne__(self, other):89 return not self.__eq__(other)90 @property91 def has_healthd_group_version_2_support(self):92 if PlatformVersion.is_custom_platform_arn(self.name):93 return False94 return pkg_resources.parse_version(self.platform_version) \95 >= pkg_resources.parse_version('2.0.10')96 @property97 def has_healthd_support(self):98 return pkg_resources.parse_version(self.platform_version) \...
device_db.py
Source:device_db.py
1'''2This file is used as a database of known devices.3In the future this may need to be changed to an actual database4but at the time of creation this was sufficient5'''6devices = [7 {8 'platformName': 'Android',9 'platformVersion': '6.0.1',10 'deviceName': 'Galaxy S5',11 'udid': 'ca13ba30',12 },13 {14 'platformName': 'Android',15 'platformVersion': '6.0.1',16 'deviceName': 'Galaxy S7 Edge',17 'udid': 'b85d1213'18 },19 {20 'platformName': 'Android',21 'platformVersion': '6.0.1',22 'deviceName': 'Galaxy S6 Edge Plus',23 'udid': '0715f763fb412738'24 },25 {26 'platformName': 'Android',27 'platformVersion': '6.0.1',28 'deviceName': 'Galaxy S6',29 'udid': '06157df6a58b4c33',30 },31 {32 'platformName': 'Android',33 'platformVersion': '4.4.4',34 'deviceName': 'Nexus 5',35 'udid': '04d08f25344bd15b'36 },37 {38 'platformName': 'Android',39 'platformVersion': '7.0',40 'deviceName': 'Galaxy S7',41 'udid': 'ebacbe57',42 },43 {44 'platformName': 'Android',45 'platformVersion': '6.0.1',46 'deviceName': 'ZTE',47 'udid': '3487a1c5'48 },49 {50 'platformName': 'Android',51 'platformVersion': '5.0.2',52 'deviceName': 'Galaxy A5',53 'udid': 'VCP7N15A20006622'54 },55 {56 'platformName': 'Android',57 'platformVersion': '5.1',58 'deviceName': 'Huawei',59 'udid': 'fdb354b1'60 },61 {62 'platformName': 'Android',63 'platformVersion': '4.4.2',64 'deviceName': 'LG G3',65 'udid': 'LGD850caeb2ee'66 }67]68browsers = ('Chrome', '')69test_android = {70 'platformName': 'Android',71 'deviceName': 'Android Emulator'72 }73emulator_version = (74 '4.4',75 '5.0',76 '5.1',77 '6.0',78 '7.0',79 '7.1.1'...
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!!