Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload a file/photo using katalon studio?

I'm trying to upload file using katalon studio for automation testing (web Testing. After clicking on 'Browse' button the windows popup is opened but i can't choose photo or go to specific path. I found a command WebUI.UploadFile() but I think I'm not using it correctly.

If anyone had something like this, please share your experience. How could i do this in katalon?

like image 497
M.Mortada Avatar asked Jul 30 '17 08:07

M.Mortada


People also ask

Is Katalon studio still free?

The free license offers core features of the low-code test automation experience in Katalon Studio. You can see a breakdown of features available to free users here: Katalon Studio vs Katalon Studio Enterprise Features. Currently, the free license does not include Katalon Runtime Engine and console mode features.

Is Katalon studio paid?

Katalon Studio has a free version and offers a free trial. Katalon Studio paid version starts at US$170.00/month.


1 Answers

You can give this solution a try:

  1. Create the following custom keyword (https://docs.katalon.com/display/KD/Define+custom+keywords):
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

public class WebUICustomKeyword { 
    @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); 
    } 
}
  1. Replace 'Upload File' step with that custom keyword in your test case instead, e.g:
CustomKeywords.'com.katalon.WebUICustomKeyword.uploadFile'(findTestObject('BrowseButton'), 'yourFileHere')
like image 98
Hung D. Pham Avatar answered Sep 18 '22 09:09

Hung D. Pham