1、下载Android-SDK、夜神安卓模拟器、Appium、adb命令执行包并配置环境变量
2、打开夜神
3、打开Appium进行配置,配置如下
4、启动命令,到夜神bin目录下执行
adb connect 127.0.0.1:62001
adb devices
5、运行测试代码,自动安装apk并启动
# coding=utf-8 import re import time import yaml_ini from appium import webdriver from create_order import generate_orders_all # android app 版本信息 app_version : {'platformName': 'Android', # Android或iOS 'platformVersion': '5.1.1', # 安卓版本 'deviceName': '127.0.0.1:62001 device', # 手机设备名称,通过adb devices 查看 'appPackage': 'com.test.test', # 用 aapt dump badging 查看包名 'appActivity': 'com.test.main_module.ui.SplashAt', 'newCommandTimeout': '200000'} # 无操作是默认关闭时间 app_ip = yaml_ini.read_yaml()['app_ip'] app_version = yaml_ini.read_yaml()['app_version'] dr = webdriver.Remote('http://127.0.0.1:4723/wd/hub', app_version) # 启动服务器地址,后面跟的是手机信息 def login(): # 输入账户密码 time.sleep(5) dr.find_element_by_id('com.test.test:id/edt_phone').send_keys('') dr.find_element_by_id('com.test.test:id/edt_pwd').send_keys('') dr.find_element_by_id('com.test.test:id/tv_login').click() # 输入短信验证码 time.sleep(3) dr.find_element_by_id('com.test.test:id/txt_pin_entry1').send_keys('') time.sleep(3) dr.find_elements_by_class_name('android.widget.TextView')[3].click() # 点击登陆 time.sleep(3) dr.find_element_by_id('com.test.test:id/tv_open_latter').click() # 不开启手势登陆 time.sleep(3) dr.find_element_by_id('com.test.test:id/ivClose').click() # 判断登陆是否成功 time.sleep(3) login_data = dr.find_element_by_id('com.test.test:id/tv_online').text if '在线' in login_data: print('登陆成功') def start_order(): # 开始接单 # time.sleep(3) # dr.find_elements_by_class_name('android.widget.TextView')[34].click() # 抢单 generate_orders_all() time.sleep(3) dr.find_element_by_id('com.test.test:id/tv_grab').click() time.sleep(3) grab_result = dr.find_element_by_id('com.test.test:id/tv_status').text if '等待对方付款' in grab_result: grab_order_id = dr.find_element_by_id('com.test.test:id/tv_order_num_value').text grab_order_money = dr.find_element_by_id('com.test.dcpay:id/tv_money_value').text print('抢单成功: ' + grab_order_id + ' ' + grab_order_money) time.sleep(3) dr.find_element_by_id('com.test.test:id/tv_confirm').click() time.sleep(3) send_money = dr.find_element_by_id('com.test.test:id/receive_amount').text if '请输入实际收款金额' in send_money: time.sleep(3) dr.find_element_by_id('com.test.test:id/receive_amount').click() amount = (str(grab_order_money)).lstrip('¥') dr.find_element_by_id('com.test.test:id/receive_amount').send_keys(amount) time.sleep(3) dr.find_element_by_id('com.test.test:id/receive_confirm').click() time.sleep(3) order_y_n = dr.find_element_by_id('com.test.test:id/tv_order_status').text if '交易成功' == order_y_n: print('完成订单')