3

I want to write a android test framework using Appium and python. Appium link: http://appium.io/

So after installing appium with npm, to start its server I need to execute the command "appium" in terminal.It will start the server. It looks something like this after starting:

    ranits-MacBook-Pro:$ appium
[Appium] Welcome to Appium v1.8.1
[Appium] Appium REST http interface listener started on 0.0.0.0:4723

But I need to start the appium server from my code using python?

Any help?

4
  • 2
    we need more information on what exactly you are trying to do Commented Aug 7, 2018 at 19:51
  • 1
    Please check How do I ask a good question Commented Aug 7, 2018 at 19:52
  • @AlImran I'm aware of the CoC, could you clarify how this relates to my comment? Particularly as the first link in the "Expectations" box is the same page I linked to? Commented Aug 8, 2018 at 9:57
  • edited the question. Commented Aug 17, 2018 at 15:07

3 Answers 3

4

The Python client actually comes with a handy module called AppiumService that you can use to programmatically start/stop an Appium server.

from appium.webdriver.appium_service import AppiumService

appium_service = AppiumService()

To start,

self.appium_service.start()

To stop,

self.appium_service.stop()

That's literally it, and I believe it's a cleaner way to start/stop the Appium server than issuing an OS system command to like in the above solution(s).

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @sohum, how to pass the port number?
Like this: self.appium_service.start(args=['-p 1000']), where -p is a port flag and 1000 is the number of your port.
1

First of all its good to check manually if "appium" command on shell launches the appium server or not(Seems in your case its working fine). In my case it was not with the installation of Appium desktop version. Posting the details of what i did to resolve this in case it helps someone:

  1. Installed npm (as part of node installation, MSI available at nodejs.org)
  2. npm install -g appium

Now to answer your main question, below is what i used in my Python script to start the appium server on a new window so that it runs separately from the rest of the script execution:

import os
os.system("start /B start cmd.exe @cmd /k appium") 

In case you want to change the port(e.g. to 4728) of the appium server (may be when you have multiple servers for multiple devices) you can use following:

os.system("start /B start cmd.exe @cmd /k appium -a 127.0.0.1 -p 4728")

if you want to stop that appium service. Add these two lines on your code:

os.system("taskkill /F /IM node.exe")
os.system("taskkill /F /IM cmd.exe")

Comments

1

To start the appium server Programmatically (Python way) all you have to do is execute the below code

import OS
os.System("appium")

This would start the appium server in the backend .Other way to start the appium server is

import os
os.system(/Path/of/ur/main.js)

Enter these code in a py file and execute .. the server will start

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.