Why does .pdf file only show the last line within the if statements but not the other steps of the if statement?
I searched the forum and found someone else brought up this issue in 2018? I’m still facing this same problem, was this ever resolved?
Handling errors in Katalon Studio using Groovy with if-else statements can be quite effective. Here’s a basic example to help you get started:
Basic if-else Structure:
Use verifyElementPresent or verifyElementVisible with FailureHandling.OPTIONAL to avoid stopping the test if an element is not found.
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.model.FailureHandling
if (WebUI.verifyElementPresent(findTestObject('Object Repository/YourObject'), 10, FailureHandling.OPTIONAL)) {
WebUI.click(findTestObject('Object Repository/YourObject'))
} else {
WebUI.comment('Element not found, proceeding with alternative steps.')
// Alternative steps
}
Using try-catch for Error Handling:
This approach can be useful for more complex error handling.
try {
WebUI.click(findTestObject('Object Repository/YourObject'))
} catch (Exception e) {
WebUI.comment('An error occurred: ' + e.message)
// Handle the error, e.g., take a screenshot, log the error, etc.
}
Combining if-else with try-catch:
For robust error handling, you can combine both methods.
try {
if (WebUI.verifyElementPresent(findTestObject('Object Repository/YourObject'), 10, FailureHandling.OPTIONAL)) {
WebUI.click(findTestObject('Object Repository/YourObject'))
} else {
WebUI.comment('Element not found, proceeding with alternative steps.')
// Alternative steps
}
} catch (Exception e) {
WebUI.comment('An error occurred: ' + e.message)
// Handle the error
}
These examples should help you manage errors effectively in your Katalon tests.
My tests are not failing. I gave a very simple example here, but in fact my if loop has, read excel, add Users, Add other data related to users…etc All these actions pass, records are being created. I use try and catch everywhere I can; however I don’t use Failure Handling as much as I should, I will try that. This still does not fix the problem of PDF report not showing all the detailed steps within the loop.
I’m sorry I can’t share my report on public forum, but all you have to do is create a simple if loop like this.
if(abc)
{
Print statement 1
Print statement 2
}
pdf report will only show print statement 2, at least that’s what I’m experiencing.
I could see that the PDF report prints only the last step inside a for loop.
I think I could understand what @mqamar discussed about.
With the limit = 9999, the TS1 passed. It took 78 seconds on my M1 Macbook Air. The size of HTML report was 1.2 Mbytes. The size of PDF report was just 7 Kbytes.
It is obvious that Katalon developers designed their product intentionally as such.
I would support their design because I can guess what Katalon developers thought. Let’ imagin a case where KS is changed to include all the steps inside the for loop to be reported in a PDF, and I set a large number to the for loop limit; Say limit=98765. Then, I believe, the byte size of a PDF file will get gigantic — some Giga bytes or more. Such large PDF file is not usefull, is just an obstacle. Probablly Katalon developers experienced such a case in the early days of their product development. So they decided to make their product not to inlude too much details in a PDF.
Just checking in to see if everyone else in this thread were able to answer your original question(s) or not?
If yes, then don’t forget to mark helpful replies as a solution so that others who may be asking similar questions / running into similar problems can find the solution as well!
Hey @albert.vu, Where could @mqamar post their pdf requirement, others might find it useful too?
We never bother with *pdf reports because they do not list enough details so we use the *.html reports.
Why do you want the PDF report to be improved for you?
The HTML report is enough for your debugging job, isn’t it?
Do you have any specific reason why you stick to the PDF format? For example, you want to attach the report into your organizational database which accepts PDF but rejects HTML?
The current PDF report shows the last 1 line within a segment of for loop. I guess that the current implementation has a constant value “limit=1” somewhere . Then it should not be very difficult to change the limit from 1 to 25 or 50 as @mqamar requires.
There’s no requirement for PDF, it’s mainly used when we want to review the results (failed tests) next day. I have not looked into html report, will review them after the weekend. Thanks