1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
import uiautomator2 as u2 from time import sleep
packageName = 'com.qianmi.cash.debug' packageLocation = '/Users/wangwei/work/qianmi/app/cash-pad-all-in-one/app/build/outputs/apk/debug/app-debug.apk'
Create_Order_Count = 5
def connect(): device = u2.connect("emulator-5554") device.debug = False device.implicitly_wait(60) return device
def setup(device): device.app_install(packageLocation) device.app_start(packageName) sleep(5) return
def teardown(device): device.app_stop(packageName) device.app_clear(packageName)
return
def login(device): device(resourceId="com.qianmi.cash.debug:id/textview_save").click() sleep(3)
device(resourceId=packageName + ":id/edittext_login_by_password_phone").click() device.send_keys("18538761267") loginPwd = device(resourceId=packageName + ":id/edittext_password") loginPwd.send_keys("111111") device(resourceId=packageName + ":id/textview_login_by_password_submit").click() sleep(5)
device(resourceId=packageName + ":id/layout_background").click() device(resourceId=packageName + ":id/textview_confirm").click()
sleep(60) device(resourceId=packageName + ":id/dialog_close_btn").click()
def setMember(device): device(resourceId="com.qianmi.cash.debug:id/select_vip_tv").click() device.xpath('//*[@resource-id="com.qianmi.cash.debug:id/cash_right_frame"]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]').click() device.click(1532, 657) device.click(1119, 863) device.click(1261, 671) device.click(1259, 766) device.click(1391, 873) device.click(1261, 671) device.click(1118, 669) device.click(1382, 771) device.click(1118, 863) device.click(1254, 868) device.click(1391, 778) device.click(1119, 669) device.click(1532, 858) sleep(5) device(resourceId="com.qianmi.cash.debug:id/tv_member_info_close").click()
def createOrder(device): device(resourceId="com.qianmi.cash.debug:id/textview_category", text="所有").click() sleep(1) device.xpath('//*[@resource-id="' + packageName + ':id/recycler_category"]/android.widget.LinearLayout[3]').click() sleep(1) device.xpath('//*[@resource-id="' + packageName + ':id/recycler_goods"]/android.widget.RelativeLayout[2]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]').click() device.xpath('//*[@resource-id="' + packageName + ':id/recycler_goods"]/android.widget.RelativeLayout[4]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]').click() sleep(2)
device(resourceId=packageName + ":id/tv_cash_to_cash").click() device.xpath('//*[@resource-id="' + packageName + ':id/settlement_mode_of_payment_rv"]/android.widget.LinearLayout[2]').click()
device(resourceId=packageName + ":id/cash_key_board").click() device.click(1497, 652)
tid = device(resourceId="com.qianmi.cash.debug:id/tv_order_tid").get_text()
sleep(5) return tid
def repeatCreateOrder(): device = connect() count = 0 while (count < Create_Order_Count): setMember(device) tid = createOrder(device) count += 1 print(" =============== 创建订单 %s,第%d次 =============== " % (tid, count))
def main(): device = connect() setup(device) login(device) count = 0 while (count < Create_Order_Count): setMember(device) tid = createOrder(device) count += 1 print(" =============== 创建订单 %s,第%d次 =============== " % (tid, count)) teardown(device)
if __name__ == "__main__": main()
|