csv - 何在 Jmeter 中删除 csv 文件中的重复项
问题描述
我有一个将输出保存到 CSV 文件的 Jmeter 脚本。在输出(CSV)文件中,我想删除 URL 列表(第 3 列)中的重复项。我怎样才能做到这一点?
csv 文件中的示例行如下:
responsecode, responsemessage,url
404,Not Found,http://test1
404,NotFound,http://test1
404,Not Found,http://test2
404,NotFound,http://test3
404,Not Found,http://test2
预期的:
responsecode, responsemessage,url
404,Not Found,http://test1
404 Not Found,http://test2
404,Not Found,http://test3
任何人都可以帮助如何做到这一点?
谢谢。
解决方案
如果您有一个 CSV 文件,如下所示:
200,OK,http://example.com
404,Not Found,http://example.com/foo
200,OK,http://example.com
404,Not Found,http://example.com/bar
并希望将其转换为以下内容:
200,OK,http://example.com
404,Not Found,http://example.com/foo
404,Not Found,http://example.com/bar
将tearDown 线程组添加到您的测试计划
将JSR223 Sampler添加到 tearDown 线程组
将以下代码放入“脚本”区域:
def dedup = new File('original.csv').readLines().collectEntries { [it.split(',')[2], it] } dedup.entrySet().each { entry -> new File('without-duplicates.csv') << entry.getValue() << System.getProperty('line.separator') }
替换
original.csv
为 CSV 文件的相对路径或完整路径,并替换为文件without-duplicates.csv
的所需名称/位置,不重复
有关 JMeter 中 Groovy 脚本的更多信息:Apache Groovy - 为什么以及如何使用它
推荐阅读
- c# - C# 中开尔文符号 (K) 的 ToLowerInvariant 具有不同的结果
- python - 如何为许多 FastAPI 端点设置多个默认值
- sql - Oracle SQL 周年日期查询
- macos - 使用 curl 下载文件后返回文件名
- c# - HttpClient 401 在生产中但在 ID 中运行时没有
- amazon-s3 - Kafka-s3-connect 启动后立即终止
- python - 默认情况下如何使用预览笔记本编辑器打开jupyter
- paypal - 通过 PayPal API 获取用户的公司名称和国家/地区
- android - 通过 USB 发送 http 请求的 Android 应用
- plot - 如何使用 draw.io 创建高频图?