Android App PressBackKey has no effect

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

Android App PressBackKey has no effect

Post by piotrn » Thu Aug 08, 2013 9:32 am

Hi

I cannot get any effect using the PressBackKey while testing an Android app. There is no effect for the PressKeyBack action.

Is this a known problem? Has anybody got this working on a real mobile device?

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)

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

AndroidApp(app.Element).PressBackKey()

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 PressBackKey has no effect

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

Apparently
PressKeys("{BACK}")
call is better to use for go-back user action:

Code: Select all

normal_delay = 30000 
...
app = Host.Local.Find[MobileApp](RxPath(mobile_app_id), normal_delay)[0]
app.PressKeys("{BACK}")
Note also that the app adapter reference must be found again before the KeyPress because it might be invalid because of previous app user action.

Cheers

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Android App PressBackKey has no effect

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

Hello,

I would recommend to use the PressKeys("{BACK}") method. If you take a look in the code, which is created by Ranorex Studio you will see that Ranorex also generates PressKeys("{BACK}") when you click the back button.
The method PressBackKey() is more or less for internal use in Ranorex.
In general I would also recommend to use the MobileApp capability and not the AndroidApp capability.

Regards,
Bernhard
.
Image