参考http://www.cnblogs.com/binghaixuefeng/p/5558804.html 的命令在 Python 中启动 appium
代码如下:
import com
import verification_code
import subprocess
cmd ="start /b appium -a 172.20.6.29 -p 4723 --session-override --command-timeout 600"
p = subprocess.Popen(cmd, shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
time.sleep(5)
print(p)
PATH = lambda p: os.path.abspath(
os.path.join(os.path.dirname(__file__), p)
)
desired_caps = {}
desired_caps['platformName'] ='Android'
desired_caps['platformVersion'] ='4.4.4'
desired_caps['deviceName'] = '01b70616'
desired_caps['appPackage'] ='com.kdweibo.client'
desired_caps['appActivity'] = 'com.kdweibo.android.ui.activity.StartActivity' #主界面Activity
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
driver.implicitly_wait(60)
调用这个模块后报错如下:
C:\Python27\python.exe "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 5.0.1\helpers\pydev\pydevd.py" --multiproc --qt-support --client 127.0.0.1 --port 61805 --file C:/Users/Administrator/PycharmProjects/KDsign_app/test/test.py
pydev debugger: process 91048 is connecting
Connected to pydev debugger (build 143.595)
<subprocess.Popen object at 0x038C6470>
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 5.0.1\helpers\pydev\pydevd.py", line 2403, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 5.0.1\helpers\pydev\pydevd.py", line 1794, in run
launch(file, globals, locals) # execute the script
File "C:/Users/Administrator/PycharmProjects/KDsign_app/test/test.py", line 4, in <module>
from commond import SignOutside,SignInside
File "C:\Users\Administrator\PycharmProjects\KDsign_app\commond\SignOutside.py", line 2, in <module>
from basic import SetUp
File "C:\Users\Administrator\PycharmProjects\KDsign_app\commond\basic.py", line 24, in <module>
class SetUp():
File "C:\Users\Administrator\PycharmProjects\KDsign_app\commond\basic.py", line 31, in SetUp
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
File "build\bdist.win32\egg\appium\webdriver\webdriver.py", line 37, in __init__
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 74, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 123, in start_session
'desiredCapabilities': desired_capabilities,
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 173, in execute
response = self.command_executor.execute(driver_command, params)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 349, in execute
return self._request(command_info[0], url, body=data)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 417, in _request
resp = opener.open(request)
File "C:\Python27\lib\urllib2.py", line 431, in open
response = self._open(req, data)
File "C:\Python27\lib\urllib2.py", line 449, in _open
'_open', req)
File "C:\Python27\lib\urllib2.py", line 409, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 1227, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "C:\Python27\lib\urllib2.py", line 1197, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [Errno 10061] >