I’m writing a test case for a native mobile app. On some screens there can be 1 to 4 objects that have similar resource-id, index and even xpath properties. That’s due to the way the app was written.
I tried using Mobile.tapAtPosition but it failed. Searching the community, I found that this is an acknowledged issue which should be addressed in version 10 of Studio.
How can I differentiate between these objects so I can reference each of them independently?
Welcome to our community. We have a recording video guiding about this problem, find it here.
Step-by-step guide:
// uninstall the current uiautomator2
appium driver uninstall uiautomator2// go to <<user directory>>/.katalon/tools/android_sdk/platform-tools then open a terminal/cmd there, run the following command
./adb devices
./adb shell pm list package -3// You will see the list as below:
package:io.appium.settings
package:io.appium.uiautomator2.server.test
package:io.appium.uiautomator2.server
package:io.appium.android.apis
package:com.example.myapplication// uninstall the old uiauotmator2 server
./adb uninstall io.appium.uiautomator2.server.test
./adb uninstall io.appium.uiautomator2.server// re-install the new uiautomator2 at your root folder
appium driver install uiautomator2@2.45.1
@aviv.te tapAtPosition will likely not make a very reliable test and has a much higher chance of breaking with future changes than using object identifiers. It looks like there is a workaround to get tapAtPosition working but I would suggest looking for another way to solve your issue.
One strategy I have used is to look for a parent object that is unique because sometimes the object you are looking for may be unique when you look only at child objects of the unique parent object.
If you always know how many like objects will be on the screen and are in an expected order you can find the like objects and always select the one in the list you are looking for.
If those don’t work you may ask that developers add unique identifiers for these objects.
So I thought it was working well, but then I discovered that every time I disconnect the mobile device and re-connect it, I need to repeat the uninstallation of io.appium.uiautomator2.server, otherwise I’m getting these errors:
=============== ROOT CAUSE =====================
Caused by: org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command 'C:\\Users\\AvivT\\.katalon\\tools\\android_sdk\\platform-tools\\adb.exe -P 5037 -s 15261FDD4004DT install -r C:\\Users\\AvivT\\.appium\\node_modules\\appium-uiautomator2-driver\\node_modules\\appium-uiautomator2-server\\apks\\appium-uiautomator2-server-debug-androidTest.apk' exited with code 1'; Command output: adb: failed to install C:\Users\AvivT\.appium\node_modules\appium-uiautomator2-driver\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-debug-androidTest.apk: Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE: Existing package io.appium.uiautomator2.server.test signatures do not match newer version; ignoring!]
I tried uninstalling the app from the device and let Studio install a fresh version, but that didn’t work.
Also tried uninstalling uiautomator2 v2.45.1 and re-installing the most updated version, but still having the same problem. I really don’t understand what’s causing this issue.