请注意操作步骤:
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()