知识点1:
初始化连接手机
1.查找udid和包名
2,appium连接ios手机的条件
from appium import webdriver
from selenium.webdriver.common.by import By
import timedef test_01():desired_caps = dict()desired_caps["platformName"]="iOS"desired_caps["appium:platformVersion"]="15.0"desired_caps["appium:deviceName"]="iPhone 11 Pro"desired_caps["appium:app"]="com.XXXXXXX.hecmccmobile"desired_caps["udid"]='0000XXX0-000XXXXX1DA802E'driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_caps)time.sleep(10)if __name__ == '__main__':test_01()
3.打开app的代码
知识点2:
卸载ios手机app
def uninstall_app(udid="00008030-000D24563410402E"):os.system("ideviceinstaller -u " + udid + " -U com.wondertek.hecmccmobile")# 卸载app
知识点3:
导出iOS手机日志到电脑
import configparser
import os
import timerootPath = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
path = rootPath + "/log/"rootPath_ini = os.path.join(rootPath, "config.ini")
cf = configparser.ConfigParser() # 初始化
cf.read(rootPath_ini) # 读文件
udid = cf.get("config", "udid") # 发信服务器def isExists(folder):if os.path.exists(folder): # 判断文件夹是否存在passelse:os.mkdir(folder) # 创建文件夹以及子文件夹def open_log(log_name):times = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())log_path = pathfilename = log_name + times + ".log"isExists(log_path)logs = os.path.join(log_path, filename)print(r"idevicesyslog >> %s &" % logs)os.system(r"idevicesyslog -u " + udid + r" >> %s &" % logs)time.sleep(2)def kill_log():# 杀进程os.system("pkill idevicesyslog")if __name__ == '__main__':open_log("DEbug")time.sleep(7)print("关闭")kill_log()
知识点4:
发送email邮件
import configparser
import os
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.header import Header'''
发送email代附件
'''def sendemail_l(report_name):# report_name为文件名称html_msg = """<p>iOS手机稳定性测试报告已发送至各位邮箱,请及时查收。</p><p>如有疑问请及时联系。</p>"""# html_msg为文件正文内容msg = MIMEMultipart()msg['From'] = Header('王浩') # 发送者# msg['To'] = Header('接收者姓名') # 接收者subject = 'iOS手机稳定性测试报告' # 邮件标题msg['Subject'] = Header(subject, 'utf-8') # 邮件主题msg.attach(MIMEText(html_msg, 'html', 'utf-8'))# 邮件信息配置rootPath = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))rootPath_report = os.path.join(rootPath, "Report")# 确定Report文件夹att1 = MIMEText(open(os.path.join(rootPath_report, report_name), 'rb').read(), 'base64', 'utf-8')att1["Content-Type"] = 'application/octet-stream'# 构造附件,这里的filename可以任意写,写什么名字,邮件中显示什么名字att1.add_header("Content-Disposition", "attachment", filename=("gbk", "", report_name))# 非中文写法# att1["Content-Disposition"] = 'attachment; filename="test.html"'msg.attach(att1)rootPath_ini = os.path.join(rootPath, "config.ini")cf = configparser.ConfigParser() # 初始化cf.read(rootPath_ini) # 读文件mail_host = cf.get("Email", "mail_host") # 发信服务器mail_user = cf.get("Email", "mail_user") # 登录账号,及发送邮件账号mail_pass = cf.get("Email", "mail_pass") # 登录账号授权码mail_str = cf.get("Email", "receivers") # 收信方邮箱receivers = mail_str.split(",") # 拆分邮箱print(receivers)smtpObj = smtplib.SMTP()smtpObj.connect(mail_host, 25) # 25 为 SMTP 端口号smtpObj.login(mail_user, mail_pass)smtpObj.sendmail(mail_user, receivers, msg.as_string())print("邮件发送成功")smtpObj.quit()# 关闭if __name__ == '__main__':sendemail_l("android稳定性测试报告2022-11-11-16_10_02.html")