我想要一种方法来更新wiki状态页面并在JMeter测试运行完成后上传文件。 这是你可以根据你的 Jenkins 工作的结果有条件地开始的事情。
我通过以下步骤完成了此操作:
-
在安装线程组中,添加了 BeanShell 采样器以在我的结果文件夹中查找最新的报告文件。
import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter; import org.apache.commons.io.filefilter.WildcardFileFilter; import org.apache.commons.io.comparator.LastModifiedFileComparator;
log.info("GET MOST RECENT RESULTS REPORT FOR THE APP TESTED"); String dir_path = props.get("test_results_path"); File theNewestFile = null; try { File dir = new File(dir_path); FileFilter fileFilter = new WildcardFileFilter("Results_${testApp}*.*"); File[] files = dir.listFiles(fileFilter); if (files.length > 0) { /** The newest file comes first **/ Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE); theNewestFile = files[0]; String fileName = files[0].getName().toString(); log.info("fileName: "+fileName); print("fileName: "+fileName); props.put("varResultsReportFile",fileName); } return theNewestFile; } catch (Throwable ex) { log.error("Failed in Beanshell", ex); throw ex; }
-
使用维基/汇合系统帐户登录
- 获取
rest/api/content?title=${testApp}&spaceKey=${testSpaceKey}&expand=version,history
- 使用 JSON 提取程序提取页面版本号 (
results..version.number
) 和页面 ID(results..id
) - 使用 BeanShell 后处理器将 1 添加到页面版本号中,并将该值存储在变量中。当您将更新放入维基时,您将需要它
- 获取
rest/api/content?title=${testApp}&spaceKey=${testSpaceKey}&expand=body.storage
- 使用JSON提取器扩展页面正文值(
results..body.storage.value
) - 在步骤 7 中创建的 JMeter 变量上使用 CSS/JQuery 提取器,提取所有表值。例如,CSS/JQuery 表达式=td 和匹配 No= 1 来提取第一列值。
- PUT
rest/api/content/${varPageId}
并在 JSON 正文中更新需要更新的单个表值,并还原提取的不需要更新的值。 - POST
rest/api/content/${varResultsPageId}/child/attachment
对于"文件上载"选项卡,"文件路径=${__P(test_results_path)}${__P(varResultsReportFile)},参数名称=文件,MIME 类型=文本/csv - 注销