How to quit Appium server(launching through command prompt) listening on particular port number?

Hi everyone,

If there are two Appium servers have been already launched with two port numbers (say e.g. 4723 and 5723). I just want to quit only one server listening on 4723. Is there a way (Appium related command line argument) to quit only one server.

Note : I’ve tried with killing process of node.exe, this is going to close all the servers but not only particular node.

Thanks & Regards,
Vijay Bhaskar.

1 Like

have you tried driver.quit()

Hi @Venkatesh,

Thanks for your valuable suggestion. My bad, here I missed that, we are going with parallel test runs. If I’m trying quit driver instance, that will automatically closes the second Appium server driver instance too.

Could you please suggest if there is a way (Appium related command line argument) to quit only one server.

Thanks,
Vijay Bhaskar.

@bhaskar, you need to launch appium services using separate threads for parallel execution. even if you perform driver.quit() it will quit only relevant instance it does not affect other driver instance. you can refer https://github.com/saikrishna321/AppiumTestDistribution

Instantiate two drivers on different ports, give sufficient timeout so that server is not killed even if you don’t fire command. you can do that programatically as well, and then kill the driver1/driver2 using driver.quit().

Please share the code if it does not works.

I am probably misunderstanding your problem. Do you want to quit an Appium test session, or do you want to kill the Appium process? Quitting an Appium test session does not involve needing to know which port the Appium process is listening on. If you ask about ports, however, then this means that you want to kill the process listening on a particular port.

Hi @afwang,

Thanks for the reply, I need to kill the process listening on a particular port. Is there a way to kill such process. Please let me know.

Thanks,
Vijay Bhaskar.

mac:

 cmd1 = new String[]{"sh", "-c", "lsof -P | grep ':4725' | awk '{print $2}' | xargs kill -9"};
1 Like

Many Thanks @Aleksei,

May I know, Is same available for windows too. Please let me know.

Thanks,
Vijay Bhaskar.

1 Like

There might be a cleaner way to kill the Appium process than relying on a shell script. If you are launching your Appium servers through your test framework (that is, the Appium processes are child processes of your test process), then you can use your particular language’s API to terminate the children. For example, Java has the destroy method as part of the Process class. Although I’m far less familiar with other languages, I believe Python and Ruby have similar methods available for dealing with children.

it is BUT what will you do if by some reason your test did not execute it by some reason and next test relying that appium server is killed?

otherwise indeed you may stop appium server in pure code as process.

we use Java so can’t help with python.

1 Like

Thanks @afwang,Aleksei and everyone.

Seems like it leads to positive way with your inputs… :smile:

Thanks,
Bhaskar.