How to open FileChooser in a Katalon Test Case

I have made a GitHub project published


Background

I have a Katalon Studio project VisualTestingInKatalonStudio. It is a visual testing tool for Web application, built on top of KatalonStudio. The tool takes screenshots of web pages, save them into .png files. I will execute the tool twice β€” before I change my Web Application Under Test, and after I changed it. The tool compares 2 sets of screenshots β€” the current screenshot against the previous one. It produces a concise report if it has detected any differences in the page views. I often use this tool when I upgrade/reconfigure my business Web application in production. One of my Katalon project based on the VisualTestingInKatalonStudio processes 800 URLs in 80 minutes without any human intervention. When I see the report telling me β€œNo Significant difference found in the 800 pages of your AUT”, I am relieved. I get confident that I haven’t made any silly mistakes to the production service. This tool frees me from slavery labor of looking at a lot of URLs manually before/after system changes.

Problem to solve

When I execute a image comparison processing, I need to specify which set of previous screenshots to choose as the basis with which the current screenshots are compared against. The following image shows an example how the previous sets of screenshots are stored and accumulated in a VisualTesting project directory.

VisualTesting project
β”œβ”€β”€ Storage
β”‚   β”œβ”€β”€ CURA.chronos_capture
β”‚   β”‚   └── CURA_DevelopmentEnv
β”‚   β”‚       β”œβ”€β”€ 20200628_231335
β”‚   β”‚       β”œβ”€β”€ 20200701_220844
β”‚   β”‚       └── 20200704_071004
β”‚   β”‚           β”œβ”€β”€ CURA.visitSite
β”‚   β”‚           β”‚   β”œβ”€β”€ appointment.php%23summary.png
β”‚   β”‚           β”‚   β”œβ”€β”€ default%23appointment.png
β”‚   β”‚           β”‚   β”œβ”€β”€ home.png
β”‚   β”‚           β”‚   β”œβ”€β”€ profile.php%23login.png
β”‚   β”‚           β”‚   β”œβ”€β”€ revisited.png
β”‚   β”‚           β”‚   └── γƒˆγƒƒγƒ—.png
β”‚   β”‚           └── material-metadata-bundle.json

The current version (1.19.5) of β€œVisualTestingInKatalonStudio” has a test case script CURA/restorePreviousScreenshots. This selects one of the timestamp directories(yyyyMMdd_hhmmss). The default behavior is to choose the last previous set.

WebUI.callTestCase(findTestCase("Test Cases/VT/restorePreviousTSuiteResult"), 
                    ["STRATEGY":"last"])

Potentially the script can chose any other set if I specify the exact timestamp (e.g, 20200628_231335 ) as:

WebUI.callTestCase(findTestCase("Test Cases/VT/restorePreviousTSuiteResult"), 
        ["STRATEGY":"exactlyAtOrBefore", "timestamp":"20200628_231335" ])

However I do not want to edit CURA/restorePreviousScreenshots script often. I would rather like to interactively visit the directories and select one from the GUI-rendered list.

So my question is: Is it possible to open File Chooser dialog in a Katalon Test Case?

Solution

In a test case script in Katalon Studio, I can use javax.swing.JFileChooser to open a File Chooser.

Description

Just have a look at the sample test case script Test Cases/openJFileChooser .

I worked!

1 Like

I found a problem here.

If I touch anywhere in the Katalon Studio’s window, then the dialog of JFileChoose goes behind the Katalon Studio. I easily miss the dialog.

It is impossible to control the z-index of windows rendered by different processes.


A more serious problem is there. If I click anywhere of the window of Katalon Studio UI before the dialog of JFileChooser comes up, then the dialog will never get visible. I can not see it, I can not interact with it. All I can do is to terminated the test at all. It seems that the dialog looses control where it should render itself if I click the window of Katalon Studio.

So I have to be very careful NOT TO CLICK Katalon Studio before the JFileChooser dialog comes up.

This restriction is a serious one. I think that I should not use JFileChooser dialog within Katalon Studio at all.

If Katalon Studio provides a built-in keyword that shows SWT FileChooser, then it might be possible to keep the dialog is rendered over the Katalon Studio main window and so that I would not miss it.

@ThanhTo

any comment?

1 Like

I could fix the problem β€œJFileChooser dialog goes behind other window, or becomes invisible” by a small code change: