I wanted a way to update a wiki status page and upload a file after a JMeter test was done running. This is something that you could conditionally kick off depending on the results of your Jenkins job.
1 Answer
I did this with these steps:
in a setup thread group, added a BeanShell Sampler to locate the most recent report file in my results folder.
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; }login with a wiki/confluence system account
- GET
rest/api/content?title=${testApp}&spaceKey=${testSpaceKey}&expand=version,history - Use a JSON Extractors to extract page Version number(
results..version.number) and page id(results..id) - Use a BeanShell PostProcessor to add 1 to the page version number and store that value in a variable. You will need this when you PUT your update into the wiki
- GET
rest/api/content?title=${testApp}&spaceKey=${testSpaceKey}&expand=body.storage - Use JSON Extractor to extact page body value(
results..body.storage.value) - Using a CSS/JQuery Extractor on the JMeter Variable you created in step 7, Extract all the table values. For example,CSS/JQuery Expression=td and Match No= 1 to extract first column value.
- PUT
rest/api/content/${varPageId}and in the JSON body, update the single table value that you need to update and restore the values you extracted that you dont need updated. - POST
rest/api/content/${varResultsPageId}/child/attachmentFor the Files upload tab, File Path=${__P(test_results_path)}${__P(varResultsReportFile)}, Parameter Name=file, MIME Type=text/csv - logout