当前位置:网站首页>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
边栏推荐
- Evolution from monomer architecture to microservice architecture
- C language structure to realize simple address book
- Development guidance document of CMDB
- Button wizard business running learning - commodity quantity, price reminder, judgment Backpack
- C language - stack
- Quick sort (C language)
- Introduction to extensible system architecture
- Huge number (C language)
- Container cloud notes
- MPLS: multi protocol label switching
猜你喜欢

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

Use the data to tell you where is the most difficult province for the college entrance examination!

Realsense of d435i, d435, d415, t265_ Matching and installation of viewer environment

Vs201 solution to failure to open source file HPP (or link library file)

Hidden C2 tunnel -- use of icmpsh of ICMP

leetcode842. Split the array into Fibonacci sequences
![[Galaxy Kirin V10] [server] set time synchronization of intranet server](/img/f8/0847314029930840c91bce97ccd961.jpg)
[Galaxy Kirin V10] [server] set time synchronization of intranet server

【Day1】 deep-learning-basics
![[machine] [server] Taishan 200](/img/e5/69a1a4ca04814a033a77d3cb4601b3.jpg)
[machine] [server] Taishan 200

基于线性函数近似的安全强化学习 Safe RL with Linear Function Approximation 翻译 2
随机推荐
[Galaxy Kirin V10] [desktop and server] FRP intranet penetration
[Galaxy Kirin V10] [server] system startup failed
Virtual machine configuration network
Reasons and solutions for the 8-hour difference in mongodb data date display
Rhcsa learning practice
Rhsca day 11 operation
Online troubleshooting
Learning XML DOM -- a typical model for parsing XML documents
Dos:disk operating system, including core startup program and command program
Rhcsa - day 13
MFC document view framework (relationship between classes)
[Galaxy Kirin V10] [server] set time synchronization of intranet server
Const's constant member function after the function; Form, characteristics and use of inline function
183 sets of free resume templates to help everyone find a good job
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
Tables in the thesis of latex learning
/*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*/
leetcode1229. Schedule the meeting
OSPF comprehensive experiment
Es entry series - 6 document relevance and sorting