- 启动appium服务,连接手机,将测试用例demo存放到.py文件中
- #-*- coding:utf-8 -*-
- # 引入类库
- import time
- # appiumAPI库
- from appium import webdriver
- # from selenium import webdriver
- # from lib2to3.pgen2.driver import driver
- # 定义启动设备需要的参数
- desired_caps = {}
- # 设备系统
- desired_caps['platformName'] = 'Android'
- # 设备系统版本号
- desired_caps['platformVersion'] = '5.1.2'
- # 设备名称
- desired_caps['deviceName'] = 'MI 3'
- # 要测试的应用的地址
- # desired_caps['app'] = 'C:\Users\Administrator\Desktop\123456\moer_finance-release.apk'
- # 应用的包名
- desired_caps['appPackage'] = 'com.moer.moerfinance'
- desired_caps['appActivity'] = '启动的app的activity'
- # 启动app
- driver = webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)
- # 重置应用为初始状态
- driver.reset()
- # 设置时间等待,应用在开启的时候需要一定的时间加载页面,如果命令之后没有时间间隔是会导致元素找不到执行错误的
- time.sleep(5)
- # 滑动页面,从x1,y1滑动到x2,y2,滑动的时间为500毫秒
- driver.swipe(800,800,200,800,500)
- driver.quit()
在cmd中执行给文件,就可以看到手机的执行效果。
- from appium import webdriver 引入webdriver类
import time
from appium import webdriver
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.1.2'
desired_caps['deviceName'] = 'MI 3'
desired_caps['appPackage'] = 'com.moer.moerfinance'
desired_caps['appActivity'] = 'com.moer.moerfinance.advertisement.AdvertisementActivity'
driver = webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)
time.sleep(10)
driver.find_element_by_id("com.moer.moerfinance:id/user_center").click()
time.sleep(5)
driver.find_element_by_id("com.moer.moerfinance:id/main_page_left_portrait_menu").click()
time.sleep(3)
driver.find_element_by_id("com.moer.moerfinance:id/top_bar_login_area").click()
time.sleep(3)
driver.deactivate_ime_engine()
driver.find_element_by_id("com.moer.moerfinance:id/account").send_keys("13269902200")
time.sleep(2)
driver.find_element_by_id("com.moer.moerfinance:id/password").send_keys("654321")
time.sleep(2)
driver.find_element_by_id("com.moer.moerfinance:id/login").click()
driver.quit()