#!/usr/local/bin/python3.7 from appium import webdriver from appium.webdriver.common.touch_action import TouchAction import time import random class SpeedTest: # 启动app def __init__(self): desired_caps = {} desired_caps[‘platformName‘] = ‘iOS‘ # 设备系统 desired_caps[‘platformVersion‘] = ‘‘ # 设备系统版本 desired_caps[‘deviceName‘] = ‘‘ # 设备名称 desired_caps[‘bundleId‘] = ‘‘ # 测试app包名 desired_caps[‘udid‘] = ‘‘ #设备id desired_caps[‘automationName‘] = ‘XCUITest‘ # 测试框架 desired_caps[‘noReset‘]=‘true‘ # 保留app的登录状态 desired_caps[‘xcodeSigningId‘]=‘iOS Developer‘ # desired_caps[‘xcodeOrgId‘]=‘aaaaa‘ # 团队id desired_caps[‘newCommandTimeout‘]=3600 self.driver = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub‘, desired_caps) # 保持端口号和appium服务端口一致 # 使用隐式等待或者显示等待,尽量减少time.sleep强制等待的使用提高脚本执行速度。 self.driver.implicitly_wait(2) def cashout(self): money_list = [‘1元‘,‘5元‘,‘10元‘,‘50元‘] money = random.choice(money_list) self.driver.find_element_by_name(money).click() self.driver.find_element_by_name(‘立即提现‘).click() self.driver.back() self.driver.back() def speedtest(self): self.driver.find_element_by_xpath("//XCUIElementTypeApplication[@name=‘网速管家‘]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeImage").click() time.sleep(1) self.driver.find_element_by_name(‘我的‘).click() def signin(self): if ‘补‘ in self.driver.page_source: # 获取‘补‘的个数 num = self.driver.find_element_by_name(‘补‘).size() i = 0 for i in range(0,num): self.driver.find_element_by_name(‘补‘).click() self.driver.find_element_by_name(‘我要补签,拿回奖励‘).click() if ‘签到领积分‘ in self.driver.page_source: self.driver.find_element_by_name(‘签到领积分‘).click() self.driver.back() elif ‘签到领积分‘ in self.driver.page_source: self.driver.find_element_by_name(‘签到领积分‘).click() self.driver.back() else: self.driver.back() def perinfo(self): # 测试个人中心 self.driver.find_element_by_name(‘个人信息‘).click() # 更换头像 # self.driver.find_element_by_name(‘头像‘).click() # self.driver.find_element_by_xpath("//XCUIElementTypeButton[@name=‘从相册中选择‘]").click() # time.sleep(1) # self.driver.find_element_by_name(‘所有照片‘).click() # time.sleep(2) # # 使用坐标定位元素,前面一定要加延时(两种方法tap or press) # TouchAction(self.driver).press(x=0, y=466).release().perform() # # self.driver.tap([(249,466)],500) # self.driver.find_element_by_name(‘选取‘).click() # time.sleep(1) # 填写昵称 self.driver.find_element_by_name(‘昵称‘).click() # 定义一个昵称列表 nick_name = [‘墨殇浅辰‘,‘尘埃未定‘,‘只言片语‘,‘蔷薇·花开‘,‘夜思晨‘,‘酒不醉人人自醉‘,‘初恋栀子花‘] nickName = self.driver.find_element_by_xpath("//XCUIElementTypeApplication[@name=‘网速管家‘]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeTextField") # 清空之前的昵称 nickName.clear() nickName.send_keys(random.choice(nick_name)) self.driver.find_element_by_name(‘完成‘).click() # 选择性别 self.driver.find_element_by_name(‘性别‘).click() sex_list = [‘男‘,‘女‘] sex = random.choice(sex_list) print(sex) if sex == ‘男‘: TouchAction(self.driver).tap(x=136, y=356).perform() # 通过坐标点击确定 TouchAction(self.driver).tap(x=282, y=457).perform() else: # 取消 TouchAction(self.driver).tap(x=129, y=457).perform() # 重置密码 self.driver.find_element_by_name(‘密码‘).click() self.driver.find_element_by_xpath("//XCUIElementTypeApplication[@name=‘网速管家‘]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeTextField[1]").send_keys("18827441913") self.driver.find_element_by_name(‘获取验证码‘).click() # 取消验证码弹框 TouchAction(self.driver).tap(x=362, y=518).perform() self.driver.find_element_by_xpath("//XCUIElementTypeApplication[@name=‘网速管家‘]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeTextField[2]").send_keys(‘111111‘) self.driver.find_element_by_name(‘下一步‘).click() time.sleep(0.5) # 返回 self.driver.back() # 返回我的页面 self.driver.back() # 积分 self.driver.find_element_by_name(‘积分‘).click() self.driver.find_element_by_name(‘积分介绍‘).click() self.driver.back() self.driver.find_element_by_name(‘可用积分‘).click() self.driver.find_element_by_name(‘可用积分明细‘).click() # 冻结积分明细 TouchAction(self.driver).tap(x=119, y=697).perform() self.driver.find_element_by_name(‘去提现‘).click() self.cashout() self.driver.find_element_by_name(‘冻结积分‘).click() self.driver.find_element_by_name(‘冻结积分明细‘).click() # 可用积分明细 TouchAction(self.driver).tap(x=122, y=641).perform() self.driver.find_element_by_name(‘去提现‘).click() self.cashout() self.driver.find_element_by_name(‘提现兑换‘).click() self.cashout() self.driver.find_element_by_name(‘积分‘).click() self.driver.find_element_by_name(‘提现记录‘).click() self.driver.back() self.driver.find_element_by_name(‘积分明细‘).click() self.driver.find_element_by_name(‘可用积分明细‘).click() # 冻结积分明细 TouchAction(self.driver).tap(x=144, y=696).perform() self.driver.find_element_by_name(‘去提现‘).click() self.cashout() # 去测速 # TouchAction(self.driver).tap(x=352, y=450).perform() # time.sleep(3) # self.speedtest() # self.driver.find_element_by_name(‘积分‘).click() # self.driver.find_element_by_name(‘去签到‘).click() # self.signin() # 去观看 TouchAction(self.driver).tap(x=358, y=611).perform() self.driver.back() # 去完成 TouchAction(self.driver).tap(x=355, y=693).perform() self.cashout() self.driver.back() self.driver.back() def test(self): # 首先判断是否登录 self.driver.find_element_by_name(‘我的‘).click() if ‘未登录‘ in self.driver.page_source: self.driver.find_element_by_name(‘未登录‘).click() self.driver.find_element_by_name(‘账号密码登录‘).click() self.driver.find_element_by_xpath("//XCUIElementTypeApplication[@name=‘网速管家‘]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther[2]/XCUIElementTypeTextField").send_keys("18827441913") self.driver.find_element_by_xpath("//XCUIElementTypeApplication[@name=‘网速管家‘]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther[2]/XCUIElementTypeSecureTextField").send_keys("123456") self.driver.find_element_by_name(‘登录‘).click() time.sleep(1) self.perinfo() else: time.sleep(1) self.perinfo() if __name__ == ‘__main__‘: speedtest =SpeedTest() speedtest.test()