In this section we
will learn how we can start and stop the appium server through the program for our mobile automation test case.
There are a lot of scenarios
where we wanted to execute our appium mobile test either through some CI tools
like Jenkins or on some cloud machine, in that case, it is very much important that
we are able to start and stop the appium server through code.
For achieving this
task we need to mimic the manual step that we usually perform to start our
appium server. Before moving further I would highly recommend you to read this
blog to know how to set up an appium server through the command line.
As we have already seen that to start appium server through command prompt we follow below steps:
1)
Open command prompt
2)
Execute the below command
and hit enter
appium -a ip address -p portnumber on which appium server need to
be started for e.g appium -a
127.0.0.1 -p 4723.
Similarly to stop
appium server we can kill the node process from task manager.
Below is the code
snippet to start and stop the appium server.
Code to start
appium server can be either placed in @BeforeSuite or @BeforeClass in your
automation framework.
Similarly, code to
stop appium server can be either placed in @AfterSuite or @AfterClass in the automation framework.