Adding a endpoint automatically

Mobile Testing, Android App Testing.
tomwolf
Posts: 18
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: 297
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 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

tomwolf
Posts: 18
Joined: Tue Feb 26, 2019 9:04 am

Re: Adding a endpoint automatically

Post by tomwolf » Mon Jul 01, 2019 2:33 pm

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).
Last edited by tomwolf on Mon Aug 05, 2019 3:31 pm, edited 1 time in total.
Regards,

Tom Wolf

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Adding a endpoint automatically

Post by Support Team » Mon Jul 01, 2019 8:55 pm

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