How to upload a file in Mobile Browser - Android

@Elly_Tran @vu.tran @duyluong
How to upload a file in Mobile Browser. Below is the sample url

https://the-internet.herokuapp.com/upload

I have set up the Mobile browser automation using the below documentation.

https://docs.katalon.com/docs/legacy/katalon-studio-enterprise/test-design/web-test-design/testing-web-app-on-mobile-browsers

You can try with the UploadFile keyword on WebUI first and try with mobile.

1 Like

@quan.trinh

The upload is not working, the page is crashing. I ran the test on a physical device.

Mobile_Upload_File

It looks like you found a bug in the AUT…

@mwarren04011990 Manually - In mobile device it is working fine. Only via automation it is failing.

The file to be uploaded into Mobile Web Browser, is placed in my Laptop (C:\Users\UserName\Desktop\TEST.pdf). Is that OK?

@Elly_Tran @vu.tran @duyluong, @ThanhTo , @Jass
Kindly help. Your help is higly appreciated.

mhm, i am not familiar with mobile testing, so you can call me stupid.
for my eyes, you are testing a certain application on a mobile device.
but the file to upload is on your PC from where you start the test.

something does not fit here…

perhaps the file should be on the mobile device also?

Hi,

I have the same guess as @bionel . Can you please try upload the same file to web browser (Firefox, Chrome, etc) first to test whether your file is valid or uploadFile by Katalon is working well? Follow this doc or this video. As well, please help provide us the log you receive.

1 Like

My Script is working fine in Chrome & Firefox browser in Windows 10 Desktop.

Thanks, I have followed the document & Video as well.

In case of Mobile browser testing, where should the “file to uploaded” be placed?

Is there any other additional configuration / settings to done in case mobile browser upload. Kindly Clarify.

Thanks :slightly_smiling_face:

I read How to upload / attach file using Appium | Selenium Easy in order to understand how people test uploading files in Mobile. In this article, when you started uploading, you want to choose a file from “Files” folder on the Mobile device.

Files


I think, you must do a preprocessing: you have to somehow transfer the file from your Windows’ C:\Users\UserName\Desktop\TEST.pdf into the Mobile device’s "Files" folder. Only after you have prepared the fixture file, you can test uploading the file from the Mobile devices’ "Files" folder.

How to prepare the file on the Movile devices’ “Files” folder? ---- I don’t know. Possibly you want to bundle the fixture PDF file in the APK file?

Wherevere you like, is your device.
C:\Users\UserName\Desktop\TEST.pdf cannot be a valid path, since there is no way to mount your PC drive into the mobile device.
E.g for my android device, i am opening the Files application, go to whatever folder, long tap on a certain file to select it, and from More > Details I can see what is the path.

See:

You can either download the file from a certain location straight on your phone, or upload it via data cable.

I have pasted my pdf file in the android device.

WebUI.uploadFile(findTestObject('Upload_File'), '/storage/emulated/0/Download/dummy.pdf')

But still the script is failing.

Caused by: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: unknown error: path is not absolute: /storage/emulated/0/Download/dummy.pdf

are you sure that is the right absolute path, from your device point of view?
you are not reading fully our hints, so we cannot help you anymore.
the only think i can suggest right now is, change your username into discover.appium
cheers!

The absolute path is correct to best of my knowledge.

your knowledge may be wrong.
that is from adb point of view.

LE: ok, i was nasty but you don’t help us much.
explore the file path from the device point of view, i already gave some hints

@Elly_Tran, @vu.tran

Hi there,
I am also facing the same challenge to Upload document from Real mobile device (Android v9) and from Emulator (Android v11).

Actually, I tried the below both solutions:

  1. WebUI.uploadFile(testObject(browse_Btn), “/storage/emulated/0/Download/UploadDoc.pdf”)
  2. WebUI.sendKeys(testObject(Downloads_Icon), ‘D’)

I am unable to Upload the file from required location (e.g. Download folder) in Android device due to the below errors using WebUI uploadFile(), sendKeys() methods:

WebUI.uploadFile() - Error:
Caused by: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: 'input[type='file']' located by 'input[type='file']' not found

WebUI.sendKeys() - Error:
Unable to send keys 'D' to object '//*[@resource-id = 'android:id/text1']'

Caused by: org.openqa.selenium.InvalidElementStateException: Cannot set the element to 'D'. Did you interact with the correct element?

Is there any way to Upload File from the Location directly using the Android File path as highlighted in below screenshot.

Regs,
Venkat

Hi @Elly_Tran @vu.tran, @Jass Has anyone from Katalon dev team tried the upload file in Android mobile browser. Kindy confirm. Appreciate your support :slight_smile:

In the below thread it is mentioned as:
@Zarashima
Unfortunately, ‘Upload File’ keyword can only access a file from a local machine, so it will not understand device’s path in case you try to upload it from your mobile device

How to set upload file path in Android device (Samsung S3) - Archive - Katalon Community

Hi,

Katalon has not supported keywords for mobiles yet. You can try to reach the following docs:

@Elly_Tran, @vu.tran @duyluong

I am able to upload document in mobile chrome browser using the below approach.

After the below execution of code, Upload document is successful using Mobile.switchToNative(). But unable to handle the web elements in chrome browser.

Could you please tell how to switch back to Mobile Chrome browser.

I tried Mobile.switchToWebView(), but it is failing. Could you please help me in this regard.

'Click "Browse" button'
browser.Click.usingJS(testObject(FileUpload_btn))

'Switch to Native View'
Mobile.switchToNative()

'Click Allow - Permission'
Mobile.tap(findTestObject('Mobile/android.widget.Button0 - ALLOW'), 0)

'Click Allow - Permission'
Mobile.tap(findTestObject('Mobile/android.widget.Button0 - ALLOW'), 0)

'Select Documents Folder'
Mobile.tap(findTestObject('Mobile/android.widget.TextView0 - Documents'), 0)

'Select the pdf file'
Mobile.tap(findTestObject('Mobile/android.view.View0'), 0)

'The below build in keyword is failing so commenting'
// Mobile.switchToWebView()

'Click "Close" upload document icon- the below line is also failing'
// browser.Click.usingJS(testObject('mat-icon[id=\'btnClose\']'))