Application scenario:
Every written use case is on each tester's computer. For a long time, many test cases will disappear inexplicably due to personnel replacement. Therefore, it is hoped to add a saving function on Xmind2testcase platform, which can uniformly save all the written use cases to the test server for reference by relevant personnel in the future
Idea:
In preview Add a save button under the HTML page. After clicking this button, you need to have permission to judge (because after the company uses xmind to import the use cases, you can send the preview page to R & D \ product \ project manager and others for viewing. This button can only be clicked by testers to determine the final version of the test cases). After judgment, save the relevant use case files locally
Effect achieved:
Use the Xmind2testcase platform and import the XMIND file in preview Add the save local button under HTML. After the tester confirms that this version is the final version, click this button to judge whether the current host ip is the tester's ip. If so, save the uploaded XMIND and csv files to a folder of the corresponding server. If it is not the tester's ip, a prompt of no permission will pop up; When the saved file exists locally, it will be updated to ensure that the saved file is the latest version
The implementation and code of function points are as follows:
1. Save to local function (Click Save to create a folder under the specified path, and create a separate project folder for each uploaded use case, which contains xmind files and csv files)
Modify preview HTML file, add save button:
<div> <a href="{{ url_for("local_save", filename= name) }}"> <input style="font-size: 22px;margin-top: -120px;margin-right:150px;float: right" type="submit" class="pure-button " id="save" value="Save final version" /> </a> </div>
Modify application Py file, add local_save function:
@app.route('/local_save/<filename>') def local_save(filename): # Save file to local method full_path = join(app.config['UPLOAD_FOLDER'], filename) if not exists(full_path): abort(404) path = r"E:/Testcase/" # File you want to create if os.path.isdir(path) == False: # If the file does not exist, it is created os.mkdir(path) dir_path = path + filename[:-6] # Path for each project if os.path.isdir(dir_path) == False: # After uploading the project, judge dir_ Is there a folder for the project under the path? If not, create it os.mkdir(path + filename[:-6]) listdir = os.listdir(dir_path) for i in range(len(listdir)): # Judge whether the uploaded file name already exists in the folder if listdir[i] == filename: os.unlink(dir_path + '/' + listdir[i]) # Delete duplicate files and replace duplicate files elif listdir[i][:-4] == filename[:-6]: os.unlink(dir_path + '/' + listdir[i]) zentao_csv_file = xmind_to_zentao_csv_file(full_path) # Generate csv file csv_path = os.path.abspath(zentao_csv_file) # Get current file address shutil.move(full_path, dir_path) # Move the xmind file to the specified folder shutil.move(csv_path, dir_path) # Move the csv file to the specified folder return render_template('savefile.html')
You also need to add a successfully saved page savefile html:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>XMind2TestCase</title> <link rel="shortcut icon" href="{{ url_for('static',filename='favicon.ico') }}" type="image/x-icon"/> <link rel="stylesheet" type="text/css" media="all" href="{{ url_for('static',filename='css/pure-min.css') }}"> <link rel="stylesheet" type="text/css" media="all" href="{{ url_for('static',filename='css/custom.css') }}"> </head> <style> body{ text-align:center} #main{ margin-top: 20%} </style> <body> <div class="splash-container" > <div class="splash" id="main"> <h1> Saved successfully! </h1> <h2><a href="{{ url_for("index") }}" style="color:#FFFFFF; text-shadow: 5px 5px 11px rgba(0, 0, 0, 0.58);">Go Back</a></h2> </div> </div> </body> </html>
2. After clicking the Save button, you need to add a permission judgment (use ip to add permission judgment. When the tester clicks save, judge whether the tester's computer ip is consistent with the written ip. If not, jump to the prompt page without permission)
application.py file, modify the above local_save function:
@app.route('/local_save/<filename>') def local_save(filename): # Save file to local method ip_List = ['Here, enter the information that can be saved ip'] # ip list hostname = socket.gethostname() # Get host name ip = socket.gethostbyname(hostname) # Get the host ip for i in range(len(ip_List)): # Traverse ip list if ip_List[i] == ip: # If the ip is consistent with the one in the list, execute file saving full_path = join(app.config['UPLOAD_FOLDER'], filename) if not exists(full_path): abort(404) path = r"E:/Testcase/" # File you want to create if os.path.isdir(path) == False: # If the file does not exist, it is created os.mkdir(path) dir_path = path + filename[:-6] # Path for each project if os.path.isdir(dir_path) == False: # After uploading the project, judge dir_ Is there a folder for the project under the path? If not, create it os.mkdir(path + filename[:-6]) listdir = os.listdir(dir_path) for i in range(len(listdir)): # Judge whether the uploaded file name already exists in the folder if listdir[i] == filename: os.unlink(dir_path + '/' + listdir[i]) # Delete duplicate files and replace duplicate files elif listdir[i][:-4] == filename[:-6]: os.unlink(dir_path + '/' + listdir[i]) zentao_csv_file = xmind_to_zentao_csv_file(full_path) # Generate csv file csv_path = os.path.abspath(zentao_csv_file) # Get current file address shutil.move(full_path, dir_path) # Move the xmind file to the specified folder shutil.move(csv_path, dir_path) # Move the csv file to the specified folder return render_template('savefile.html') else: return render_template('permissions.html', name=filename)
New permissions HTML page, prompt page without saving operation permission (a name parameter will be returned to the permissions.html page, and there is use case data when it can be returned to the preview.html page):
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>XMind2TestCase</title> <link rel="shortcut icon" href="{{ url_for('static',filename='favicon.ico') }}" type="image/x-icon"/> <link rel="stylesheet" type="text/css" media="all" href="{{ url_for('static',filename='css/pure-min.css') }}"> <link rel="stylesheet" type="text/css" media="all" href="{{ url_for('static',filename='css/custom.css') }}"> </head> <style> body{ text-align:center} #main{ margin-top: 20%} </style> <body> <div class="splash-container" > <div class="splash" id="main"> <h1> No permission to perform save operation! </h1> <h2><a href="{{ url_for('preview_file',filename = name )}}" style="color:#FFFFFF; text-shadow: 5px 5px 11px rgba(0, 0, 0, 0.58);">Go Back</a></h2> </div> </div> </body> </html>
The above completes this small function. If you have problems or need to modify the current source code, you can send private letters or comments!