# \[SOLVED !\] How can I start appium server programatically in parallel?

**URL:** <https://discuss.appium.io/t/solved-how-can-i-start-appium-server-programatically-in-parallel/25096>\
**Category:** Support\
**Created:** [February 3, 2019, 1:39pm UTC](https://discuss.appium.io/t/solved-how-can-i-start-appium-server-programatically-in-parallel/25096 "2019-02-03T13:39:47Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abush](https://discuss.appium.io/user_avatar/discuss.appium.io/abush/32/9636_2.png) [@Abush](https://discuss.appium.io/u/Abush)\
**Post date:** [February 3, 2019, 1:39pm UTC](https://discuss.appium.io/t/solved-how-can-i-start-appium-server-programatically-in-parallel/25096/1 "2019-02-03T13:39:47Z")

</div>

I am running latest appium (installed globally with npm) I want to start and stop appium in parallel,  
But it’s looks hard to implement, since capabilities are strings and port is int, maybe someone can help?

I am using java code and using AppiumServiceBuilder,

Thanks!

---

<div class="post-metadata">

**Author:** ![Zuzeac](https://discuss.appium.io/letter_avatar_proxy/v4/letter/z/b5a626/32.png) [@Zuzeac](https://discuss.appium.io/u/Zuzeac)\
**Post date:** [February 4, 2019, 8:16am UTC](https://discuss.appium.io/t/solved-how-can-i-start-appium-server-programatically-in-parallel/25096/2 "2019-02-04T08:16:54Z")

</div>

It’s pretty hard to explain, I spend a lot of time to make it work.  
To start appium i’m using this method where I pass the port from the testng.xml.  
You also need to specify a different system port for each instance.  
You should find some threads here, explaining everything.

```
capabilities.setCapability(AndroidMobileCapabilityType.SYSTEM_PORT, systemPort);

public void startServer(int appiumPort) {
	final AppiumServiceBuilder builder;
	builder = new AppiumServiceBuilder();
	builder.usingPort(appiumPort);
	builder.withCapabilities(capabilities);
	builder.withArgument(GeneralServerFlag.SESSION_OVERRIDE);
	builder.withArgument(GeneralServerFlag.LOG_LEVEL, "error");
	service = AppiumDriverLocalService.buildService(builder);
	service.start();
	this.appiumServiceUrl = service.getUrl().toString();
	logger.info("Appium Service started at " + this.appiumServiceUrl);
}
```

---

<div class="post-metadata">

**Author:** ![Abush](https://discuss.appium.io/user_avatar/discuss.appium.io/abush/32/9636_2.png) [@Abush](https://discuss.appium.io/u/Abush)\
**Post date:** [February 4, 2019, 8:29am UTC](https://discuss.appium.io/t/solved-how-can-i-start-appium-server-programatically-in-parallel/25096/3 "2019-02-04T08:29:13Z")

</div>

Thanks for the answer, so I need to define “port” for each instance in test.ng xml and also system port?  
Can you explain about sytem port?

Thanks

---

<div class="post-metadata">

**Author:** ![Zuzeac](https://discuss.appium.io/letter_avatar_proxy/v4/letter/z/b5a626/32.png) [@Zuzeac](https://discuss.appium.io/u/Zuzeac)\
**Post date:** [February 4, 2019, 12:50pm UTC](https://discuss.appium.io/t/solved-how-can-i-start-appium-server-programatically-in-parallel/25096/4 "2019-02-04T12:50:13Z")

</div>

check this

> [@How to run multiple simulators on a Mac machine and running parallel tests at the same time](https://discuss.appium.io/t/how-to-run-multiple-simulators-on-a-mac-machine-and-running-parallel-tests-at-the-same-time/21082/2):
>
> Please refer this

---

<div class="post-metadata">

**Author:** ![Abush](https://discuss.appium.io/user_avatar/discuss.appium.io/abush/32/9636_2.png) [@Abush](https://discuss.appium.io/u/Abush)\
**Post date:** [February 4, 2019, 1:30pm UTC](https://discuss.appium.io/t/solved-how-can-i-start-appium-server-programatically-in-parallel/25096/5 "2019-02-04T13:30:16Z")

</div>

Hi, thanks for your response, it’s to complicated, I have windows, maven, not a mac, And this is too. Hard to. Implement…

---

<div class="post-metadata">

**Author:** ![Abush](https://discuss.appium.io/user_avatar/discuss.appium.io/abush/32/9636_2.png) [@Abush](https://discuss.appium.io/u/Abush)\
**Post date:** [February 4, 2019, 4:33pm UTC](https://discuss.appium.io/t/solved-how-can-i-start-appium-server-programatically-in-parallel/25096/6 "2019-02-04T16:33:03Z")

</div>

I tried everything, it doesnt work,  
Someone has a sample code for activate appium server programatically in parallel?

---

<div class="post-metadata">

**Author:** ![Zuzeac](https://discuss.appium.io/letter_avatar_proxy/v4/letter/z/b5a626/32.png) [@Zuzeac](https://discuss.appium.io/u/Zuzeac)\
**Post date:** [February 5, 2019, 10:11am UTC](https://discuss.appium.io/t/solved-how-can-i-start-appium-server-programatically-in-parallel/25096/7 "2019-02-05T10:11:48Z")

</div>

Check this out, there is a list with tutorials and sample frameworks

> **[SrinivasanTarget/awesome-appium](https://github.com/SrinivasanTarget/awesome-appium#test-frameworks)**
>
> A curated list of delightful Appium resources. Contribute to SrinivasanTarget/awesome-appium development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![Abush](https://discuss.appium.io/user_avatar/discuss.appium.io/abush/32/9636_2.png) [@Abush](https://discuss.appium.io/u/Abush)\
**Post date:** [February 5, 2019, 3:30pm UTC](https://discuss.appium.io/t/solved-how-can-i-start-appium-server-programatically-in-parallel/25096/8 "2019-02-05T15:30:43Z")

</div>

Doesn’t work, already try it,

I need to Activate the appium server from java code for a few devices and that’s seems to be an issue…

That’s so hard?  
I hoped that by using udid it can help… Port is int and annotations are Stringa, seems that I’m stuck…

Any help will be appriciate

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [February 5, 2019, 7:35pm UTC](https://discuss.appium.io/t/solved-how-can-i-start-appium-server-programatically-in-parallel/25096/9 "2019-02-05T19:35:21Z")

</div>

@Abush why not to start Appium in Java as in command line using any executer (tons in Java). If you can start appium with command: “appium” in console/terminal, it should not be a problem.

---

<div class="post-metadata">

**Author:** ![Abush](https://discuss.appium.io/user_avatar/discuss.appium.io/abush/32/9636_2.png) [@Abush](https://discuss.appium.io/u/Abush)\
**Post date:** [February 5, 2019, 9:55pm UTC](https://discuss.appium.io/t/solved-how-can-i-start-appium-server-programatically-in-parallel/25096/10 "2019-02-05T21:55:11Z")

</div>

Hi @Aleksei,

I need also to monitor that the appium service is up/down and to do add extra flags like - - relaxed security and so on, Is it possible? To start appium server in parallel from cmd and also to monitor each server o  
If he’s running or not?

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [February 6, 2019, 9:24am UTC](https://discuss.appium.io/t/solved-how-can-i-start-appium-server-programatically-in-parallel/25096/11 "2019-02-06T09:24:55Z")

</div>

why you need to monitor? just start X appium servers with ERROR! logs (works better), some UNIQUE port each and any other flags you need before tests. And close servers after.

---

<div class="post-metadata">

**Author:** ![Abush](https://discuss.appium.io/user_avatar/discuss.appium.io/abush/32/9636_2.png) [@Abush](https://discuss.appium.io/u/Abush)\
**Post date:** [February 6, 2019, 10:22am UTC](https://discuss.appium.io/t/solved-how-can-i-start-appium-server-programatically-in-parallel/25096/12 "2019-02-06T10:22:08Z")

</div>

Thanks, I will try and update.

---

<div class="post-metadata">

**Author:** ![Abush](https://discuss.appium.io/user_avatar/discuss.appium.io/abush/32/9636_2.png) [@Abush](https://discuss.appium.io/u/Abush)\
**Post date:** [February 6, 2019, 7:10pm UTC](https://discuss.appium.io/t/solved-how-can-i-start-appium-server-programatically-in-parallel/25096/13 "2019-02-06T19:10:26Z")

</div>

Still no luck… I have tried so many methods

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [February 6, 2019, 7:23pm UTC](https://discuss.appium.io/t/solved-how-can-i-start-appium-server-programatically-in-parallel/25096/14 "2019-02-06T19:23:43Z")

</div>

we do not know anything about your “no luck”. we need more info to help you. how you tried? why it does not help you?

---

<div class="post-metadata">

**Author:** ![Abush](https://discuss.appium.io/user_avatar/discuss.appium.io/abush/32/9636_2.png) [@Abush](https://discuss.appium.io/u/Abush)\
**Post date:** [February 10, 2019, 11:03am UTC](https://discuss.appium.io/t/solved-how-can-i-start-appium-server-programatically-in-parallel/25096/15 "2019-02-10T11:03:25Z")

</div>

After a lot of trying I succeed to activate appium (JAVA) pragmatically in parallel,  
This is my code that works now:

public DesiredCapabilities cap = new DesiredCapabilities();  
static String Appium\_Node\_Path = “C:\Program Files\nodejs\node.exe”;//That is my patch, change it to your path  
static String Appium\_JS\_Path = “C:\node\_modules\appium\build\lib\main.js”; //That is my patch, change it to your path

cap.setCapability(“deviceName”, deviceName);  
cap.setCapability(“udid”, udid);  
cap.setCapability(“url”, url);

```
    cap.setCapability("appPackage", "your package");
    cap.setCapability("appActivity", "your activity");
    cap.setCapability(MobileCapabilityType.NO_RESET, true);

  AppiumDriverLocalService service;
   service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder().
            usingPort(4723).usingDriverExecutable(new File(Appium_Node_Path)).
            withAppiumJS(new File(Appium_JS_Path))
            .withArgument(GeneralServerFlag.RELAXED_SECURITY)
            .withArgument(GeneralServerFlag.SESSION_OVERRIDE)
            .withArgument(GeneralServerFlag.LOG_LEVEL, "error")
            .withCapabilities(cap));
    service.start();
    Log.info("Appium started ......");
    Thread.sleep(10000);
    driver = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), cap); 

```

And make another one just like that with 1 change: URL: with diff port,  
also using testng.xml for each device,

Works great !

---

<div class="post-metadata">

**Author:** ![Abush](https://discuss.appium.io/user_avatar/discuss.appium.io/abush/32/9636_2.png) [@Abush](https://discuss.appium.io/u/Abush)\
**Post date:** [February 11, 2019, 1:59pm UTC](https://discuss.appium.io/t/solved-how-can-i-start-appium-server-programatically-in-parallel/25096/16 "2019-02-11T13:59:31Z")

</div>

I am working now on framework that connecting the devices in the network automatically, kill the appium server automatically, start the appium server automatically with no limit of devices, ios + android,  
Also found a simple way to kill the appium server port before starting the server.

I am using minimum code(java) and progress is very good, if someone wants to join then please reply,

Thanks.

---

<div class="post-metadata">

**Author:** ![VInoth\_kumar](https://discuss.appium.io/letter_avatar_proxy/v4/letter/v/8797f3/32.png) [@VInoth\_kumar](https://discuss.appium.io/u/VInoth_kumar)\
**Post date:** [December 12, 2019, 12:01pm UTC](https://discuss.appium.io/t/solved-how-can-i-start-appium-server-programatically-in-parallel/25096/17 "2019-12-12T12:01:47Z")

</div>

Where need to change the URL and port here for each device? did you mean here -\> new URL("[http://0.0.0.0:4723/wd/hub](http://0.0.0.0:4723/wd/hub) ? or Using port?
