当前位置:网站首页>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
边栏推荐
- Hlk-w801wifi connection
- Latex arranges single column table pictures in double column format articles
- leetcode1-3
- OSPF comprehensive experiment
- Collection of practical string functions
- 【Day2】 convolutional-neural-networks
- /*Rewrite the program, find the value of the element, and return the iterator 9.13: pointing to the found element. Make sure that the program works correctly when the element you are looking for does
- /*The rewriter outputs the contents of the IA array. It is required that the type defined by typedef cannot be used in the outer loop*/
- Knapsack problem and 0-1 knapsack problem
- DCL statement of MySQL Foundation
猜你喜欢
DDL statement of MySQL Foundation
Network connection (II) three handshakes, four waves, socket essence, packaging of network packets, TCP header, IP header, ACK confirmation, sliding window, results of network packets, working mode of
Remove linked list elements
20 minutes to learn what XML is_ XML learning notes_ What is an XML file_ Basic grammatical rules_ How to parse
Sword finger offer 05 (implemented in C language)
MongoDB数据日期显示相差8小时 原因和解决方案
Architecture introduction
OSPF summary
Idea SSH channel configuration
Rhcsa learning practice
随机推荐
Sword finger offer 31 Stack push in and pop-up sequence
/*The rewriter outputs the contents of the IA array. It is required that the type defined by typedef cannot be used in the outer loop*/
如果不知道這4種緩存模式,敢說懂緩存嗎?
Basic data types of MySQL
Student achievement management system (C language)
Rhcsa - day 13
Native div has editing ability
Tables in the thesis of latex learning
20 minutes to learn what XML is_ XML learning notes_ What is an XML file_ Basic grammatical rules_ How to parse
The most detailed teaching -- realize win10 multi-user remote login to intranet machine at the same time -- win10+frp+rdpwrap+ Alibaba cloud server
Architecture introduction
Knapsack problem and 0-1 knapsack problem
Read a piece of text into the vector object, and each word is stored as an element in the vector. Convert each word in the vector object to uppercase letters. Output the converted elements in the vect
[Galaxy Kirin V10] [desktop and server] FRP intranet penetration
Ruby time format conversion strftime MS matching format
Recursion and divide and conquer strategy
Hlk-w801wifi connection
Rhcsa day 9
[Galaxy Kirin V10] [server] NUMA Technology
[untitled]