mac终端使用pytest执行iOS UI自动化测试方法
1、安装pytest-repeat插件:
pip install pytest-repeat
2、安装allure-pytest插件:
pip install allure-pytest
3、打开终端:
pytest -q -s -ra --count=100 test_open_stream.py --alluredir=./report/CXL
-q:表示“quiet mode”(安静模式),减少输出信息,只显示最小的结果信息。
-s:允许在控制台中输出 print 语句的内容,方便调试。
-ra:显示测试报告摘要,包括通过、失败、错误等详细信息。
--count=100:表示将 test_open_stream.py 测试运行 100 次。
--alluredir=./report/C6L:将测试结果保存到 ./report/CXL 目录中,以便之后生成 Allure 报告。
4、在测试完成后,生成 Allure 报告来查看详细的测试结果:
allure serve ./report/CXL
在查看报告之前需要安装allure插件:
brew install allure
查看是否安装成功:
allure --version
【问题】
allure安装时间较长,需要网络稳定,第一次没有安装成功。第二次安装allure过程出现如下报错:
==> Pouring python@3.12--3.12.7_1.sonoma.bottle.tar.gz Error: The brew link
step did not complete successfully The formula built, but is not symlinked into /usr/local Could not symlink bin/2to3-3.12 Target /usr/local/bin/2to3-3.12 already exists. You may want to remove it: rm '/usr/local/bin/2to3-3.12' To force the link and overwrite all conflicting files: brew link --overwrite python@3.12 To list all files that would be deleted: brew link --overwrite python@3.12 --dry-run Possible conflicting files are: /usr/local/bin/2to3-3.12 -> /Library/Frameworks/Python.framework/Versions/3.12/bin/2to3-3.12 /usr/local/bin/idle3.12 -> /Library/Frameworks/Python.framework/Versions/3.12/bin/idle3.12 /usr/local/bin/pydoc3.12 -> /Library/Frameworks/Python.framework/Versions/3.12/bin/pydoc3.12 /usr/local/bin/python3.12 -> /Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12 /usr/local/bin/python3.12-config -> /Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12-config
【解决】
rm /usr/local/bin/2to3-3.12
rm /usr/local/bin/idle3.12
rm /usr/local/bin/pydoc3.12
rm /usr/local/bin/python3.12
rm /usr/local/bin/python3.12-config
brew link python@3.12
【备注】
上面的报错原因是我之前安装的python版本不是通过homebrew安装的,在后续使用homebrew安装其他插件时会弹出上面的提示,即homebrew希望有它来管理python版本。按照上面的解决方法,可以解决问题,但是后来在使用pytest执行脚本的时候报错:
testmanzhang@TestMandeMBP practiceUICatalog % pytest
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.12/bin/pytest", line 5, in <module>
from pytest import console_main
之前安装的pytest插件不能用了,后来恢复了原来的符号连接:
sudo rm /usr/local/bin/2to3-3.12
sudo ln -s /Library/Frameworks/Python.framework/Versions/3.12/bin/2to3-3.12 /usr/local/bin/2to3-3.12
sudo rm /usr/local/bin/idle3.12
sudo ln -s /Library/Frameworks/Python.framework/Versions/3.12/bin/idle3.12 /usr/local/bin/idle3.12
sudo rm /usr/local/bin/pydoc3.12
sudo ln -s /Library/Frameworks/Python.framework/Versions/3.12/bin/pydoc3.12 /usr/local/bin/pydoc3.12
sudo rm /usr/local/bin/python3.12
sudo ln -s /Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12 /usr/local/bin/python3.12
sudo rm /usr/local/bin/python3.12-config
sudo ln -s /Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12-config /usr/local/bin/python3.12-config
所以建议大家使用homebrew安装python。