How to check if appium server is running

How to check if appium server is running on appium application using java code on windows and mac both?

1 Like

you have port number which uses appium so use it to check is something listening this port or not.

e.g. with default appium port (Mac):

lsof -n -i:4723 | grep LISTEN

2 Likes

Can u pls provide java code to execute the above command which i can use in my script?

For someone else who end up on this page looking for this answer. You would need to make a get request to this url http://127.0.0.1:4723/wd/hub/status. Use any http client that you want to use. One example using curl is shown below.

To test this, open two terminals (say in powershell or linux). Use one to start/stop appium server and another to test the state of the connection.

Test1:
Terminal one: appium is not started. So write nothing yet on this terminal.
In Terminal two: Do below. It should give a connection refused error as shown below.
PS D:\Appium-cross-platform-example> curl http://127.0.0.1:4723/wd/hub/status curl: (7) Failed to connect to 127.0.0.1 port 4723: **Connection refused**

Test2:
Here I started appium server by writing on first terminal ‘appium’. Which started server with below logs.
Pramod Yadav@DESKTOP-GPU5LFR MINGW64 / $ appium (node:19756) [DEP0128] DeprecationWarning: Invalid 'main' field in 'C:\Users\Pramod Yadav\AppData\Roaming\npm\node_modules\appium\node_modules\mjpeg-server\package.json' of './lib/mpegserver'. Please either fix that or report it to the module author (Usenode --trace-deprecation …to show where the warning was created) [Appium] Welcome to Appium v1.21.0 [Appium] Appium REST http interface listener started on 0.0.0.0:4723

Now in terminal two: Run the same command again and check logs.
PS D:\Appium-cross-platform-example> curl http://127.0.0.1:4723/wd/hub/status **{"value":{"build":{"version":"1.21.0"}},"sessionId":null,"status":0}**

You can now parse this result in language of your choice and decide what you want to do with this information. Cheers!

1 Like