請注意操作步驟:
1、
用資料線連線手機,
開啟開發者模式,
並賦予相關許可權,
並保持不鎖屏狀態;
2、
啟動Appium桌面服務端;
3、
執行程式;
首次執行,
Appium會在手機上安裝3個App:
Unlock;
Appium Setting;
Appium Android Input Manager for Unicode;
請不要解除安裝!
TaobaoTest.py:
import unittest
from time import sleep
from appium.webdriver import webdriver
class MyTestCase(unittest.TestCase):
def setUp(self):
capabilities = {
"platformName": "Android",
# Mobile OS型別
"platformVersion": "7.1.1",
# Mobile OS版本
"deviceName": "3216e430",
# adb devices
"browserName": "",
# Web瀏覽器名稱,如果對App測試,值為空
"appPackage": "com.taobao.taobao",
# 手機淘寶包名
"appActivity": "com.taobao.tao.welcome.Welcome",
# 手機淘寶的啟動頁
"unicodeKeyboard": True,
# 支援中文輸入,預設false
"resetKeyboard": True,
# 重置輸入法為系統預設
"noReset": True,
# 不重新安裝apk
"noSign": True
# 不重新簽名apk
}
self.driver = webdriver.WebDriver("http://localhost:4723/wd/hub", capabilities)
sleep(1)
def test_taobao(self):
driver = self.driver
driver.find_element_by_id("com.taobao.taobao:id/home_searchedit").click()
# 點選淘寶搜尋框
sleep(1)
driver.find_element_by_id("com.taobao.taobao:id/searchEdit").send_keys("華碩官方旗艦店")
sleep(1)
driver.find_element_by_id("com.taobao.taobao:id/searchbtn").click()
sleep(5)
assert driver.page_source.__contains__("asus華碩官方旗艦店")
def tearDown(self):
self.driver.close_app()
self.driver.quit()
if __name__ == '__main__':
unittest.main()