1、安装python,准备转换文件generate_case_csv_file.py
# -*- coding: utf-8 -*-
import sys
import os
import csv
import json
import hashlib
import requests
from xmindparser import xmind_to_dict
class ZentaoSession(requests.Session):
url_root = 'http://zentao.tangees.com/zentao/index.php'
url_login = url_root + '?m=user&f=login&t=json'
url_get_modules = url_root + '?m=testcase&t=json'
url_create_modules = url_root + '?m=tree&f=manageChild&root={_id}&view=case&t=json'
url_pre_page = url_root + '?m=tree&f=browse&productID={_id}&view=case'
def login(self, account, password):
cred = {
'account': account,
'password': hashlib.md5(password.encode('utf8')).hexdigest(),
'keepLogin[]': 'on'
}
r = self.post(self.url_login, data=cred)
return r.status_code == 200 and r.json()['status'] == 'success'
def set_product_in_cookies(self, product_name):
r = self.get(self.url_get_modules)
if r.status_code == 200 and r.json()['status'] == 'success':
products = json.loads(r.json()['data'])['products']
self.product_path_id_map = {v: k for k, v in products.items()}
if product_name in self.product_path_id_map:
self.product_id = self.product_path_id_map[product_name]
else:
print('项目不存在:' + product_name)
exit(0)
temp_cookie = requests.cookies.RequestsCookieJar()
temp_cookie.set(
'lastProduct', str(self.product_id),
domain='zentao.tangees.com', path='/zentao/')
temp_cookie.set(
'preProductID', str(self.product_id),
domain='zentao.tangees.com', path='/zentao/')
self.cookies.update(temp_cookie)
return self
def get_modules_of_product(self, product_name):
self.set_product_in_cookies(product_name)
r = self.get(self.url_get_modules)
if r.status_code == 200 and r.json()['status'] == 'success':
self.zentao_data = json.loads(r.json()['data'])
modules = self.zentao_data['modules']