Appium appium IOS 在真机上怎么通过指令 执行 python 脚本

luyi0824 · 2013年12月05日 · 最后由 唐僧之妈 回复于 2013年12月10日 · 1794 次阅读

appium IOS 在真机上怎么通过指令 执行 python 脚本

有没有知道具体的步骤

我现在模拟器执行 python 脚本的环境 OK 了

grunt appium 启动服务器

nosetests simple.py 执行脚本

共收到 39 条回复 时间 点赞

没有高手帮我这个菜鸟吗???

#1 楼 @luyi0824 翻翻之前的帖子看下。工作时间大神都在忙,肯定会有人来帮你~

@mingway_hu @luyi0824 不好意思,这个问题没人解答过。估计论坛里没人试验过。

@luyi0824 首先你启动 appium 的时候

  • 指定设备的 UUID
  • 指定 APP 的 Bundle ID

比如
appium -U 45f082689dbaebb0ffa3620b3ae22ad9faff9a30 --app io.appium

然后再去运行脚本。比如源码的案例下面的 examples/python/simple_real_device.py

理论上是这样,不过我遇到了一些问题。 没有成功的运行起来。

#4 楼 @lihuazhang 我也尝试了一下,也碰到了问题,估计是服务器没跟设备连接起来,Bundle ID 是写在测试用例中

#5 楼 @luyi0824 我重启了下 mac 后, 可以了 运行成功。

