How to start the Appium server in iOS Machine automatically through Java Code

I need to automate the appium server via Java code in Mac machine.

In windows I have used the following code.

public void startAppiumServer() throws IOException, InterruptedException {

    CommandLine command = new CommandLine("cmd");
    command.addArgument("/c");
    
    command.addArgument("D:\\SOFTWARES\\AppiumForWindows-1.2.4.1\\Appium\\node.exe");  
    command.addArgument("D:\\SOFTWARES\\AppiumForWindows-1.2.4.1\\Appium\\node_modules\\appium\\bin\\appium.js");  
    command.addArgument("--address", false);  
    command.addArgument("127.0.0.1");  
    command.addArgument("--port", false);  
    command.addArgument("4723");    
    command.addArgument("--full-reset", false);  

    DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();  
    DefaultExecutor executor = new DefaultExecutor();  
    executor.setExitValue(1);
    executor.execute(command, resultHandler);
}

public static void startApplication() throws Exception{

	System.out.println("application has started...................");

	System.out.println("Into iOS");
	DesiredCapabilities capabilities = new DesiredCapabilities();

        capabilities.setCapability(CapabilityType.BROWSER_NAME, "");	
	capabilities.setCapability("avd","Test");
	capabilities.setCapability("deviceName","");	
	capabilities.setCapability("platformVersion","4.3");
	capabilities.setCapability("platformName","Android");
	capabilities.setCapability("app","D:/SOFTWARES/Apks/QuickSales.apk");
	
	driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); 
	System.out.println("Appium SetUp for Android is successful and Appium Driver is launched successfully");
}

public static void main(String as[]) throws Exception
{
    
    startApplication();
    try{Thread.sleep(5000);}catch(Exception e){}
    
    System.out.println("Stopping Server");
    stopAppiumServer();
    System.out.println("Server Stopped");

}

How it could be done for MAC machine

@Hassan_Radi Can you give your suggestions please

I’m using two shell scripts to start and stop server after each test.
There must be better way to do that at least I could get things done )

Here is the gist: https://gist.github.com/nishanov/f76c59645021e69c1a71
I’m not a shell script expert so feel free to :smile:

@ashokkumarg @Aki
I developed a Java library as a support library for Appium, you can find details on how to use it to start/stop the server here.

Please tell me if you encounter any issues.

Hope it helps.

I don’t see this post available, can you please resent the post.

https://www.linkedin.com/pulse/appium-support-library-hassan-radi

Looks like there is some problem in the link, the link is getting redirected to “5 Things Great Managers Do Every Day
and it says sorry this post is not available

Yes it is re-directed to the wrong page. :confused:

In Google, search like Appium support library Hasan radi. You will get it

It is working fine from my end… not sure why it is redirecting to another page from your side !!!

@Hassan_Radi I’m getting an error like Browser start up failure or Invalid remote server address
In windows I have used the above code which was in the description:

@0x1mason suggestions please