Appium [Share]如何在真机上运行 Inspector(iOS)

唐僧之妈 · August 13, 2014 · Last by 云飞凌风 replied at September 05, 2014 · 1678 hits
本帖已被设为精华帖!

今天想通过 Inspector 来定位元素,结果半天都运行不起来,后来通过一番搜索,终于可以正常运行了,在这里记录并总结一下,分享给需要的朋友们。

一、环境
Appium:1.2.0
XCode:5.1.1

二、前提条件
你的测试代码需要在真机上成功运行过,如何在真机上运行测试代码,请自行检索。

三、步骤
1.启动 Appium(GUI)
2.运行你的测试代码
3.点击 Appium 上的 Inspector 按钮,为了能在测试代码运行结束后继续使用 Inspector,可以将 tearDown 改写为:

def tearDown(self):
        # End the session
        # self.driver.quit()
        pass

这样 session 就不会被注销掉,可以一直刷新或录制了。

共收到 9 条回复 时间 点赞

大赞!!!~~

知道为什么写成 pass 么

请问如何连接苹果手机真机呢?
我的应用程序代码已经在真机上运行过,然后我想通过 appium 来运行应用到真机中?

#3 楼 @wangcityboy 如何连接真机?
三部分,第一,需要将手机和 Mac 连接起来,第二,将被测应用(需要 development 证书)安装到真机上 第三,在 Appium 上配置真机的 UDID 以及被测应用的 BundleID

#4 楼 @xiaomayi0323 在模拟器上,运行 java 类中添加的测试方法能够运行,为什么当连接到真机的时候,运行不了了呢?

#5 楼 @wangcityboy 你这样问,神仙也没办法帮你,需要将你的代码信息和报错信息才能帮你看啊

#6 楼 @xiaomayi0323
报错代码:
info: [debug] App is an iOS bundle, will attempt to run as pre-existing
info: [debug] Creating new appium session 6b59eb9a-213c-43c2-9ce9-94fab6eb71e1
info: [debug] Removing any remaining instruments sockets
info: [debug] Cleaned up instruments socket /tmp/instruments_sock
info: [debug] Setting Xcode folder
info: [debug] Setting Xcode version
info: [debug] Setting iOS SDK Version
info: [debug] iOS SDK Version set to 7.1
info: [debug] Detecting automation tracetemplate
info: [debug] Not auto-detecting udid, running on sim
info: [debug] Localizable.strings is not currently supported when using real devices.
info: [debug] Not setting locale because we're using a real device
info: [debug] Creating instruments
info: [debug] Preparing uiauto bootstrap
info: [debug] Dynamic bootstrap dir:
info: [debug] Dynamic env:
info: [debug] Dynamic bootstrap code:
info: [debug] Dynamic bootstrap path:
info: [debug] Reusing dynamic bootstrap:
info: [debug] Not setting iOS and app preferences since we're on a real device
info: [debug] Starting iOS device log capture via deviceconsole
error: iOS log capture failed: spawn ENOENT
info: [debug] Cleaning up appium session
error: Failed to start an Appium session, err was: Error: spawn ENOENT
info: [debug] Error: spawn ENOENT
at errnoException (child_process.js:1000:11)
at Process.ChildProcess._handle.onexit (child_process.js:791:34)
info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: spawn ENOENT)","code":"ENOENT","errno":"ENOENT","syscall":"spawn","origValue":"spawn ENOENT"},"sessionId":null}
info: <-- POST /wd/hub/session 500 177.110 ms - 197
info: [debug] Not setting device type since we're connected to a device
info: [debug] Creating iDevice object with udid a0ee9c874742cd***ef1b43f148fe72068c58265
info: [debug] Couldn't find ideviceinstaller, trying built-in at /usr/local/lib/node_modules/appium/build/libimobiledevice-macosx/ideviceinstaller
info: [debug] Checking app install status using: /usr/local/lib/node_modules/appium/build/fruitstrap/fruitstrap isInstalled --id a0ee9c874742cd***ef1b43f148fe72068c58265 --bundle kingdee.Password

Java Eclipse 中报错的代码:
System info: host: 'ifufeiyangtekiMac.local', ip: '192.168.235.131', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.4', java.version: '1.8.0'
Driver info: io.appium.java_client.AppiumDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:95)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:126)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:153)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:49)
at com.teiron.app.Password.TestRealiPhone.setUp(TestRealiPhone.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:653)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

程序部分代码:

public void testUIComputation() throws Exception {  
    //触发生成密码按钮
    WebElement button = driver.findElement(By.name("button_pwd"));
    button.click();
    //断言生成的值是否跟输入的值相等
    WebElement texts = driver.findElement(By.name("Text_pwd"));
    assertEquals("判断值是否相等:",String.valueOf(texts.getText().length()), String.valueOf(values.get(0)));     
}```

最好加个等待, 因为 appium 接受不到命令, 会有一个超时, 然后就退出 session 了

#8 楼 @seveniruby 恩。这样更好

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up