Hi team, how to add steps to verify and compare data in downloaded file with data in the web application?
I believe it may depend on the type of file that is being downloaded. If it is a pdf, then I would say no. If the file will be in a different format every time, then I would again have to say noâunless you know the format, how are you going to get the âdataâ. If it is a text file and the file will be in the exact same format, then you may be able to, however, there is no out-of-the-box method. You will have to program it yourself, using File IO. Take a Google Search to see what you can get.
Saying the above, is it worth the trouble to get the data off the file? Instead, can you hard-code the expected data from the file beforehand and verify match the text off the web page? This would be my first method that I would try, but I donât know the whole story.
Hi Arpitha,
If downloaded file is Excel, then you can verify data with excel keywords,
You can install Excel Keywords plugin from Katalon store.
https://store.katalon.com/product/34
Thanks.
I have to download the Reports from the application (Example: Table Report) or a Chart (Ex.: Bar Chart) in Excel, PDF and CSV formats or in Image format (if it is a Chart) and I have to verify if that file is downloaded and compare the data between downloaded file and the Report in the application.
So, how can I do this in Katalon Studio? Can you please explain with simple steps?
If the downloaded file is in CSV or PDF format, what keywords we can use to verify and compare the data?
For PDF you canât compare data and for CSV you need to use File IO method just as @grylion54 has suggested.
No, I canât. You provided no information. and your question seems to be no simple at all.
- Please tell us the URL of application page you are interested in
- Please tell us the URL of the downloadable file, or tell us the procedure how to get it
- Please specify which specific data in the page and the downloadedf file you want to verify (= test the equality of 2 items).
- If the URL is not public to the Internet (so that others can not get access to), you should create a set of mimic and disclose them to the Interenet.
- You should not expect to be told of a magical spell that solves all your problems at once â Katalon Studio is not capable of such magic. You would need to solve your problems by writing custom codes a lot one by one.
Above is the sample Table Report, this Report I have to download and verify if it is successfully downloaded, and I have to verify those column names only (State, Name, Amount and Date)
Could you let us know the 2 URLs: one of the web page, another of the downloadable file?
No I canât share the URLs
If the above is an Excel sheet and the information is on âSheet1â and you know the pathway to the fileâs âlocationâ, then you could go with:
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import com.kms.katalon.core.model.FailureHandling as FailureHandling;
FileInputStream fis = new FileInputStream(**location**)
XSSFWorkbook workbook = new XSSFWorkbook(fis)
XSSFSheet sheet = workbook.getSheet('Sheet1')
Row row = sheet.getRow(0);
Cell cell = row.getCell(0);
heading = cell.getStringCellValue();
WebUI.verifyMatch(heading, "State", false, FailureHandling.STOP_ON_FAILURE)
row = sheet.getRow(0);
cell = row.getCell(1);
heading = cell.getStringCellValue();
WebUI.verifyMatch(heading, "Name", false, FailureHandling.STOP_ON_FAILURE)
Edit: I added the FailureHandling but you donât need it if you review the warning messages the verifyMatch gives.
Hi Team, I have downloaded 1 Record in the application and I have to verify if it is downloaded successfully in Katalon Studio. How to verify this?
Please find the attached screenshot.
Application URL : https://opensource-demo.orangehrmlive.com/web/index.php/recruitment/viewCandidates
Downloaded File : file:///C:/Users/admin/Downloads/resume%20(2).pdf
Finally I understand you want to compare the content of a PDF file and a web page.
It is just difficult to achieve.
PDF is a format for human to read with their eyes.
PDF is not designed for software to reuse its content.
I believe that you should give up your idea.
You may try an exercise of programming: you want to convert a PDF file into a HTML file (= a kind of text) somehow. Then you want to parse the HTML text and extract the data you are interested in.
So your first hardle would be converting the PDF file you downloaded into a HTML file. Possibly you want to use
But this approach would be a very difficult, it will require a good skill of Java programing.
Also, the HTML generated out of a PDF file will be âunstructuredâ. All you can do agaist it would be to search a text you like, and get a boolean result (Yes or No) if the text is present or not. You would be able to verify if a string âJoe Rootâ is found somewhere in the HTML file. But you would not be able to grasp a data row of âJoe Rootâ and extract the row of data out of the HTML.
If you want to confirm what is in the PDF, good luck, however, if you want to confirm that the file has been downloaded, then you can do a count of the files in the Download directory before downloading, then proceed with the download and then do a recount of the Download directory. That process was discussed on this forum a few months back.
Edit1: You can review the code from this OP and see what might be useful to you:
How can I delete specified number of files from a file folder - Product Forums / Katalon Studio - Katalon Community
Edit2: Here is another link (the audio is very poor but pay attention when the gent uses âsizeâ):
List Files from Folder in Katalon studio - YouTube
Edit3: when you do your recount, you could also isolate the ânewâ file that was downloaded and then review the file extension that it was â.pdfâ.
WebUI.verifyMatch("pdf", fileName.split(".")[1].toLowerCase(), false)
Hi Team, I tried with code that you gave by replacing the location as âFileInputStream fis = new FileInputStream(âDownloads/Downloads.xlsâ)
But I am getting error for that location as â element not interactable: [object HTMLDivElement] has no size and locationâ.
The file will get downloaded under âThis PC >> Downloadsâ folder.
Am I missing something?
A couple of things may be needed. I have an example below:
gTestIdPathWay = "G:\\Katalon Test Cases\\Data Files\\TestId RT-WP-012.xlsx";
Give the full pathway and use double slash in your pathway.
So yourâs may be:
C:\\Downloads\\Downloads.xls
Note: you are using an Excel 2007 (or earlier) extension.
Your code
FileInputStream fis = new FileInputStream('Downloads/Downloads.xls')
is wrong. The constructor of java.io.FileInputStream
will never accept a String as argument.
It should rather be:
File downloadsDir = new File(System.getProperty('user.home') + '/Downloads')
File f = new File(downloadsDir, 'Downloads.xls')
FileInputStream fis = new FileInputStream(f)
Hello team, below mentioned code is working fine. After this how can I verify the data inside the downloaded file? I want to verify only first line of the excel sheet (Ex.: Column names)
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter;
import java.util.regex.Matcher
import java.util.regex.Pattern
import java.util.stream.Collectors
// get the current timestamp in the format of yyyyMMdd_hhmmss
LocalDateTime now = LocalDateTime.now()
String timestamp = DateTimeFormatter.ofPattern(âyyyyMMdd_hhmmssâ).format(now)
// prepare a regular expression to match the file
Pattern pattern = Pattern.compile(â^(myFile\-)(\d{8}_\d{6})(\.txt)$â)
// find the Path of âDownloadsâ directory of my OS user
Path userHome = Paths.get(System.getProperty(âuser.homeâ))
Path downloads = userHome.resolve(âDownloadsâ)
println(downloads.toString())
// get the set of files contained in the Downloads directory now (before insertion)
Set previousFileSet = Files.list(downloads).collect(Collectors.toSet())
// insert an anonymous file (equivalent to downloading a file from web)
Path newFile = downloads.resolve(âmyFile-${timestamp}.txtâ)
newFile.toFile().text = âHello, world!â
// get the set of files contained in the Downloads directory now (after insertion)
Set currentFileSet = Files.list(downloads).collect(Collectors.toSet())
// calculate the Relative Complement of the file sets (âafterâ minus âbeforeâ)
Set differenceSet = new HashSet(currentFileSet)
differenceSet.removeAll(previousFileSet)
// how many files were inserted? should be 1 or more
assert differenceSet.size() >= 1
// know the file name
Path differenceFile = differenceSet.toList().get(0)
String fileName = differenceFile.getFileName().toString()
// verify the name of inserted file
Matcher matcher = pattern.matcher(fileName)
assert matcher.matches()
assert matcher.group(1) == âmyFile-â
assert matcher.group(3) == â.txtâ
// now we know the timestamp part of the file name inserted
println âtimestamp was ${matcher.group(2)}â