- 【Execution test】>>>>Get download PDF address
- Use a JSON extractor to extract the URL in the response data.
- Intercept the URL suffix path. (BeanShell post-processing program)
import org.apache.commons.lang.StringUtils; String ss=StringUtils.substringBeforeLast("${downloadurl}", "/") ; String sss=StringUtils.substringAfterLast("${downloadurl}", "/") ; String ssss=StringUtils.substringAfter(ss, "//") ; vars.put("downurl",ssss); vars.put("downurlpath",sss); System.out.println(ss); System.out.println(sss); System.out.println(ssss);
-
【Execute test】>>>Download PDF and verify
-
Write download content into PDF file (BeanShell post-processing program)
import java.io.*; byte[] result = prev.getResponseData(); String file_name = "C:/Users/Administrator/Downloads/test/Invitation_Parent_${test_centername}${__time(yyyy-MM-dd)}en.pdf"; File file = new File(file_name); FileOutputStream out = new FileOutputStream(file); out.write(result); out.close();
-
Assert whether the downloaded file exists, exist, delete the file (BeanShell post-processing program)
import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.RandomAccessFile; StringBuffer fileBuf=new StringBuffer(); String filePar = "C:/Users/Administrator/Downloads/test/Invitation_Parent_${test_centername}${__time(yyyy-MM-dd)}en.pdf"; File myPath = new File( filePar ); if(!myPath.exists()) { Failure=true; FailureMessage = "error, check"; } else { Failure=false; FailureMessage = "ok!"; myPath.delete(); }