Page 1 of 1

Adding a endpoint automatically

Posted: Thu May 09, 2019 1:08 pm
by tomwolf
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!

Re: Adding a endpoint automatically

Posted: Wed May 15, 2019 10:23 am
by McTurtle
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 rxInstallationPath=@"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

Re: Adding a endpoint automatically

Posted: Mon Jul 01, 2019 2:33 pm
by tomwolf
Hi everyone,

What I said was incorrect: 'The only problem is that after a little while Ranorex loses connection to the endpoint and the test fails.' These connection loses where due to wrong RanoreXPaths and didn't have to do anything with adding the Endpoints using the UI or via UserCode. I also didn't implement the code and just used the Endpoints that I've added before with a Reconnect action (made in UserCode: https://www.ranorex.com/forum/automatic ... 13867.html).

Re: Adding a endpoint automatically

Posted: Mon Jul 01, 2019 8:55 pm
by Support Team
Hello tomwolf,

I am confused by your last response, do you still need assistance on the matter? I can confirm the code provided by McTurtle does work.

Regards,
Sean