當前位置:首頁 » 編程語言 » 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();

熱點內容
存儲停止運行什麼意思 發布:2025-08-21 06:29:09 瀏覽:339
如何取消網路電視的登錄密碼 發布:2025-08-21 05:58:26 瀏覽:896
win10要求電腦什麼配置 發布:2025-08-21 05:56:52 瀏覽:952
騰訊視頻清理緩存 發布:2025-08-21 05:55:20 瀏覽:698
編程讓我著迷 發布:2025-08-21 05:22:28 瀏覽:765
80d怎麼看存儲 發布:2025-08-21 05:21:39 瀏覽:338
刺激戰場國際服安卓怎麼登不了 發布:2025-08-21 05:14:01 瀏覽:17
混沌序列加密圖像 發布:2025-08-21 04:54:21 瀏覽:955
從哪裡找微博登錄密碼 發布:2025-08-21 04:32:34 瀏覽:444
java輸出三角形 發布:2025-08-21 04:31:43 瀏覽:705