Adding a endpoint automatically

Mobile Testing, Android App Testing.
tomwolf
Posts: 11
Joined: Tue Feb 26, 2019 9:04 am

Adding a endpoint automatically

Post by tomwolf » Thu May 09, 2019 1:08 pm

Hello everyone,

I've been testing on Android Studio emulators and my company would like to automate starting up an emulator by starting my Ranorex test. I've been able to create a bat file that startups my Android emulator, but now I ran into a problem with Ranorex. The problem is that Ranorex supports connecting endpoints manually and I've seen some sample codes about automatic connecting WebDriver endpoints, but I need to be able to refresh or reconnect Android and Apple endpoints automatically.

A week ago I've asked this ^ question and I got the right answer. The only problem is that after a little while Ranorex loses connection to the endpoint and the test fails. After searching the internet I found out that it isn't possible to reconnect endpoints that are manually added using the Ranorex UI (correct me if I'm wrong). So the only question that's left is how am I able to add and delete endpoints by User Code?

So might there be any User Code or option to automatically add and delete Android endpoints?

Detailed description of my system:
Windows 10 Enterprise
Ranorex 8.3.3
Service App 2.0.3 on Android

If there is anymore information needed, I would like to hear!
Regards,

Tom Wolf

McTurtle
Posts: 254
Joined: Thu Feb 23, 2017 10:37 am
Location: Benedikt, Slovenia

Re: Adding a endpoint automatically

Post by McTurtle » Wed May 15, 2019 10:23 am

Hi tomwolf,

I'm not actually using this. I only tried and it does get a device connection during runtime without actually adding an endpoint manually before:
string GetFirstConnectedDeviceNames()
		{
			string [email protected]"C:\Program Files (x86)\Ranorex\Studio\Bin\RxEnv\Android\Tools\adb.exe";
			System.Diagnostics.Process adb = new System.Diagnostics.Process();
			
			adb.StartInfo.FileName= rxInstallationPath;
			adb.StartInfo.UseShellExecute = false;
			adb.StartInfo.RedirectStandardOutput=true;
			adb.StartInfo.Arguments = "devices";
			adb.Start();
			string devices_output=adb.StandardOutput.ReadToEnd();
			int startIndex=devices_output.IndexOf("\n")+1;
			int endIndex=devices_output.LastIndexOf("\t");
			string device_first=devices_output.Substring(startIndex,endIndex-startIndex);
			return device_first;
		}
		
		public void AddEndpoint()
		{
			var device=Ranorex.Core.Remoting.RemoteServiceLocator.Service.AddDevice("myPhone",
			                                                                        Ranorex.Core.Remoting.RemotePlatform.Android,
			                                                                        RemoteConnectionType.USB,
			                                                                        GetFirstConnectedDeviceNames()
			                                                                       );
			device.Reconnect();
			var info=device.Status;
		}
Methods can be found by"using Ranorex.Core.Remoting;".
iOS I did not try at all. You would somehow need to get the USB address for the iOS device... Does this help?

Regards,
McTurtle