当前位置:网站首页>XMIND to excel test case
XMIND to excel test case
2022-06-25 21:17:00 【Next Lu Kou】
xmind turn Excel The test case
One 、 introduction
As a test point worker , We need to write test cases often , We usually use xmind perhaps freemain Write the map first , Then write our test cases according to the guide diagram . Can we directly convert the contents of the map into Excel Test cases ,… With ideas , Start to act , Test people don't advise , Began to dry .
Two 、 Environmental preparation
Point work generally uses python Mostly , This time we also use python To write a script to realize this requirement , I learned from the Internet xmindparser The library can parse xmind File data , Support will xmind File resolved to dict、json、xml data type . After the data analysis is completed , You also need to store the parsed data Excel in ,python Handle Excel Lots of Libraries , What I use here is openpyxl library .
python 3.7.1
xmindparser 1.0.9
openpyxl 3.0.9
The above describes the libraries used this time , There's another point ,xmind Everyone writes the map differently , How should we analyze and form a unified standard , So we should make a rule to write the map , Here is a rule I made , This rule will be explained later . Rules are not the only , It can be made according to the actual situation .
The central theme : Project title
Secondary title : Module title
Three level title : Use case title
The fourth level title : Operation steps
Five level titles : Expected results
3、 ... and 、 scripting
1、 Read xmind file
Read xmind File data ,xmind_to_dict(xmind_file_path)[0][“topic”] The returned data is as shown in the figure , When we read the file, we take out the branch data under the central topic and the secondary directory , For subsequent processing .
The code is as follows :
from xmindparser import xmind_to_dict
def read_xmind_data(xmind_file_path):
""" Read xmind file , Return to the central topic title and other branches list data :param xmind_file: xmind File path :return: """
case_data_dict=xmind_to_dict(xmind_file_path)[0]["topic"]
title = case_data_dict["title"]
data_list=case_data_dict["topics"]
return title,data_list
2、 According to the read data , Parsing data
We have read the data above , First, analyze the data structure , We found each one topics There are all next level list, We can use loops or recursion to extract data , And form a similar : Sign in - Enter the correct account and password to log in - Enter the login page - Successfully entered the login page The data of this structure .
The returned data is as follows :
The code is as follows :
def xmind_to_caselist(data_list,title,listcase,strcase=''):
""" Based on the incoming list data , Recursively parse the data , form : Sign in - Enter the correct account and password to log in - Enter the login page - Successfully entered the login page The data of :param data_list: After passing in and parsing list :param strcase: Initial string , The default is empty. :param listcase: Storing use case data list :return: Return the data of each use case list """
for branch_one in data_list:
strcase_one = strcase + branch_one['title'] + '_'
if 'topics' not in branch_one:
# Branch does not exist topics when , Add data to listcase in
strcase_one=title+'_'+ strcase_one
listcase.append(strcase_one)
continue
branch = branch_one['topics']
# recursive , Traverse all branches
xmind_to_caselist(branch,title,listcase,strcase=strcase_one)
return listcase
3、 Define the test case title
At present, my company uses tapd,tapd The test case template used in is marked with the title :ID Use case catalog Use case name precondition Use case step Expected results Use case types Use case status Use case level . Some of the titles are generally unchanged , I'll use the default value . Returned from above listcase data , Split the data and compose a use case , A use case is a list, Convenient for subsequent writing Excel in .
The returned data is as follows :
The code is as follows :
def change_case(listcase,top_term='',case_type=' A functional test ',case_state=' To be updated ',case_grade=' in '):
""" Excel The use case titles in are divided into the following 9 individual (tapd Upload standard on ): ID Use case catalog Use case name precondition Use case step Expected results Use case types Use case status Use case level ID: Self increasing Use case catalog : Project name - Module name for example : XX XX project - Login module Use case name : Extract the three-level title of the incoming data + The fourth level title + Five level titles precondition : The default is empty. , You can fill in the general data by yourself Use case step : Four level title of extracted data Expected results : Five levels of titles for extracting data Use case types : The default value is function test , Other values can be filled in as : Performance testing , Safety test Use case status : The default value is to be updated , Other values can be filled in as : normal , obsolete Use case registration : The default value is medium , Other values can be filled in as : high , low :param data_list: Incoming from xmind Decomposed into list data :param top_term: precondition :param case_type: Use case types :param case_state: Use case status :param case_grade: Use case level :return: Return to take a use case as a list The data of , for example [[ Use cases 1],[ Use cases 2],[ Use cases 3]] """
total_case=[]# The overall use case format list
case_id=1
for data in listcase:
case_list=[]# Of each use case list
data_sp=data.split('_')
case_list.append(case_id)
case_list.append(data_sp[0]+"-"+data_sp[1])
case_list.append(data_sp[2]+','+data_sp[3]+','+data_sp[4])
case_list.append(top_term)
case_list.append(data_sp[3])
case_list.append(data_sp[4])
case_list.append(case_type)
case_list.append(case_state)
case_list.append(case_grade)
total_case.append(case_list)
case_id+=1
return total_case
4、 Data writing Excel in
In the above steps , Data sorting has been completed , Use openpyxl The library completes the writing of data and adjusts the style accordingly .
The code is as follows :
def write_excel_case(total_case,save_path):
""" Write the parsed data to Excel in :param total_case: Parse the finished data :param save_path: File save path :return: """
wb=Workbook()
ws=wb.active
ws['A1']='ID'
ws['B1']=' Use case catalog '
ws['C1']=' Use case name '
ws['D1']=' precondition '
ws['E1']=' Use case step '
ws['F1']=' Expected results '
ws['G1']=' Use case types '
ws['H1']=' Use case status '
ws['I1']=' Use case level '
i=1
for case in total_case:
ws['A{}'.format(i + 1)] = case[0]
ws['B{}'.format(i + 1)] = case[1]
ws['C{}'.format(i + 1)] = case[2]
ws['D{}'.format(i + 1)] = case[3]
ws['E{}'.format(i + 1)] = case[4]
ws['F{}'.format(i + 1)] = case[5]
ws['G{}'.format(i + 1)] = case[6]
ws['H{}'.format(i + 1)] = case[7]
ws['I{}'.format(i + 1)] = case[8]
i+=1
column_list = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I']
cell_list = ['A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1', 'H1', 'I1']
# Set header font
font=Font(name=' Song style ',bold=True)
for cel in cell_list:
cell=ws[cel]
cell.font=font
# Set column table center
alignment = Alignment(horizontal='center',wrapText=True)
for col_name in column_list:
col_list = ws[col_name]
for col in col_list:
col.alignment = alignment
# Set the width of the column
ws.column_dimensions['B'].width = 20
ws.column_dimensions['C'].width = 60
ws.column_dimensions['D'].width = 30
ws.column_dimensions['E'].width = 30
ws.column_dimensions['F'].width = 30
ws.column_dimensions['G'].width = 15
ws.column_dimensions['H'].width = 15
ws.column_dimensions['I'].width = 15
# Set the height of the row
for x in range(2,ws.max_row+1):
ws.row_dimensions[x].height = 40
wb.save(save_path)
5、 Operation entrance
The functions required by the script have been completed in the above steps , Here is the script function to run :
The code is as follows :
def run_main(xmind_file_path,save_path,top_term='',case_type=' A functional test ',case_state=' To be updated ',case_grade=' in '):
""" :param xmind_file_path: xmind File path :param save_path: File save path :param top_term: precondition :param case_type: Use case types :param case_state: Use case status :param case_grade: Use case level :return: """
title,data_list=read_xmind_data(xmind_file_path)
listcase=xmind_to_caselist(data_list,title,[])
total_case = change_case(listcase, top_term=top_term,case_type=case_type,case_state=case_state,case_grade=case_grade)
write_excel_case(total_case,save_path)
The operation result is as follows :
Four 、 summary
Implementing this requirement is not very difficult , It mainly uses the corresponding library to parse data and save , At present, only scripts have been implemented , Continue to learn , I want to convert the script into Tkinter Desktop application , Easier to use .
边栏推荐
- What is machine learning? (Fundamentals)
- STM32 self balancing robot project, with code, circuit diagram and other data attached at the end (learning materials and learning group at the end)
- C language dynamic memory allocation
- Shell scripts: Variables
- ThreadLocal class
- JS__ Inheritance mode, namespace, object enumeration__ Duyi
- Explain memcached principle in detail
- [machine learning] machine learning from zero to mastery -- teach you to understand the principle of decision tree
- 股市小白通过网上进行股票开户安全吗?
- Must see the summary! In depth learning era, you should read 10 articles to understand image classification!
猜你喜欢
Lantern Festival, learning at the right time! Novice training camp attacks again, learning buff continues to fill up
[nailing scenario capability package] enterprise and public institution intelligent access control
Must see the summary! In depth learning era, you should read 10 articles to understand image classification!
Install JDK, MySQL and nexus under Linux (tar package installation)
[nail scenario capability package] hospital visitor verification
Write a "standard" macro min, which inputs two parameters and returns the smaller one
New generation engineers teach you how to play with alluxio + ml (Part 2)
How to play one to many in JPA?
05 configuring network parameters
MySQL is slow to add indexes_ Why is your SQL so slow? Why is your MySQL index invalid?
随机推荐
js (1)
Yolov4 reading notes (with mind map)! YOLOv4: Optimal Speed and Accuracy of Object Detection
Is it safe for Xiaobai to open a stock account online?
Kubernetes related knowledge - surprise interview
Molecular dynamics - basic characteristics of molecular force field
Illustrated with pictures and texts, 700 pages of machine learning notes are popular! Worth learning
Leetcode theme [array] -31- next spread
Yunzhisheng atlas supercomputing platform: computing acceleration practice based on fluid + alluxio (Part I)
01 network basics
On merging and sorting
Lesson 1 Preparation
[nailing scenario capability package] exhibition admission
C language dynamic memory allocation
Analysis and cleaning of kdevtmpfsi virus content
[important notice] developer document update (12.13-12.19)
Compile 6relayd using the cross compiler
Flexible scale out: from file system to distributed file system
Is flush app regular? Is it safe or not
How to solve the problem of flash write protection in STM32?
Mysqldumpslow out slow statements in the database