Send ADB commands via Ranorex?

Mobile Testing, Android App Testing.
Otter_T
Posts: 18
Joined: Mon Aug 31, 2015 5:33 pm

Send ADB commands via Ranorex?

Post by Otter_T » Sat Mar 04, 2017 12:25 am

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.

asdf
Posts: 174
Joined: Mon Mar 21, 2016 3:16 pm

Re: Send ADB commands via Ranorex?

Post by asdf » Mon Mar 06, 2017 3:48 pm

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.

Otter_T
Posts: 18
Joined: Mon Aug 31, 2015 5:33 pm

Re: Send ADB commands via Ranorex?

Post by Otter_T » Mon Mar 06, 2017 4:57 pm

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