iOS自动化,知识点1

知识点1:

初始化连接手机

1.查找udid和包名

2,appium连接ios手机的条件

from appium import webdriver
from selenium.webdriver.common.by import By
import time

def 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 time


rootPath = 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):  # 判断文件夹是否存在
        pass
    else:
        os.mkdir(folder)  # 创建文件夹以及子文件夹


def open_log(log_name):
    times = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
    log_path = path
    filename = 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")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值