How to upload a file in Mobile Browser - Android

Hello, this solution seems to be the one working.
You will be able to push a file from your Project repository to the mobile enviroment using:

@Keyword
	public static void pushFileToMobile(String mobileDestinationPath, String localFileCanonicalPath) {
		WebUI.comment('<- Pushing: ' + localFileCanonicalPath + ' to mobile: ' + mobileDestinationPath)
		AppiumDriver<?> driver = MobileDriverFactory.getDriver()
		driver.pushFile(mobileDestinationPath, new File(localFileCanonicalPath))
	}

Now, in the phone I use your approach:

String localFilePath = '/Resources/image1.png'
String localFileCanonicalPath = new File(localFilePath).getCanonicalPath()

String mobileDestinationPath = '/sdcard/Download/image1.png'

CustomKeywords.'mobile.pushFileToMobile'(mobileDestinationPath, localFileCanonicalPath)
	
// Click and prompt mobile File Explorer
WebUI.click(findTestObject('Upload zone'))
	
// Select the first file in download folder from native

// Switch to native to use the File Explorer
Mobile.switchToNative()

// My mobile device opens up the recent images so I just need to select the first one
Mobile.tap(findTestObject('Object Repository/mobile/first image from the menu'),
		0)

Mobile.tap(findTestObject('Done button'),
		0)

// Wait a little so test doesn't bug
Mobile.delay(5)

// Change the context manually NOT using Mobile.switchToWebView()
MobileDriverFactory.getDriver().context('CHROMIUM')

The issue with your version is that the mobile driver cannot find a WebDriver context to change to. Is because is not called WebView is called ‘CHROMIUM’ at least in my case. You can log this:

MobileDriverFactory.getDriver().getContextHandles()

To confirm that you have WEBVIEW available or maybe is being called something else.

Now, this approach doesn’t work in testing cloud using “Mobile Browser” option. I’m getting:

[TEST_STEP][FAILED] - mobile.pushFileToMobile(mobileDestinationPath, localFileCanonicalPath): No application is started yet.

[MESSAGE][FAILED] - No application is started yet.
Reason:
com.kms.katalon.core.exception.StepFailedException: No application is started yet.
	at com.kms.katalon.core.appium.driver.AppiumDriverManager.verifyWebDriverIsOpen(AppiumDriverManager.java:717)
	at com.kms.katalon.core.appium.driver.AppiumDriverManager.getDriver(AppiumDriverManager.java:692)
	at com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory.getDriver(MobileDriverFactory.java:253)
	at webMobile.NativeUtils.pushFileToMobile(NativeUtils.groovy:59)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:55)
	at TC-36 Upload a Sticker to PM (Using upload button) (Page maker).run(TC-36 Upload a Sticker to PM (Using upload button) (Page maker):53)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:448)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:439)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:418)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:410)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:285)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:369)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:369)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:369)
	at com.kms.katalon.core.common.CommonExecutor.accessTestCaseMainPhase(CommonExecutor.java:65)
	at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(TestSuiteExecutor.java:150)
	at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:106)
	at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:180)
	at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)
	at TempTestSuite1727328384865.run(TempTestSuite1727328384865.groovy:35)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

Hi there, :wave:

Thank you very much for your topic! It may take a little while before Katalon team member or others forum members respond to you.

In the meantime, you can double-check your post to see if you can add any extra information i.e. error logs, HTML codes, screenshots, etc. Check out this posting guide to help us help you better!

Thanks! :sunglasses:
Katalon Community team

@vmokkapati
To upload files to Android applications through Katalon Studio, it’s better to use mobile keywords instead of WebUI methods.

Open the file directly via URI
Mobile.startActivity('content://com.android.providers.downloads.documents/document/raw%3A%2Fstorage%2Femulated%2F0%2FDownload%2FUploadDoc.pdf')

Navigating through the system file manager

Mobile.tap(findTestObject('Downloads_Folder'), 10)
Mobile.tap(findTestObject('UploadDoc.pdf'), 10)

For corporate solutions where data security is important (e.g., financial or medical applications), it’s necessary to additionally verify file integrity. My collegues from Andersen often use SOC services to monitor such operations 24/7. Make sure that in the Object Repository, Downloads_Folder and UploadDoc.pdf have correct resource IDs.

This method works on both real devices (Android 9+) and emulators.

P.S. For complex projects where testing is part of the DevOps cycle, it’s better to integrate a threat monitoring system to automatically upload files and check them for vulnerabilities.