debug: Appium request initiated at /wd/hub/session
debug: Request received with params: {"sessionId":null,"desiredCapabilities":{"device":"iPhone Simulator","platform":"Mac","browserName":"","version":"6.0","app":"io.appium.TestApp"}}
info: App is an iOS bundle, will attempt to run as pre-existing
info: Creating new appium session bcc46555-24e6-46b0-b725-d1d4b462af08
info: Removing any remaining instruments sockets
info: Cleaned up instruments socket /tmp/instruments_sock
info: Cleaning up any tracedirs
info: No tracedirs to clean up
info: Localizable.strings is not currently supported when using real devices.
info: Not setting device type since we're connected to a device
info: Starting iOS device log capture via idevicesyslog
debug: Real device specified but no ipa, assuming bundle ID is on device
debug: Creating instruments
info: instruments is: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments
info: [INSTSERVER] Instruments socket server started at /tmp/instruments_sock
info: Attempting to run app on real device with UDID 45f082689dbaebb0ffa3620b3ae22ad9faff9a30
info: Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate -w 45f082689dbaebb0ffa3620b3ae22ad9faff9a30 io.appium.TestApp -e UIASCRIPT /usr/local/lib/node_modules/appium/lib/devices/ios/uiauto/bootstrap.js -e UIARESULTSPATH /tmp/appium-instruments/
info: And extra without-delay env: {}
info: And launch timeout: 90000ms
info: [INSTSERVER] Instruments is ready to receive commands
info: Instruments launched. Starting poll loop for new commands.
info: Setting initial orientation to PORTRAIT
info: Pushing command to appium work queue: "au.setScreenOrientation('PORTRAIT')"
debug: Sending command to instruments: au.setScreenOrientation('PORTRAIT')
info: [INSTSERVER] Socket data received (15 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Sending command to instruments: au.setScreenOrientation('PORTRAIT')
info: [INSTSERVER] Socket data received (56 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":"PORTRAIT"}
info: Device launched! Ready for commands (will time out in 60secs)
info: Appium session started with sessionId bcc46555-24e6-46b0-b725-d1d4b462af08
POST /wd/hub/session 303 46032ms - 9b
debug: Appium request initiated at /wd/hub/session/bcc46555-24e6-46b0-b725-d1d4b462af08
debug: Request received with params: {}
info: Responding to client with success: {"status":0,"value":{"version":"6.0","webStorageEnabled":false,"locationContextEnabled":false,"browserName":"","platform":"Mac","javascriptEnabled":true,"databaseEnabled":false,"takesScreenshot":true,"device":"iPhone Simulator","app":"io.appium.TestApp"},"sessionId":"bcc46555-24e6-46b0-b725-d1d4b462af08"}
GET /wd/hub/session/bcc46555-24e6-46b0-b725-d1d4b462af08 200 2ms - 382b
debug: Appium request initiated at /wd/hub/session/bcc46555-24e6-46b0-b725-d1d4b462af08/elements
debug: Request received with params: {"using":"tag name","sessionId":"bcc46555-24e6-46b0-b725-d1d4b462af08","value":"textField"}
info: Pushing command to appium work queue: "au.getElementsByType('textField')"
debug: Sending command to instruments: au.getElementsByType('textField')
info: [INSTSERVER] Sending command to instruments: au.getElementsByType('textField')
info: [INSTSERVER] Socket data received (79 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":[{"ELEMENT":"0"},{"ELEMENT":"1"}]}
info: Responding to client with success: {"status":0,"value":[{"ELEMENT":"0"},{"ELEMENT":"1"}],"sessionId":"bcc46555-24e6-46b0-b725-d1d4b462af08"}
POST /wd/hub/session/bcc46555-24e6-46b0-b725-d1d4b462af08/elements 200 1193ms - 157b
debug: Appium request initiated at /wd/hub/session/bcc46555-24e6-46b0-b725-d1d4b462af08/element/0/value
debug: Request received with params: {"sessionId":"bcc46555-24e6-46b0-b725-d1d4b462af08","id":"0","value":["1"]}
info: Pushing command to appium work queue: "au.getElement('0').setValueByType('1')"
debug: Sending command to instruments: au.getElement('0').setValueByType('1')
info: [INSTSERVER] Sending command to instruments: au.getElement('0').setValueByType('1')
info: [INSTSERVER] Socket data received (48 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":""}
info: Responding to client with success: {"status":0,"value":"","sessionId":"bcc46555-24e6-46b0-b725-d1d4b462af08"}
POST /wd/hub/session/bcc46555-24e6-46b0-b725-d1d4b462af08/element/0/value 200 2348ms - 87b
debug: Appium request initiated at /wd/hub/session/bcc46555-24e6-46b0-b725-d1d4b462af08/element/1/value
debug: Request received with params: {"sessionId":"bcc46555-24e6-46b0-b725-d1d4b462af08","id":"1","value":["5"]}
info: Pushing command to appium work queue: "au.getElement('1').setValueByType('5')"
debug: Sending command to instruments: au.getElement('1').setValueByType('5')
info: [INSTSERVER] Sending command to instruments: au.getElement('1').setValueByType('5')
info: [INSTSERVER] Socket data received (48 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":""}
info: Responding to client with success: {"status":0,"value":"","sessionId":"bcc46555-24e6-46b0-b725-d1d4b462af08"}
POST /wd/hub/session/bcc46555-24e6-46b0-b725-d1d4b462af08/element/1/value 200 1820ms - 87b
debug: Appium request initiated at /wd/hub/session/bcc46555-24e6-46b0-b725-d1d4b462af08/elements
debug: Request received with params: {"using":"tag name","sessionId":"bcc46555-24e6-46b0-b725-d1d4b462af08","value":"button"}
info: Pushing command to appium work queue: "au.getElementsByType('button')"
debug: Sending command to instruments: au.getElementsByType('button')
info: [INSTSERVER] Sending command to instruments: au.getElementsByType('button')
info: [INSTSERVER] Socket data received (143 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":[{"ELEMENT":"2"},{"ELEMENT":"3"},{"ELEMENT":"4"},{"ELEMENT":"5"},{"ELEMENT":"6"},{"ELEMENT":"7"}]}
info: Responding to client with success: {"status":0,"value":[{"ELEMENT":"2"},{"ELEMENT":"3"},{"ELEMENT":"4"},{"ELEMENT":"5"},{"ELEMENT":"6"},{"ELEMENT":"7"}],"sessionId":"bcc46555-24e6-46b0-b725-d1d4b462af08"}
POST /wd/hub/session/bcc46555-24e6-46b0-b725-d1d4b462af08/elements 200 1326ms - 293b
debug: Appium request initiated at /wd/hub/session/bcc46555-24e6-46b0-b725-d1d4b462af08/element/2/click
debug: Request received with params: {"sessionId":"bcc46555-24e6-46b0-b725-d1d4b462af08","id":"2"}
info: Pushing command to appium work queue: "au.tapById('2')"
debug: Sending command to instruments: au.tapById('2')
info: [INSTSERVER] Sending command to instruments: au.tapById('2')
info: [INSTSERVER] Socket data received (50 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":null}
info: Responding to client with success: {"status":0,"value":null,"sessionId":"bcc46555-24e6-46b0-b725-d1d4b462af08"}
POST /wd/hub/session/bcc46555-24e6-46b0-b725-d1d4b462af08/element/2/click 200 1174ms - 89b
debug: Appium request initiated at /wd/hub/session/bcc46555-24e6-46b0-b725-d1d4b462af08/elements
debug: Request received with params: {"using":"tag name","sessionId":"bcc46555-24e6-46b0-b725-d1d4b462af08","value":"staticText"}
info: Pushing command to appium work queue: "au.getElementsByType('staticText')"
debug: Sending command to instruments: au.getElementsByType('staticText')
info: [INSTSERVER] Sending command to instruments: au.getElementsByType('staticText')
info: [INSTSERVER] Socket data received (96 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":[{"ELEMENT":"8"},{"ELEMENT":"9"},{"ELEMENT":"10"}]}
info: Responding to client with success: {"status":0,"value":[{"ELEMENT":"8"},{"ELEMENT":"9"},{"ELEMENT":"10"}],"sessionId":"bcc46555-24e6-46b0-b725-d1d4b462af08"}
POST /wd/hub/session/bcc46555-24e6-46b0-b725-d1d4b462af08/elements 200 1347ms - 192b
debug: Appium request initiated at /wd/hub/session/bcc46555-24e6-46b0-b725-d1d4b462af08/element/8/text
debug: Request received with params: {"sessionId":"bcc46555-24e6-46b0-b725-d1d4b462af08","id":"8"}
info: Pushing command to appium work queue: "au.getElement('8').text()"
debug: Sending command to instruments: au.getElement('8').text()
info: [INSTSERVER] Sending command to instruments: au.getElement('8').text()
info: [INSTSERVER] Socket data received (49 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":"6"}
info: Responding to client with success: {"status":0,"value":"6","sessionId":"bcc46555-24e6-46b0-b725-d1d4b462af08"}
GET /wd/hub/session/bcc46555-24e6-46b0-b725-d1d4b462af08/element/8/text 200 939ms - 88b
debug: Appium request initiated at /wd/hub/session/bcc46555-24e6-46b0-b725-d1d4b462af08
debug: Request received with params: {"sessionId":"bcc46555-24e6-46b0-b725-d1d4b462af08"}
info: Shutting down appium session...
info: Stopping ios
info: [INST] 2013-12-06 10:50:50 +0000 Debug: target.setDeviceOrientation("1")
       2013-12-06 10:50:53 +0000 Debug: target.frontMostApp().elements()[0].elements()[0].tap()
2013-12-06 10:50:54 +0000 Debug: target.frontMostApp().keyboard().typeString("1")
2013-12-06 10:50:55 +0000 Debug: target.frontMostApp().elements()[0].elements()[1].tap()
2013-12-06 10:50:56 +0000 Debug: target.frontMostApp().keyboard().typeString("5")
2013-12-06 10:50:58 +0000 Debug: target.frontMostApp().elements()[0].elements()[2].tap()
2013-12-06 10:51:00 +0000 Stopped: Script was stopped by the user
Instruments Trace Complete (Duration : 52.047413s; Output : /Users/Apple/instrumentscli0.trace)

info: [INSTSERVER] Instruments exited with code 0
info: Stopping iOS log capture
info: [INSTSERVER] Socket closed forcibly due to exit
info: [INSTSERVER] Instruments socket server closed
info: Deleted tracedir we heard about from instruments (/Users/Apple/instrumentscli0.trace)
info: Cleaning up appium session
info: Responding to client with success: {"status":0,"value":null,"sessionId":"bcc46555-24e6-46b0-b725-d1d4b462af08"}
DELETE /wd/hub/session/bcc46555-24e6-46b0-b725-d1d4b462af08 200 583ms - 89b
➜  python git:(master) ✗ python simple_real_device.py
.
----------------------------------------------------------------------
Ran 1 test in 56.793s

OK
➜  python git:(master)

#6 楼 @lihuazhang 我现在 mac 在家里回去试试看不过貌似你已经成功了是吧~~

#7 楼 @lihuazhang 我按照你说的方法试了一下
在 appium 目录下执行 appium -U b5a93d4e5d0f4714d2ed29f3497752d92fd11a9b --app io.appium.TestApp
结果

在 examples/python 目录下 执行 python simple_real_device.py
结果

找不到程序

你是哪些步骤,说说哈

脚本里面需要改吗?

@luyi0824 你没按我的步骤啊。。。 bundle id 不对

#10 楼 @lihuazhang 我 bundle id 也换成了 --app io.appium 还是出现一样的问题

#10 楼 @lihuazhang

我这边还是还是不行

一直报 bundle id 的错误

#8 楼 @monkey 大神,求帮忙看看问题哈

#13 楼 @luyi0824 你的各个 version 号都是多少?我最近太忙。。。有空的时候来看了。。等待其他大神的解救。。。

@luyi0824 你在模拟器上能运行么? xcode 必须 5.0.2 或者以上

#15 楼 @lihuazhang w 模拟器上能正常运行,xcode 更新到 5.0.2 也还是一样找不到 bundle id


appium 版本 12.02

python 2.7

紧急呼救!!!

#14 楼 @monkey
xcode 5.0.2
appium 版本 12.02

python 2.7

#15 楼 @lihuazhang 大神,能加我 QQ:471701839 上指导我吗?谢谢!!!

#18 楼 @luyi0824 一直在医院诶。。。

#19 楼 @lihuazhang
这。。。生病了啊!!!
能再帮我想想会是哪里出问题了?
或者你从第一步开始,运行,截图我看看
你在真机上运行,工程中的程序需要自己先编译或者进行其他操作吗?或者有哪些步骤需要做的,我没做。
比如之前模拟器上运行脚本,需要把程序把模拟器编译进去之类的步骤

我也是一样的环境,也报同样的错误

#19 楼 @lihuazhang 求帮忙。。。。。看来是缺少什么步骤了,也有人碰到一样的问题了

#21 楼 @xiaomayi0323 你找到原因了没?

@luyi0824 @xiaomayi0323 你们的应用本身在真机上能运行嘛?

#24 楼 @lihuazhang appium 项目中带的程序不能在真机上运行

#24 楼 @lihuazhang 要先把程序烧到真机上吗?

#26 楼 @luyi0824 必须要能在真机上运行啊。。。 苹果条例,要想跑真机,必须买证书

#27 楼 @lihuazhang 我自己的程序有证书呢,也能在真机上运行

#28 楼 @luyi0824 那你用自己的 bundle id

#23 楼 @luyi0824 还没有找到原因

#24 楼 @lihuazhang 应用本身可以在真机上运行

Appium Log

Kingsons-MacBook:Study kingson$ appium -U 1a601f5cd791bc379115095fc81cd69b096582a3 --app com.telenavsoftware.doudouy
info: Welcome to Appium v0.11.4 (REV b04decd191002628c88e9bf475553da1cd04a036)
info: Appium REST http interface listener started on 0.0.0.0:4723
   info  - socket.io started
debug: Appium request initiated at /wd/hub/session
debug: Request received with params: {"sessionId":null,"desiredCapabilities":{"device":"iPhone Simulator","platform":"Mac","browserName":"iOS","version":"7.0","app":"com.telenavsoftware.doudouy"}}
info: App is an iOS bundle, will attempt to run as pre-existing
info: Creating new appium session a36fdf63-9b22-48a4-bb01-4b44ddb54aff
info: Removing any remaining instruments sockets
info: Cleaned up instruments socket /tmp/instruments_sock
info: Cleaning up any tracedirs
info: No tracedirs to clean up
info: Localizable.strings is not currently supported when using real devices.
info: Not setting device type since we're connected to a device
info: Starting iOS device log capture via idevicesyslog
debug: Real device specified but no ipa, assuming bundle ID is on device
debug: Creating instruments
info: instruments is: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments
info: [INSTSERVER] Instruments socket server started at /tmp/instruments_sock
info: Attempting to run app on real device with UDID 1a601f5cd791bc379115095fc81cd69b096582a3
info: Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate -w 1a601f5cd791bc379115095fc81cd69b096582a3 com.telenavsoftware.doudouy -e UIASCRIPT /usr/local/lib/node_modules/appium/lib/devices/ios/uiauto/bootstrap.js -e UIARESULTSPATH /tmp/appium-instruments/
info: And extra without-delay env: {}
info: And launch timeout: 90000ms
info: [INST STDERR] 2013-12-10 10:40:22.536 instruments[53424:507] Connection to the remote device lost while launching target. Aborting...

info: [INST STDERR] 2013-12-10 10:40:22.539 instruments[53424:507] Recording cancelled : At least one target failed to launch; aborting run

info: [INST STDERR] Instruments Trace Error : Error Domain=com.apple.instruments Code=1 "Error Starting Recording" UserInfo=0x7ff6d308f220 {NSLocalizedDescription=Error Starting Recording, NSLocalizedRecoverySuggestion=At least one target failed to launch; aborting run}
Instruments Trace Error : Failed to start trace.

info: [INSTSERVER] Instruments exited with code 253
error: Instruments did not launch successfully, failing session
info: Cleaning up appium session
error: Failed to start an Appium session, err was: Error: Instruments did not launch successfully--please check your app paths or bundle IDs and try again
info: Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Instruments did not launch successfully--please check your app paths or bundle IDs and try again)","origValue":"Instruments did not launch successfully--please check your app paths or bundle IDs and try again"},"sessionId":null}
POST /wd/hub/session 500 6015ms - 342b```

我的部分代码片段:

```python
class TestSequenceFunctions(unittest.TestCase):

    def setUp(self):
        # set up appium
        app = "com.telenavsoftware.doudouy"
        #app = os.path.join(os.path.dirname(__file__),
        #                   '../../apps/DDY/build/',
        #                   'DouDouY.app')
        #app = os.path.abspath(app)
        self.driver = webdriver.Remote(
            command_executor='http://127.0.0.1:4723/wd/hub',
            desired_capabilities={
                'browserName': 'iOS',
                'device': 'iPhone Simulator',
                'platform': 'Mac',
                'version': '7.0',
                'app': app
            })```

#1 楼 @luyi0824 终于运行起来了,你可以确保下面几点无误后再试试:
1.启动 Appium 时,保证你的 Real Device 的 UDID 和你的应用的 Bundle ID 正确
2.确保你的应用可以安装到你的真机上
3.安装后请断开与 Xcode 的连接
4.确保 Mac 上没有启动 Instruments 工具

如果还不行,你可以自己启动 Instruments 工具来试试

#29 楼 @lihuazhang 可以运行了!哈哈,谢谢哈

#33 楼 @xiaomayi0323 我也在早上运行成功了,最主要是先把应用程序烧到真机上

#36 楼 @luyi0824 哦,不错,换个头像吧

#37 楼 @xiaomayi0323 appreciate ~ @luyi0824 是不是要先放上去吧? 其实你看代码 就知道没有把 app 烧到真机上的代码。

我这边遇到的问题比较有意思

运行 appium.app 检测环境,全部 OK,如下:

Running iOS Checks

✔ Xcode is installed at /Applications/Xcode.app/Contents/Developer

✔ Xcode Command Line Tools are installed.

✔ DevToolsSecurity is enabled.

✔ The Authorization DB is set up properly.

✔ Node binary found at /usr/local/bin/node
✔ iOS Checks were successful.

命令行启动,或者 appium.app 启动,都出现下面的 info。

appium -U 149afc56ab0434769fd666ca8ac324790a27f5eb --app io.TestApp
info: Welcome to Appium v0.16.0 (REV 292d265edd9c7aaf96f165009285c814b218363d)
info: Appium REST http interface listener started on 0.0.0.0:4723
info - socket.io started
info: Spawning instruments force-quitting watcher process
info: [FQInstruments STDERR] Force quit unresponsive instruments v0.0.1

在 python 这边执行 simple_real_device.py,结果报基础的字符集解码错误。我猜想是服务器端的启动异常引起的。

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册