Changing the Android Device's Date and Time through Ranorex

Mobile Testing, Android App Testing.
ArtMed
Posts: 13
Joined: Tue Oct 08, 2013 2:20 am

Changing the Android Device's Date and Time through Ranorex

Post by ArtMed » Wed Nov 06, 2013 9:29 pm

Hey,

So there are some automations that I want to create that deal with having to first go into the Android device's settings menu, go to date and time menu and change the date and time of the Device (basically going back in time), then start my app and continue on from there.

My question is if there is a way to have Ranorex record my touches going into the devices setting menu; the reason I ask is because when I try to use the recorder, it doesn't record any of my touches that are outside of my AUT.

Thanks!

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Changing the Android Device's Date and Time through Ranorex

Post by krstcs » Thu Nov 07, 2013 2:40 pm

At this time, there is no way to automate operating system actions in Android. You cannot instrument those packages, which is required to automate with Ranorex. This is a limitation of the security model of Android, not a Ranorex issue.

The only solutions I see would be to (1) build your own version of Android, injecting Ranorex's libraries where you want, but I'm not sure how that would work, or (2) build your own shell app that changes the desired settings and instrument that shell app.
Shortcuts usually aren't...

lucian.teodorescu
Posts: 82
Joined: Fri Oct 24, 2014 10:58 am
Location: Bucharest

Re: Changing the Android Device's Date and Time through Ranorex

Post by lucian.teodorescu » Thu May 14, 2015 2:30 pm

Even if this thread is very old, I would like to post here a solution (rather than open another thread).

A bit of user code could help (although you need to make sure that the "automatic date&time" option is unchecked on your device Settings>Date&Time).

Code: Select all

//don't forget to add:
using System.Diagnostics;

public void changeDateTime(){
//your path to adb.exe goes here:
string pathToAdb = "C:\\..\\Android SDK\\sdk\\platform-tools\\adb.exe";      

//save the new system date&time in a string:
string newDateTime = "YYYYMMDD.HHmmss";
         	
Report.Info("INFO", "New SYSTEM date&time " + newDateTime); 
			
#region Genymotion player identification (when two or more players are running the same time; remove this region if not aplicable)

string playerTitleBar = repo.GenymotionAndroidVirtualDevice.GenymotionTitleBar.Element.GetAttributeValueText("Text");
string ipAddress = playerTitleBar.Substring(playerTitleBar.Length-14);

#endregion
        	
Process adbChageDateTime= new Process();
            
adbChageDateTime.StartInfo.FileName  = pathToAdb;

// uncomment and use next line if you are using the code from region above
// adbChageDateTime.StartInfo.Arguments = string.Format("-s "+ipAddress+":5555 shell date -s "+newDateTime);

adbChageDateTime.StartInfo.Arguments = string.Format(" shell date -s "+newDateTime);
adbChageDateTime.Start();        	
adbChageDateTime.WaitForExit();
}
Cheers!
Lucian Teodorescu
NetSun Software