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)