Katalon Studio Native Popup Window and Upload File


#1

In this article, I would like to mention the solution I found regarding uploading any local file in the test step during the test with Native Popup Window.

All the objects we record with the record in the test case are the descriptions in the relevant web page.

However, if you select a local file from anywhere in the project and have a step to install, the test step will be blocked in this section and you will not be able to select the file from the local and select it in the test step.

For this case, it will be more functional to create a custom keyword that performs this process step and to perform file upload with this keyword in the related steps of the test cases.

Then let’s start.

I have a file upload area in my test project below. When I click on this field while saving the project steps with record, Native Popup Window opens and I have to select a file from local. I’m selecting and installing the file, but Catalon Studio can’t save my processing steps in the popup.

res1 res23

As a solution to this problem, we should first select a local file and create a custom keyword that will perform the installation process.

To add a custom keyword, you can get help from the link below.

** STEP 1: ** The content of the following code is added to the keyword content we create.

Here are the following:

***** package ** test ** must be the same as the package name you defined when creating a custom keyword.

  • public class ** testclass ** must be the same as the keyword name you defined when creating a custom keyword.

  • The following libraries in the code should be imported because they are not defined by default when the keyword is defined.

** import com.kms.katalon.core.annotation.Keyword **
** import com.kms.katalon.core.testobject.TestObject **
** import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI **
** import internal.GlobalVariable **

  • Finally, ** def uploadFile (TestObject to, String filePath) ** The keyword function is created. The first parameter consists of the input field in which the file is to be loaded, the other parameter will be used to refer to the file path of the file to be loaded.

      package test
    
      import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
      import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
      import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
      import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
    
      import com.kms.katalon.core.annotation.Keyword
      import com.kms.katalon.core.checkpoint.Checkpoint
      import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
      import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
      import com.kms.katalon.core.model.FailureHandling
      import com.kms.katalon.core.testcase.TestCase
      import com.kms.katalon.core.testdata.TestData
      import com.kms.katalon.core.testobject.TestObject
      import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
      import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
      import java.awt.Robot
      import java.awt.Toolkit
      import java.awt.datatransfer.StringSelection
      import java.awt.event.KeyEvent
    
      import com.kms.katalon.core.annotation.Keyword
      import com.kms.katalon.core.testobject.TestObject
      import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
      import internal.GlobalVariable
    
      public class testclass {
    
      @Keyword
      def uploadFile (TestObject to, String filePath) {
      WebUI.click(to)
      StringSelection ss = new StringSelection(filePath);
      Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
      Robot robot = new Robot();
      robot.keyPress(KeyEvent.VK_ENTER);
      robot.keyRelease(KeyEvent.VK_ENTER);
      robot.keyPress(KeyEvent.VK_CONTROL);
      robot.keyPress(KeyEvent.VK_V);
      robot.keyRelease(KeyEvent.VK_V);
      robot.keyRelease(KeyEvent.VK_CONTROL);
      robot.keyPress(KeyEvent.VK_ENTER);
      robot.keyRelease(KeyEvent.VK_ENTER);
      }
      }
    

** STEP 2: ** The defined custom keyword is added to the test step. Then, the content of the related step in the script field should be expressed as follows.

CustomKeywords. testtest.testclass.uploadFile '(findTestObject, ile C: \ Users \ Desktop \ test data file )

The file related to these steps can be uploaded on the web page.

In your projects, you can select files from local and use them easily by creating custom keyword mentioned above.

I hope it has been a useful post.


How to Upload a file from windows explorer
[WebUI] Upload File
How to select a file from a folder
how to upload file from system in katalon
Katalon Studio Windows Pop Up
#2

Hi @emine

Great post. Just a small tip: You should style your code with Preformatted Text because it will be much more easy to read. Another one is to take advantage of the styling our editor provides to emphasize the test steps and the structure of your post.

Regards !


#3

Hi @ThanhTo
Thank you for small tip .
Regards …


#4

Hi Emine, in step #2 above, how do you find the “TestObject” used in the customkeyword’s uploadFile command? I can’t figure-out how to find a windows explorer object using object spy. Please help so I can give move forward with trying to implement this example. Thank you very very much.


#5

Hello @tracy_ellis
To download the file on the web page first click on the relevant field. If you do not detect it, right click on the mouse with the mouse to detect this area and add it to the object repostory part.

example field picture


After this step, the test case steps are opened as shown in the following image and custom keywords are selected. You should follow the steps in the image below.

The next step assigns the keyword e.
The first parameter is the path of the file upload area, the part I mentioned above, which can be detected by the right click if it is not detected by the recorder. Please can you look above example field picture

the second parameter refers to the path of the file in the local.
For example: C: \ TEST \ test.txt

regards …


#6

Thank you, this works great when I’m running a single test, but when I’m running a suite(or collection) of tests the native fileUpload window get lost behind all of the other open windows on my desktop and I find Robot trying to write text in places I don’t want it written. Is there anyway to ensure the FileUpload Windows desktop window is in the front before Robot tries to write to it? I know how to ensure a browser window is on top, but I cannot figure out how to ensure a native Windows window(fileUpload) is on top(or in front).


#7

This is a known issue with Robot. You need to cover all the circumstances it is likely to encounter; but if you’re executing suites, that might prove extremely difficult (if not impossible).

My advice: To keep yourself sane, restrict these kinds of tests to single-purpose testing desktops