Page 1 of 1

Android & get time

Posted: Wed Mar 06, 2019 2:16 pm
by SanMan
Connected to Nokia 3.0

Is it possible to get the current time?

Image

/mobileapp[@title='Android OS']/form[@rid='R.id.statusBarBackground']

Re: Android & get time

Posted: Thu Mar 07, 2019 9:35 am
by RobinHood42
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

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

Re: Android & get time

Posted: Thu Mar 07, 2019 2:10 pm
by SanMan
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?

Re: Android & get time

Posted: Mon Mar 11, 2019 10:06 am
by RobinHood42
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

Re: Android & get time

Posted: Wed Mar 13, 2019 11:40 am
by SanMan
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?

Re: Android & get time

Posted: Wed Mar 13, 2019 12:42 pm
by odklizec
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

Re: Android & get time

Posted: Wed Mar 13, 2019 2:03 pm
by SanMan
Thank you for the links.

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