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.
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.
https://docs.katalon.com/katalon-studio/tutorials/create_custom_keyword.html
** 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.