欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于python實(shí)現(xiàn)智能用例生成工具

 更新時(shí)間:2023年09月08日 15:49:42   作者:海是倒過來的天~  
這篇文章主要為大家詳細(xì)介紹了如何基于python實(shí)現(xiàn)智能用例生成工具,即根據(jù)輸入的功能點(diǎn),生成通用測(cè)試點(diǎn),感興趣的小伙伴可以跟隨小編一起了解下

工具作用

根據(jù)輸入的功能點(diǎn),生成通用測(cè)試點(diǎn)

實(shí)現(xiàn)步驟

工具實(shí)現(xiàn)主要分2個(gè)步驟:

1.https請(qǐng)求調(diào)用Gpt,將返回響應(yīng)結(jié)果保存為.md文件

2.用python實(shí)現(xiàn) 將 .md文件轉(zhuǎn)換成.xmind文件

3.寫個(gè)簡(jiǎn)單的前端頁(yè)面,調(diào)用上述步驟接口

詳細(xì)代碼

1.調(diào)用gpt請(qǐng)求生成 md文件

import os
import requests
import json
"""測(cè)試數(shù)據(jù)路徑管理"""
SCRIPTS_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DATAS_DIR = os.path.join(SCRIPTS_DIR, "datas")
Testcase_md= os.path.join(DATAS_DIR,'testcase.md')
"""示例代碼"""
def sendGpt_getmd(content):
    # 設(shè)置請(qǐng)求頭中的token
    headers = {
        "Content-Type": "application/json"
    }
    # payload= 設(shè)置請(qǐng)求主體中的參數(shù)和數(shù)據(jù),根據(jù)請(qǐng)求的參數(shù)格式傳參即可
    payload = {"參數(shù)": "參數(shù)值"}
    # 發(fā)送POST請(qǐng)求
    response = requests.post("https://xxxxx", headers=headers,
                             data=json.dumps(payload))
    # 解析響應(yīng)結(jié)果
    if response.status_code == 200:
        result = response.text
        print(result)
        with open(Testcase_md, "w", encoding="utf-8") as f:
            f.write(result)
    else:
        print("請(qǐng)求失??!")
if __name__ == '__main__':
  # 示例用法:keydes為功能標(biāo)題,casecontentTemp為發(fā)送給gpt的模板話術(shù),在使用時(shí)可以將keydes設(shè)置為變量,由前端傳參。另外可以根據(jù)需要修改casecontentTemp內(nèi)容
  # 僅包含一級(jí)標(biāo)題,二級(jí)標(biāo)題,無序列表格式的Markdown形式:該格式不可修改,因?yàn)楹罄m(xù)需要以Markdown格式轉(zhuǎn)換成xmind文件
  keydes='上傳附件'
  casecontentTemp="僅包含一級(jí)標(biāo)題,二級(jí)標(biāo)題,無序列表格式的Markdown形式發(fā)送給我。請(qǐng)寫出 一級(jí)標(biāo)題為'"+keydes+"'的測(cè)試用例,包含功能測(cè)試(正向/逆向/異常場(chǎng)景),性能測(cè)試,安全測(cè)試,兼容測(cè)試"
  sendGpt_getmd(casecontentTemp)

2.將md文件轉(zhuǎn)換成xmind文件

通過步驟1,生成了md文件,以下代碼是將md文件轉(zhuǎn)換成xmind文件

import markdown
from bs4 import BeautifulSoup
import xmind
def md_to_xmind(md_file, xmind_file):
    # 讀取MD文件
    with open(md_file, 'r', encoding='utf-8') as f:
        md = f.read()
    # 解析MD文件
    html = markdown.markdown(md)
    # 創(chuàng)建XMind文件
    workbook = xmind.load(xmind_file)
    # 獲取根節(jié)點(diǎn)
    root_topic = workbook.getPrimarySheet().getRootTopic()
    # 遞歸添加節(jié)點(diǎn)
    def add_topic(parent_topic, node):
        # 添加節(jié)點(diǎn)
        topic = parent_topic.addSubTopic()
        title = node.get('title', '')
        topic.setTitle(title)
        # 添加文本
        if 'html' in node:
            topic.setPlainNotes(node['html'])
        # 遞歸添加子節(jié)點(diǎn)
        if 'children' in node:
            for child in node['children']:
                add_topic(topic, child)
    # 解析HTML,并添加節(jié)點(diǎn)
    soup = BeautifulSoup(html, 'html.parser')
    rootmap_node = {'children': []}
    root_node = None
    current_node = None
    for tag in soup.children:
        if tag.name == 'h1':
            # 創(chuàng)建根節(jié)點(diǎn)
            root_node = {'title': tag.string, 'children': []}
            current_node = root_node
        elif tag.name == 'h2':
            new_node = {'title': tag.string, 'children': []}
            root_node['children'].append(new_node)
            current_node = new_node
        elif tag.name == 'p':
            current_node['html'] = str(tag)
        elif tag.name == 'ul':
            for li in tag.children:
                text = li.text.strip()
                if len(text) > 0:
                    li_node = {'title': text, 'children': []}
                    current_node['children'].append(li_node)
        elif tag.name == 'ol':
            for li in tag.children:
                text = li.text.strip()
                if len(text) > 0:
                    li_node = {'title': text, 'children': []}
                    current_node['children'].append(li_node)
    # 添加節(jié)點(diǎn)
    for node in root_node['children']:
        add_topic(root_topic, node)
    # 修改根節(jié)點(diǎn)的名稱
    root_topic.setTitle(root_node['title'])
    # 保存XMind文件
    xmind.save(workbook, xmind_file)
if __name__ == '__main__':
  # 示例用法 example.md為步驟1生成的文件,通過md_to_xmind方法調(diào)用將.md文件轉(zhuǎn)換成xmind文件
  md_to_xmind('example.md', 'example.xmind')
 

3.合并步驟1,2后運(yùn)行

import os
from scripts.datas.mdtoxmind import md_to_xmind
from scripts.datas.sendGpt import sendGpt_getmd
"""測(cè)試數(shù)據(jù)路徑管理"""
SCRIPTS_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DATAS_DIR = os.path.join(SCRIPTS_DIR, "datas")
Testcase_md= os.path.join(DATAS_DIR,'testcase.md')
Testcase_xmind= os.path.join(DATAS_DIR,'testcase.xmind')
def oneTocase(keydes):
   casecontentTemp="僅包含一級(jí)標(biāo)題,二級(jí)標(biāo)題,無序列表格式的Markdown形式發(fā)送給我。請(qǐng)寫出 一級(jí)標(biāo)題為'"+keydes+"'的測(cè)試用例,包含功能測(cè)試(正向/逆向/異常場(chǎng)景),性能測(cè)試,安全測(cè)試,兼容測(cè)試"
    sendGpt_getmd(casecontentTemp)
    md_to_xmind(Testcase_md, Testcase_xmind)
if __name__ == '__main__':
  # 示例用法
  keydes='上傳附件'
  oneTocase(keydes)

運(yùn)行后結(jié)果:

生成對(duì)應(yīng)文件

打開后查看如下內(nèi)容

后期集成測(cè)試工具構(gòu)思

1.將詳細(xì)代碼中步驟3暴露出rest接口,供前端調(diào)用

2.前端頁(yè)面可提供出形成 通用工具

到此這篇關(guān)于基于python實(shí)現(xiàn)智能用例生成工具的文章就介紹到這了,更多相關(guān)python智能生成工具內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論