Page 1 of 1

Send ADB commands via Ranorex?

Posted: Sat Mar 04, 2017 12:25 am
by Otter_T
I'm looking for a way to automate the enabling/disabling of mobile data connectivity on an Android device. The purpose for this is to verify that the AUT returns a "no internet access" message if a user attempts to open the app when their device has no mobile data connectivity, or if their device loses connectivity while the app is in use.

I'm able to remotely disable mobile data connectivity on the device by opening an ADB prompt and entering the adb shell svc data disable command. Is there a way I can incorporate this step into a .rxrec file?

Thank you.

Re: Send ADB commands via Ranorex?

Posted: Mon Mar 06, 2017 3:48 pm
by asdf
Hi Otter,

You could trigger an ADB prompt through a small code method. In the following example I retrieved the language of the Android device.
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
					
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.FileName = @"C:\Program Files (x86)\Ranorex 6.2\Bin\RxEnv\Android\tools\adb.exe";
startInfo.Arguments += "shell getprop persist.sys.localedefault";
process.StartInfo = startInfo;
process.Start();
		
Report.Info(process.StandardOutput.ReadToEnd());
Please make sure to adapt the path to the adb.exe, according to your Ranorex version.

I hope this helps.

Re: Send ADB commands via Ranorex?

Posted: Mon Mar 06, 2017 4:57 pm
by Otter_T
asdf,

Perfect! I created one code module to disable mobile data, and another to re-enable it. I can now simulate loss of connectivity at any point during a test run. Exactly what I was looking for.

Thank you!!! :D :D :D