Android & get time

Mobile Testing, Android App Testing.
SanMan
Posts: 204
Joined: Tue Apr 13, 2010 9:59 am

Android & get time

Post by SanMan » Wed Mar 06, 2019 2:16 pm

Connected to Nokia 3.0

Is it possible to get the current time?

Image

/mobileapp[@title='Android OS']/form[@rid='R.id.statusBarBackground']
Attachments
time.PNG
time.PNG (21.88 KiB) Viewed 274 times

User avatar
RobinHood42
Posts: 308
Joined: Fri Jan 09, 2015 3:24 pm

Re: Android & get time

Post by RobinHood42 » Thu Mar 07, 2019 9:35 am

Hello SanMan,

You can use "adb" to fetch the system time of your USB ( ! ) connected Android device:

Get the "Address" of your connected device (needed within the code snippet -> deviceAddress:
AndroidDeviceAddress.png
AndroidDeviceAddress.png (3.27 KiB) Viewed 258 times

and use the following code to fetch the time of your device:
public void GetAndroidSystemTime()
		{
			string adb = @"C:\Program Files (x86)\Ranorex\Studio\Bin\Runtime\RxEnv\Android\Tools\adb.exe";
			string deviceAddress = "00eXXXXXXXce27";
			
			System.Diagnostics.Process proc= new Process();
			
			proc.StartInfo.FileName  = adb;
			proc.StartInfo.Arguments = string.Format("-s {0} shell date ", deviceAddress);
			proc.StartInfo.RedirectStandardOutput = true;
			proc.StartInfo.UseShellExecute = false;

			proc.Start();
			proc.WaitForExit();
			
			//Read redirected output and log to report
			var output = proc.StandardOutput.ReadToEnd();
			Report.Info("Android System Time: " + output);
		}
Hope this helps :mrgreen:

Robin

SanMan
Posts: 204
Joined: Tue Apr 13, 2010 9:59 am

Re: Android & get time

Post by SanMan » Thu Mar 07, 2019 2:10 pm

Hi Robin,

thank you! It worked perfectly!!

Now I have a new problem:

I have a MobileUiElement > AccessibilityLabel (System.String) which I can find with Spy. Also screenshot can also be achieved.

But when this data change, AccessibilityLabel string is not updated, but screenshot is updated.

Is there some command (Refresh/Update/?) that could be used to get the updated AccessibilityLabel string value ?

Is it possible to use somehow JQuery or something?

User avatar
RobinHood42
Posts: 308
Joined: Fri Jan 09, 2015 3:24 pm

Re: Android & get time

Post by RobinHood42 » Mon Mar 11, 2019 10:06 am

Hi SanMan,

Great!

"But when this data change, AccessibilityLabel string is not updated, but screenshot is updated."

How to you access the element. Did you add the element to your repository or do you directly access it via code?

Also please upload a Ranorex snapshot file of the mentioned element: Snapshot files

Cheers,
Robin

SanMan
Posts: 204
Joined: Tue Apr 13, 2010 9:59 am

Re: Android & get time

Post by SanMan » Wed Mar 13, 2019 11:40 am

Hi Robin,

I have add the element to repository.

Is it possible to use JQuery with Ranorex?

$('#status').text();

This is how I can the valid text with browser version & console

Can I somehow do this with user code?

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 5353
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Android & get time

Post by odklizec » Wed Mar 13, 2019 12:42 pm

Hi,

Well, this is not directly Ranorex-related question. It's rather .Net-related question? ;) Generally speaking, it should be possible to call JQuery code from C# code. Have you tried google?...
https://stackoverflow.com/a/17285414
https://stackoverflow.com/questions/172 ... om-c-sharp
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

SanMan
Posts: 204
Joined: Tue Apr 13, 2010 9:59 am

Re: Android & get time

Post by SanMan » Wed Mar 13, 2019 2:03 pm

Thank you for the links.

I got my problem solved by touch() item twice before get value