当前位置:网站首页>Unittest+airtest+beatiulreport combine the three to make a beautiful test report
Unittest+airtest+beatiulreport combine the three to make a beautiful test report
2022-07-04 10:37:00 【Pot pot pot】
Netease open source airtest library , Itself is a python Third party Library , And his airtestIDE Is a powerful integration tool .
From another perspective of the author , With airtest Out of the perfect use of documents , It's more meaningful for white people like us .
Here is the effect
Refer to the author's link :
https://www.jianshu.com/p/e62d3640c07c
First introduce the three :
1、airtest It's a recent popular game UI The test framework , Click through image recognition , Assert whether the image exists, etc. to achieve the purpose of Automation . compatible Ios,Android platform .
2、unittest It is python The unit test framework of , Be similar to java Of junit.
3、beautifulreport It is specially designed for unitest Engaged in html The test reports .
preparation :
1、 clone beautifulreport project ,github Here it is written in great detail
https://github.com/TesterlifeRaymond/BeautifulReport
2、 Get ready python Environmental Science , And import airtest library , Installation depends on the official
https://github.com/AirtestProject/Airtest
4、 Post the use cases I wrote .(PS, Before running this use case , Be sure to connect your phone and turn on developer mode ,adb The connection is normal . It can be used adb devices Check )
# -*- encoding=utf8 -*-
__author__ = "guozehui"
from airtest.core.api import *
import unittest
from BeautifulReport import BeautifulReport
import os
auto_setup(__file__)
class WTestcase(unittest.TestCase):
img_path = 'img'
def save_img(self, img_name):
"""
Pass in a img_name, And store it in the default file path
:param img_name:
:return:
"""
snapshot(('{}/{}.png'.format(os.path.abspath(self.img_path), img_name)))
@classmethod
def setUpClass(cls):
# Parameter you are after you connect your mobile phone , adopt adb devices The string of things you can see
init_device("Android", "CLB7N18814003069")
def setUp(self):
# Install the computer apk Pack it on your cell phone
install("F:/game/ Your bag .apk")
start_app("com. Your game package name ")
sleep(2.0)
@BeautifulReport.add_test_img(' Health announcements exist ')
def test_demo(self):
""" Start the test """
touch(Template(r"tpl1561020321733.png", record_pos=(-0.17, 0.109), resolution=(2244, 1080)))
assert_exists(Template(r"tpl1561020429302.png", record_pos=(0.003, -0.012), resolution=(2244, 1080)), " Health announcements exist ")
self.save_img(' Health announcements exist ')
def tearDown(self):
home()
@classmethod
def tearDownClass(cls):
stop_app("com. Your game package name ")
uninstall("com. Your game package name ")
if __name__ == '__main__':
unittest.main()
5、 Finally, the report is generated , Run in the following folder “python sample.py”
Follow the steps 1, You should put beautifulreport The project was copied to your run python Environmental ,site-packages The directory . Open this directory , Edit it again sample.py file
"""
@Version: 1.0
@Project: BeautyReport
@Author: Raymond
@Data: 2017/11/17 Afternoon 3:48
@File: sample.py
@License: MIT
"""
import unittest
from BeautifulReport import BeautifulReport
if __name__ == '__main__':
# I almost forgot to say , Of use cases py Documents must be used test start , Or you can change the matching value below
test_suite = unittest.defaultTestLoader.discover('F:/code/ The folder where you store the code ', pattern='test*.py')
result = BeautifulReport(test_suite)
result.report(filename=' Test report ', description=' Start the test ', log_path='.')
Um. , That's it .---------------------------------------------------------------------------------------------------------------------------------------
Long winded
python Its advantage is that it has rich third-party libraries , The premise is that you have to find , So you can pay more attention github Submission of the great gods .
Like the author, I just want to make a demo Take a look at the effect of the test report , Automated testing is a project , If you want to continue , All use cases need to be standardized , So you need to think about how to design the directory structure of this project .
The reference author mentioned earlier , Write your own directory structure , You can think about what you need to do .
https://www.jianshu.com/p/e62d3640c07c
边栏推荐
- 【Day2】 convolutional-neural-networks
- Service developers publish services based on EDAs
- RHCE - day one
- What is devsecops? Definitions, processes, frameworks and best practices for 2022
- Hlk-w801wifi connection
- [Galaxy Kirin V10] [desktop] cannot add printer
- PHP代码审计3—系统重装漏洞
- [Galaxy Kirin V10] [server] iSCSI deployment
- system design
- Number of relationship models
猜你喜欢
Safety reinforcement learning based on linear function approximation safe RL with linear function approximation translation 2
[Galaxy Kirin V10] [server] FTP introduction and common scenario construction
[Galaxy Kirin V10] [server] iSCSI deployment
Number of relationship models
Occasional pit compiled by idea
DCL statement of MySQL Foundation
Reprint: summation formula of proportional series and its derivation process
VI text editor and user rights management, group management and time management
基于线性函数近似的安全强化学习 Safe RL with Linear Function Approximation 翻译 2
[Galaxy Kirin V10] [desktop] build NFS to realize disk sharing
随机推荐
DDL statement of MySQL Foundation
Write a program that uses pointers to set all elements of an int array to 4.18: 0.
If you don't know these four caching modes, dare you say you understand caching?
183 sets of free resume templates to help everyone find a good job
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
Use C to extract all text in PDF files (support.Net core)
The bamboo shadow sweeps the steps, the dust does not move, and the moon passes through the marsh without trace -- in-depth understanding of the pointer
[Galaxy Kirin V10] [desktop] login system flash back
Article publishing experiment
按键精灵打怪学习-识别所在地图、跑图、进入帮派识别NPC
Write a program to judge whether the two arrays are equal, and then write a similar program to compare the two vectors.
[Galaxy Kirin V10] [server] set time synchronization of intranet server
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
Introduction to tree and binary tree
MPLS: multi protocol label switching
DNS hijacking
On binary tree (C language)
Velodyne configuration command
Virtual machine configuration network
/*Write a function to open the file for input, read the contents of the file into the vector container of string class 8.9: type, and store each line as an element of the container object*/