当前位置:首页 » 编程语言 » python编写测试脚本

python编写测试脚本

发布时间: 2024-11-27 10:47:13

⑴ 怎样用python脚本生成一个html格式的测试报告

比如很简单的,可以这样:
# -*- coding:utf-8 -*-
import os,sys

html = open('index.html', 'w')
html.write("""
<html>
<head>
<title>Test</title>
<style>img{float:left;margin:5px;}</style>
</head>
<body>
""")

files = os.listdir('.')

# 首先处理文本
for f in files:
if f.lower().endswith('.txt'):
fp = open(f)
content = fp.read()
fp.close()
html.write("<p>%s</p>" % content)

# 然后处理图片
for f in files:
if f.lower().endswith('.jpg') or f.lower().endswith('.png'):
html.write("<img src='%s' />" % f)

html.write('</body></html>')
html.close()

把这个python代码放在有图片和txt文本的目录里,运行就可以了。如果不是jpg,修改增加png,gif就行了。

⑵ 如何用python写一个脚本,来跑java代码上的cucumber集成测试

1.直接执行Python脚本代码
引用 org.python包
1 PythonInterpreter interpreter = new PythonInterpreter();
2 interpreter.exec("days=('mod','Tue','Wed','Thu','Fri','Sat','Sun'); "); ///执行python脚本


2. 执行python .py文件
1 PythonInterpreter interpreter = new PythonInterpreter();
2 InputStream filepy = new FileInputStream("D:\\demo.py");
3 interpreter.execfile(filepy); ///执行python py文件
4 filepy.close();


3. 使用Runtime.getRuntime()执行脚本文件
这种方式和.net下面调用cmd执行命令的方式类似。如果执行的python脚本有引用第三方包的,建议使用此种方式。使用上面两种方式会报错java ImportError: No mole named arcpy。
1 Process proc = Runtime.getRuntime().exec("python D:\\demo.py");
2 proc.waitFor();

热点内容
sql数据溢出 发布:2025-05-17 04:55:14 浏览:731
java金额 发布:2025-05-17 04:51:48 浏览:288
安卓怎么下应用 发布:2025-05-17 04:46:52 浏览:554
算法健壮性 发布:2025-05-17 04:41:10 浏览:856
jquery文件上传进度条 发布:2025-05-17 04:39:50 浏览:221
信息技术脚本模板 发布:2025-05-17 04:39:00 浏览:258
写sql跑 发布:2025-05-17 04:38:58 浏览:252
openharmony编译依赖 发布:2025-05-17 04:32:45 浏览:610
什么叫双十一配置 发布:2025-05-17 04:14:31 浏览:979
翼状胬肉使用氟尿嘧啶怎么配置 发布:2025-05-17 04:14:24 浏览:976