Android app base element is not valid after app update

Mobile Testing, Android App Testing.
piotrn
Posts: 16
Joined: Fri Mar 25, 2011 3:04 pm

Android app base element is not valid after app update

Post by piotrn » Thu Aug 08, 2013 10:08 am

Hi

I have a problem where the base (root) adapter reference for an Android app is NOT valid after the app is updated via some user action. This problem requires the base adapter to be found again after every user action. Also it's not clear how long to delay before the search operation as the base gets invalid after some time when the app eventually updates.
Is this a known problem? Has anybody got this working on a real mobile device?

The following example code shows the problem.
The app is deployed in an Android Emulator (adt-bundle-windows-x86-20130729, AVD_for_Nexus_S_by_Google).
The provided (IronPython) code example is using the Android APIDemos app.
Note that the same logic in C# has the same problem...

Code: Select all

import clr
clr.AddReference('Ranorex.Core')
clr.AddReference('Ranorex.Plugin.Mobile')
import time
from Ranorex.Core import RxPath
from Ranorex import MobileApp, AndroidApp, Text, Host

mobile_device = 'AA'
mobile_app = 'com.example.android.apis'
mobile_app_id = "/mobileapp[@title='com.example.android.apis']"
find_normal_delay = 30000 

Host.Local.RunMobileApp(mobile_device, mobile_app)
app = Host.Local.Find[MobileApp](RxPath(mobile_app_id), find_normal_delay)[0]
assert(app.Valid, "Base app reference is NOT valid")

choice_id = "./form[@title='ApiDemos']/container/list/text[@caption='App']"
list_choice = app.Find[Text](RxPath(choice_id), find_normal_delay)[0]
assert(list_choice.Valid)
list_choice.Click()

time.sleep(10) # allow for the app to update

assert(app.Valid, "Base app reference is NOT valid")
choice_id = "./form[@title='ApiDemos']/container/list/text[@caption='Alarm']"
list_choice = app.Find[Text](RxPath(choice_id), find_normal_delay)[0]
assert(list_choice.Valid)
list_choice.Click()

time.sleep(10) # allow for the app to update
Host.Local.CloseApplication(app.Element)

piotrn
Posts: 16
Joined: Fri Mar 25, 2011 3:04 pm

Re: Android app base element is not valid after app update

Post by piotrn » Fri Aug 09, 2013 10:28 am

Apparently for Android apps the base/root adapter reference gets invalid when performing user actions. This implies that all GUI objects have to be found with a root path.
Also 'Touch' user action is better than 'Click' for mobile apps :)

The updated example:

Code: Select all

import clr
clr.AddReference('Ranorex.Core')
clr.AddReference('Ranorex.Plugin.Mobile')
from Ranorex.Core import RxPath
from Ranorex import MobileApp, Text, Host

mobile_device = 'AA'
mobile_app = 'com.example.android.apis'
mobile_app_id = "/mobileapp[@title='com.example.android.apis']"
find_normal_delay = 30000

Host.Local.RunMobileApp(mobile_device, mobile_app)
app = Host.Local.Find[MobileApp](RxPath(mobile_app_id), find_normal_delay)[0]
assert(app.Valid, "Base app reference is NOT valid")

choice_id = mobile_app_id + "/form[@title='ApiDemos']/container/list/text[@caption='App']"
list_choice = Host.Local.Find[Text](RxPath(choice_id), find_normal_delay)[0]
assert(list_choice.Valid)
list_choice.Touch()

choice_id = mobile_app_id + "/form[@title='ApiDemos']/container/list/text[@caption='Alarm']"
list_choice = Host.Local.Find[Text](RxPath(choice_id), find_normal_delay)[0]
assert(list_choice.Valid)
list_choice.Touch()

choice_id = mobile_app_id + "/form[@title='ApiDemos']/container/list/text[@caption='Alarm Service']"
list_choice = Host.Local.Find[Text](RxPath(choice_id), find_normal_delay)[0]
assert(list_choice.Valid)

Host.Local.CloseApplication(app.Element)

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Android app base element is not valid after app update

Post by Support Team » Fri Aug 09, 2013 2:59 pm

