Use the following Robot custom keyword for downloading files from a Chrome browser tab.
Assuming you have a package called tools do the following:
From within Katalon Studio right click on ‘Keywords’ > 'New '> ‘tools’ > ‘Keyword’.
Input a ‘Class Name’, e.g., RobotFileSave and click ‘OK’.
Copy and paste the following over the default values.
Save the changes.
Copy and paste CustomKeywords.‘tools.RobotFileSave.SaveFile’() to any test case where a file download is required.
package tools
//Robot imports
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 internal.GlobalVariable
/** Use: Add CustomKeywords.'tools.RobotFileSave.SaveFile'() to any test case **/
/** Saves file to the local download folder **/
public class RobotFileSave {
@Keyword
def SaveFile() {
//Waits for last action on page
Thread.sleep(2000)
Robot robot = new Robot()
//Simulate key press action
robot.delay(2000)
robot.keyPress(KeyEvent.VK_CONTROL)
robot.keyPress(KeyEvent.VK_S) //Constant for the "S"ave as key.
//Simulate key release action
robot.keyRelease(KeyEvent.VK_CONTROL)
robot.keyRelease(KeyEvent.VK_S) //Constant for the "S"ave as key.
//Simulate key press & release action
robot.delay(2000)
robot.keyPress(KeyEvent.VK_ENTER)
robot.keyRelease(KeyEvent.VK_ENTER)
}
}
/**List of robot.keyPress Keys: https://docs.oracle.com/javase/8/docs/api/java/awt/event/KeyEvent.html **/