Reputation: 311
Appium server sometimes it does not stop when you try to close it, server and port is still hanging forever and the Appium CLI has no build-in command to stop the server which makes it harder to manage programmatically
Imagine that you want to manage it programmatically with the automation process in your CI/CD pipeline such as Jenkins it could be a really painful story
appium
or
appium & (as background process)
The command to start Appium server that can be stopped only when you terminate it but sometimes it not stop
Upvotes: 0
Views: 2342
Reputation: 311
I've searched for the answer on StackOverflow for a long time and none of them answer directly to my question
So far what seems to work is that you have to kill the process of the server manually in the shell with the specific process id
To make it simply work with the pipeline, we could have a short version of the command
kill $(lsof -t -i :4723)
kill \$(lsof -t -i :${APPIUM_PORT}) [In Jenkinsfile]
Where the APPIUM_PORT is your Appium port, the default port is 4723
lsof command should work in Unix-like systems e.g. MacOS, Linux
lsof is a command meaning "list open files", which is used in many Unix-like systems to report a list of all open files and the processes that opened them
By running this command it should return an ID of the process running on that specific port to use for the kill signal
To implement in the pipeline Add this step at the end of your Jenkinsfile
post{
always{
...
echo "Stop appium server"
sh "kill \$(lsof -t -i :${APPIUM_PORT})"
}
success{
...
}
failure{
...
}
cleanup{
...
}
}
It should kill the hanging Appium server process and you can start the new Appium server again with the same port!
To see more details on this I already publish a blog here
How to start/stop Appium server in Jenkins Pipeline
Hope it helps
Upvotes: 2