Search code examples
appium

How to start Appium server programatically in mac using ruby ?


Is there a way I can get appium to startup within the code? I am trying to automate an iOS application, Since appium only needs to run when my test is running it doesnt make sense to me to keep the appium server always going.

Right now I am using Appium GUI to start server.Is it possible to add something in Before method to start the appium server before connecting the WebDriver to it, and then terminating it in the After method.

Please help me to do it in Mac using Ruby.

Appium server version: 1.8.0 Mac OS: 10.13 node: 6.11 Ruby: 2.5.1

Thanks in advance,


Solution

  • Here is solution for BDD framework written Ruby. Paste these two hooks in hooks.rb file

    Starting the server:

    AfterConfiguration do |config|
    pid = spawn ‘appium --address 0.0.0.0 --port 4723’
    Process.detach(pid)
    sleep(10)
    end
    

    AfterConfiguration hook that will be run after Cucumber has been configured. This hook will run only once,after support has been loaded but before features are loaded. so it is usefull to launch Appium server.

    Stoping the server:

    at_exit do
    exec ‘/usr/bin/killall -KILL node’
    end
    

    at_exit will be executed after execution of all the feature files. So executing exec '/usr/bin/killall -KILL node' command inside this hook kills the server at the end