Katalon Studio Native Popup Window and Upload File

@htooeaindralin199851 Hello ,
The error is not caused by the keyword, you cannot click on the file upload area. Save the test again and when you get to that area, right click this time. This time it will take all the css. You need relative css information for the relevant field.

@emine.I got it. Thank you so much indeed.

1 Like

You’re welcome

Hey @emine
I was trying to upload a file from my local to the web page. I followed your steps. It uploads the file, but I’m stuck on a part. When it uploads the file, I see a message that the file is in “scanning for viruses”. But, it doesn’t complete. And I can’t move forward because the file upload is not complete as it’s still being scanned for viruses. (Screenshot attached)
However, in my application, when I upload a file manually, it’s being scanned for say max 2-3 seconds and after that I see the upload is complete.
Can you please help me figure out why would it behave differently when done from automated script as compared to manual ? and how to handle this part in automated script ?upload

hello @gurleen.kaur

If your file upload time add delay time.
Exaple : WebUI.delay(10)

@emine… Thanks for the response. Looks like delay was not the issue. I ran the script in incognito mode and it works fine for the upload. may be some issue with cookies and cache

Hi emine,

I’m using a Mac OS and I followed all the steps you mention, and what happens to me is that opens the finder window, and then I see a Java window in my dock that I try to open to see if there is a message or something but I can’t open it, after a few seconds it disappears, some second later Katalon stops running and the step passes (no log error) but at the end it doesn’t select or upload the file like expected. Is there something that you think that could be blocking the upload?

hello @bgonzalez1
Make sure you give the file upload key the exact file path.
Ex: C:\\Users\\emine\\Desktop\\ex.pdf

@emine Hello miss !

I’m very shy now, i followed all the steps, but it’s doesn’t work.

I never worked with Keyword that why I’m not able to solve that problem.

@ferrariklersone Hi,

STEP 1: First of all, after creating a new project, right click on the Keywords file in the Tests Explorer section, and a new package is added by following the steps in the image below.

Package allows the created keywords to be grouped according to a certain category, thus making it easier to search and use the keyword.


STEP 2: Follow the steps in the screenshot below to add a keyword under the created Package.

  1. STEP: After this stage, functionality will be added to the keyword content defined in the remaining steps. The created keyword should consist of the fields listed below.

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 5: Save and open the test case page.
STEP 6: To use the keyword defined on your test case page, select the relevant test case Add> Custom Keyword option.


As a footnote, if the keywords you defined in the Test case add> custom keyword field are not listed, it will be sufficient to right click on the Keywords file in the Tests Explorer section and click the refresh option.

I have described the steps for you step by step with the explanations below. I hope it works for you.

@emine In the test case, i must have the authentification first and upload file second.

but In your steps, you did not show me how the test case must be.

I already have authentification scenario in the test case, how can i add Keyword i created ??

I’m sorry again emine -- --

First, you need to save your test, save the test steps, then add the keyword manually. In other words, you cannot add keywords while saving the test steps.
First you need to save the authentication test steps, then after the process is completed, you should add the keyword to that step in which step you need to upload a file.

Hey all!

I’m having the same issue as stated before. The file path is successfully copied into the File Explorer, but the Enter key press/release is not working, and the File Explorer stays open.

When I first found this solution it worked for me without adding any delay, then 10mins later it did not work, so I added WebUI.delay() into the script after invoking my custom keyword and it worked for 2 runs. I tried putting delays into the keyword method as some of you suggested above, but it’s not working.

I’m wondering if any of you had the same issues as me, and if you had it can you explain it why is it happening/ give me a solution.
Thank you!

Hey All, i have issue in automating upload file. I have added custom keyword to handle the native window pop-up. In my test case there are two upload steps. First upload is successful but when upload the 2nd steps native window pop-up is loaded but just stays there. No upload happens.

I can only suggest putting in delays within the routine. I put a delay after the first click:

WebUI.click(to)
WebUI.delay(1)

and another one at the end:

robot.keyRelease(KeyEvent.VK_ENTER);

WebUI.waitForPageLoad(10)
WebUI.delay(1)

Also, when your TestCase runs, you should not be typing on your keyboard or moving your mouse at all. This is one of the cons of using the robot.

Hi @mirda, This works for me …
How to use the 'Robot Framework' to load files using a custom keyword

And like @grylion54 mentioned do NOT touch your keyboard or mouse while the uploading is happening. It’s the only thing I really hate about Robot.

This might be a better solution:

Hi @adam.stephens, I am currently facing the same issue. May I know what did you do to upload the file?

Hi @sgshashi I would like to know what did you do to upload the file? I am currently facing the same issue.

Hi @jane.austria, see this post: How-to use ‘sendKeys’ or 'File Upload' to upload files

1 Like