Hello,

Could you please explain in more detail what do you mean with "the base/root adapter reference gets invalid"?
Do you mean that the root path ("/mobileapp[@title='com.example.android.apis']") changes the value if you perform some actions?
I am not sure which reference do you mean.
Thank you!

Regards,
Bernhard

piotrn
Posts: 16
Joined: Fri Mar 25, 2011 3:04 pm

Re: Android app base element is not valid after app update

Post by piotrn » Mon Aug 12, 2013 10:27 am

Hi
Let's say the top application adapter for the Android APIDemos app is found with:

Code: Select all

mobile_app_id = "/mobileapp[@title='com.example.android.apis']"
app = Host.Local.Find[MobileApp](RxPath(mobile_app_id), find_normal_delay)[0]
Now some action can be performed using the 'app' adapter:

Code: Select all

choice_id = "./form[@title='ApiDemos']/container/list/text[@caption='App']"
list_choice = app.Find[Text](RxPath(choice_id), find_normal_delay)[0]
assert(list_choice.Valid)
list_choice.Touch()
Now if we try again to find/validate a new GUI object of the app by using the available 'app' adapter, the code will fail:

Code: Select all

choice_id = "./form[@title='ApiDemos']/container/list/text[@caption='Alarm']"
list_choice = app.Find[Text](RxPath(choice_id), find_normal_delay)[0]
assert(list_choice.Valid)
list_choice.Touch()
I've got different errors:
- the connection to the application is not available anymore
- the 'app' adapter is not valid
- 'app.Find' call times out and cannot find the GUI object even if it's there

The 'app' adapter is NOT valid anymore after the first user action. The app top window RxPath is NOT changed by any user action.

Cheers

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Android app base element is not valid after app update

Post by Support Team » Wed Aug 14, 2013 4:10 pm

Hello,

It seems that the connection to your app gets lost.
This issue could be related with the Android emulator.
Is it possible to try it with your physical device?
Android app is NOT valid after the app is updated via some user action.
Could you please describe in detail what you mean with 'user action'?
Which actions are performed?
What do you mean with 'app is updated'?

Regards,
Markus (T)

piotrn
Posts: 16
Joined: Fri Mar 25, 2011 3:04 pm

Re: Android app base element is not valid after app update

Post by piotrn » Mon Aug 19, 2013 8:44 am

Hi
In this discussion thread I've provided two code examples using the Android APIDemos app.

The example code performs a simple test with two user actions:
- the APIDemos is started
- the user selects 'App' menu item
- the user selects 'Alarm' menu item

The first example implementation fails when the user selects 'Alarm' . The text element 'Alarm' cannot be found relative to the 'app' element. The 'app' element is simply not valid anymore after executing the first user action that was to select/touch the 'App' text element. Note that the app is updated with a new set of elements in the menu after selecting 'App' but the top 'app' element should not be updated or get invalid.

The second implementation of the same test scenario works because all graphics elements are found using a root Ranorex path.

It is possible that the described problem is specific when using the Android Simulator. Unfortunately I don't have a real Android phone device to test the same scenario for comparison. The Android APIDemos app is included in the Android SDK so Ranorex support should be able to check and clarify this problem.

Cheers

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Android app base element is not valid after app update

Post by Support Team » Thu Aug 22, 2013 2:25 pm

Hello!

It seems like this issue is caused by our service app if the tested app is missing a manifest setting*. This error leads to an invalid app channel. We will fix this in further releases. Until then your source code looks fine and you should have no problem to try Ranorex with another demo application.

(*) Service is looking for the versionName tag in the app manifest which is missing for APIDemos.apk You should have no problem with any application which has a versionName set.
<manifest xmlns:android=http://schemas.android.com/apk/res/android
package="ranorex.android"
android:versionCode="1"
android:versionName="1.0">
Regards,
Florian

shayanjameel08
Posts: 2
Joined: Sat Oct 12, 2013 11:43 am

Re: Android app base element is not valid after app update

Post by shayanjameel08 » Mon Oct 14, 2013 11:12 am

'Touch' user action is better than 'Click' for mobile apps :)