点击button时自动testing失败

我从appium github下载了一个简单的应用程序,并尝试使用Appium Server(1.3.3版)为其编写自动化testing。 这是我的代码

import io.appium.java_client.AppiumDriver; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.remote.DesiredCapabilities; import java.net.MalformedURLException; import java.net.URL; import java.util.concurrent.TimeUnit; import static org.testng.AssertJUnit.assertEquals; public class AppiumDemo { private AppiumDriver ad; @Before public void setupTest(){ DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("appium-version", "1.3.3"); capabilities.setCapability("platformName", "iOS"); capabilities.setCapability("platformVersion", "7.1"); capabilities.setCapability("deviceName", "iPhone 5s"); capabilities.setCapability("app", "/Users/admin/Downloads/TestApp.app"); try { ad = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); } catch (MalformedURLException e) { e.printStackTrace(); } } @After public void tearDown(){ if(ad != null) ad.quit(); } @Test public void main() { ad.findElement(By.name("IntegerA")).sendKeys("11"); ad.findElement(By.name("IntegerB")).sendKeys("1"); ad.findElement(By.name("ComputeSumButton")).click(); int ans = Integer.parseInt(ad.findElement(By.name("Answer")).getText()); assertEquals(ans, 12); ad.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); } } 

它打开模拟器,input2个数字,但是当点击button计算总和时,testing崩溃,模拟器死亡。 在intellij它表明,它失败了,我按下点击。 和 – 处理完成退出代码255.我使用安装在wmware上的优胜美地,10.10.1版。 请帮帮我,可能是什么原因呢? 非常感谢。

这里是我的Appium日志有趣的部分

 info: [debug] [INST] 2014-12-29 12:03:27 +0000 Debug: Got new command 3 from instruments: au.getElementByName('IntegerA') info: [debug] [INST] 2014-12-29 12:03:27 +0000 Debug: evaluating au.getElementByName('IntegerA') info: [debug] [INST] 2014-12-29 12:03:27 +0000 Debug: evaluation finished info: [debug] Socket data received (38 bytes) info: [debug] Socket data being routed. info: [debug] Got result from instruments: {"status":0,"value":{"ELEMENT":"0"}} info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"0"},"sessionId":"b488504c-fada-4d13-801b-67ddfda7fcfb"} info: <-- POST /wd/hub/session/b488504c-fada-4d13-801b-67ddfda7fcfb/element 200 371.561 ms - 87 {"status":0,"value":{"ELEMENT":"0"},"sessionId":"b488504c-fada-4d13-801b-67ddfda7fcfb"} info: [IOS_SYSLOG_ROW ] Dec 29 16:03:27 Admins-Mac.local lsd[3625] <Warning>: LaunchServices: Currently 0 installed placeholders: ( info: [IOS_SYSLOG_ROW ] ) info: --> POST /wd/hub/session/b488504c-fada-4d13-801b-67ddfda7fcfb/element/0/value {"id":"0","value":["11"]} info: [debug] Pushing command to appium work queue: "au.getElement('0').setValueByType('11')" info: [debug] Sending command to instruments: au.getElement('0').setValueByType('11') info: [debug] [INST] 2014-12-29 12:03:27 +0000 Debug: Lookup returned [object UIATextField] with the name "IntegerA" (id: 0). info: [debug] [INST] 2014-12-29 12:03:27 +0000 Debug: responding with: info: [debug] [INST] 2014-12-29 12:03:27 +0000 Debug: Running system command #4: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":{"ELEMENT":"0"}}... info: [debug] [INST] 2014-12-29 12:03:28 +0000 Debug: Got new command 4 from instruments: au.getElement('0').setValueByType('11') info: [debug] [INST] 2014-12-29 12:03:28 +0000 Debug: evaluating au.getElement('0').setValueByType('11') info: [debug] [INST] 2014-12-29 12:03:28 +0000 Debug: UIATextField.tap() info: [IOS_SYSLOG_ROW ] Dec 29 16:03:28 Admins-Mac.local backboardd[3609] <Error>: HID: The 'Rate Controlled' connection 'ScriptAgent' access to protected services is denied. info: [debug] [INST] 2014-12-29 12:03:29 +0000 Debug: UIATextField.tap() info: [IOS_SYSLOG_ROW ] Dec 29 16:03:31 Admins-Mac.local calaccessd[3653] <Notice>: 2014-12-29 16:03:31.354|3653|0x103c48c80: Updating birthday calendar info: [IOS_SYSLOG_ROW ] Dec 29 16:03:31 Admins-Mac.local calaccessd[3653] <Notice>: 2014-12-29 16:03:31.356|3653|0x103c48c80: BirthdayCal: Processing 6 people... info: [IOS_SYSLOG_ROW ] Dec 29 16:03:31 Admins-Mac.local calaccessd[3653] <Notice>: 2014-12-29 16:03:31.418|3653|0x103c48c80: BirthdayCal: Done. 4 adds, 0 updates, 0 deletes. info: [IOS_SYSLOG_ROW ] Dec 29 16:03:31 Admins-Mac.local SpringBoard[3619] <Notice>: 2014-12-29 16:03:31.429|3619|0x117839a40: Region monitoring not available or enabled. Trigger ignored! info: [IOS_SYSLOG_ROW ] Dec 29 16:03:31 Admins-Mac.local mobileassetd[3656] <Error>: Could not copy XPC event for stream/key: com.apple.xpc.activity/com.apple.mobileassetd.queued-asset-download: 3: No such process info: [debug] [INST] 2014-12-29 12:03:31 +0000 Debug: target.frontMostApp().keyboard().typeString("1") info: [debug] [INST] 2014-12-29 12:03:33 +0000 Debug: target.frontMostApp().keyboard().typeString("1") info: [debug] [INST] 2014-12-29 12:03:33 +0000 Debug: evaluation finished info: [debug] [INST] 2014-12-29 12:03:33 +0000 Debug: responding with: info: [debug] Socket data received (25 bytes) info: [debug] Socket data being routed. info: [debug] Got result from instruments: {"status":0,"value":""} info: [debug] Responding to client with success: {"status":0,"value":"","sessionId":"b488504c-fada-4d13-801b-67ddfda7fcfb"} info: <-- POST /wd/hub/session/b488504c-fada-4d13-801b-67ddfda7fcfb/element/0/value 200 6311.176 ms - 74 {"status":0,"value":"","sessionId":"b488504c-fada-4d13-801b-67ddfda7fcfb"} info: --> POST /wd/hub/session/b488504c-fada-4d13-801b-67ddfda7fcfb/element {"using":"name","value":"IntegerB"} info: [debug] Waiting up to 0ms for condition info: [debug] Pushing command to appium work queue: "au.getElementByName('IntegerB')" info: [debug] Sending command to instruments: au.getElementByName('IntegerB') info: [debug] [INST] 2014-12-29 12:03:33 +0000 Debug: Running system command #5: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":""}... info: [debug] [INST] 2014-12-29 12:03:34 +0000 Debug: Got new command 5 from instruments: au.getElementByName('IntegerB') 2014-12-29 12:03:34 +0000 Debug: evaluating au.getElementByName('IntegerB') info: [debug] [INST] 2014-12-29 12:03:34 +0000 Debug: evaluation finished info: [debug] [INST] 2014-12-29 12:03:34 +0000 Debug: Lookup returned [object UIATextField] with the name "IntegerB" (id: 1). info: [debug] [INST] 2014-12-29 12:03:34 +0000 Debug: responding with: info: [debug] [INST] 2014-12-29 12:03:34 +0000 Debug: Running system command #6: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":{"ELEMENT":"1"}}... info: [debug] Socket data received (38 bytes) info: [debug] Socket data being routed. info: [debug] Got result from instruments: {"status":0,"value":{"ELEMENT":"1"}} info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"1"},"sessionId":"b488504c-fada-4d13-801b-67ddfda7fcfb"} info: <-- POST /wd/hub/session/b488504c-fada-4d13-801b-67ddfda7fcfb/element 200 298.653 ms - 87 {"status":0,"value":{"ELEMENT":"1"},"sessionId":"b488504c-fada-4d13-801b-67ddfda7fcfb"} info: --> POST /wd/hub/session/b488504c-fada-4d13-801b-67ddfda7fcfb/element/1/value {"id":"1","value":["1"]} info: [debug] Pushing command to appium work queue: "au.getElement('1').setValueByType('1')" info: [debug] Sending command to instruments: au.getElement('1').setValueByType('1') info: [debug] [INST] 2014-12-29 12:03:35 +0000 Debug: Got new command 6 from instruments: au.getElement('1').setValueByType('1') info: [debug] [INST] 2014-12-29 12:03:35 +0000 Debug: evaluating au.getElement('1').setValueByType('1') 2014-12-29 12:03:35 +0000 Debug: UIATextField.tap() info: [debug] [INST] 2014-12-29 12:03:35 +0000 Debug: target.frontMostApp().keyboard().typeString("1") info: [debug] [INST] 2014-12-29 12:03:36 +0000 Debug: evaluation finished info: [debug] Socket data received (25 bytes) info: [debug] Socket data being routed. info: [debug] Got result from instruments: {"status":0,"value":""} info: [debug] Responding to client with success: {"status":0,"value":"","sessionId":"b488504c-fada-4d13-801b-67ddfda7fcfb"} info: <-- POST /wd/hub/session/b488504c-fada-4d13-801b-67ddfda7fcfb/element/1/value 200 1962.511 ms - 74 {"status":0,"value":"","sessionId":"b488504c-fada-4d13-801b-67ddfda7fcfb"} info: --> POST /wd/hub/session/b488504c-fada-4d13-801b-67ddfda7fcfb/element {"using":"name","value":"ComputeSumButton"} info: [debug] Waiting up to 0ms for condition info: [debug] Pushing command to appium work queue: "au.getElementByName('ComputeSumButton')" info: [debug] Sending command to instruments: au.getElementByName('ComputeSumButton') info: [debug] [INST] 2014-12-29 12:03:36 +0000 Debug: responding with: info: [debug] [INST] 2014-12-29 12:03:36 +0000 Debug: Running system command #7: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":""}... info: [debug] [INST] 2014-12-29 12:03:37 +0000 Debug: Got new command 7 from instruments: au.getElementByName('ComputeSumButton') info: [debug] [INST] 2014-12-29 12:03:37 +0000 Debug: evaluating au.getElementByName('ComputeSumButton') info: [debug] [INST] 2014-12-29 12:03:37 +0000 Debug: evaluation finished info: [debug] [INST] 2014-12-29 12:03:37 +0000 Debug: Lookup returned [object UIAButton] with the name "ComputeSumButton" (id: 2). 2014-12-29 12:03:37 +0000 Debug: responding with: info: [debug] [INST] 2014-12-29 12:03:37 +0000 Debug: Running system command #8: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":{"ELEMENT":"2"}}... info: [debug] Socket data received (38 bytes) info: [debug] Socket data being routed. info: [debug] Got result from instruments: {"status":0,"value":{"ELEMENT":"2"}} info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"2"},"sessionId":"b488504c-fada-4d13-801b-67ddfda7fcfb"} info: <-- POST /wd/hub/session/b488504c-fada-4d13-801b-67ddfda7fcfb/element 200 833.732 ms - 87 {"status":0,"value":{"ELEMENT":"2"},"sessionId":"b488504c-fada-4d13-801b-67ddfda7fcfb"} info: --> POST /wd/hub/session/b488504c-fada-4d13-801b-67ddfda7fcfb/element/2/click {"id":"2"} info: [debug] Pushing command to appium work queue: "au.getElement('2').rect()" info: [debug] Sending command to instruments: au.getElement('2').rect() info: [debug] [INST] 2014-12-29 12:03:38 +0000 Debug: Got new command 8 from instruments: au.getElement('2').rect() info: [debug] [INST] 2014-12-29 12:03:38 +0000 Debug: evaluating au.getElement('2').rect() info: [debug] [INST] 2014-12-29 12:03:38 +0000 Debug: evaluation finished 2014-12-29 12:03:38 +0000 Debug: responding with: info: [debug] Socket data received (83 bytes) info: [debug] Socket data being routed. info: [debug] Got result from instruments: {"status":0,"value":{"origin":{"x":94,"y":122},"size":{"width":113,"height":37}}} info: [debug] Responding to client with error: {"status":13,"value":{"message":"An unknown server-side error occurred while processing the command. (Original error: connect ECONNREFUSED)","code":"ECONNREFUSED","errno":"ECONNREFUSED","syscall":"connect","origValue":"connect ECONNREFUSED"},"sessionId":"b488504c-fada-4d13-801b-67ddfda7fcfb"} info: <-- POST /wd/hub/session/b488504c-fada-4d13-801b-67ddfda7fcfb/element/2/click 500 1022.219 ms - 293 info: --> GET /wd/hub/status {} info: [debug] Responding to client with success: {"status":0,"value":{"build":{"version":"1.3.3","revision":"34e21b01b87d4e3959e1c97c0a8d0b1a610bdc78"},"isShuttingDown":false},"sessionId":"b488504c-fada-4d13-801b-67ddfda7fcfb"} info: <-- GET /wd/hub/status 200 1.537 ms - 178 {"status":0,"value":{"build":{"version":"1.3.3","revision":"34e21b01b87d4e3959e1c97c0a8d0b1a610bdc78"},"isShuttingDown":false},"sessionId":"b488504c-fada-4d13-801b-67ddfda7fcfb"} info: --> DELETE /wd/hub/session/b488504c-fada-4d13-801b-67ddfda7fcfb {} info: Shutting down appium session info: [debug] Stopping ios info: [debug] Destroying instruments client socket. info: [debug] Closing socket server. info: [debug] Instruments socket server was closed info: [debug] Sending sigterm to instruments info: [debug] [INST] 2014-12-29 12:03:38 +0000 Debug: Running system command #9: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":{"origin":{"x":94,"y":122},"size":{"width":113,"height":37}}}... info: [IOS_SYSLOG_ROW ] Dec 29 16:03:38 Admins-Mac.local mstreamd[3614] <Notice>: (Note ) PS: Media stream daemon stopping. info: [IOS_SYSLOG_ROW ] Dec 29 16:03:38 Admins-Mac.local mstreamd[3614] <Notice>: (Note ) AS: <MSIOSAlbumSharingDaemon: 0x103b14220>: Shared Streams daemon has shut down. info: [IOS_SYSLOG_ROW ] Dec 29 16:03:38 Admins-Mac.local mstreamd[3614] <Notice>: (Warn ) mstreamd: mstreamd shutting down. info: [debug] Instruments didn't terminate after 3 seconds; trying to kill it info: [debug] Killall instruments info: [debug] Stopping iOS log capture info: [debug] Running ios sim reset flow info: [debug] Killing the simulator process info: [debug] Killall iOS Simulator 

这是我的智能日志

 org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. (Original error: connect ECONNREFUSED) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 1.02 seconds Build info: version: '2.42.1', revision: '68b415adb11acca4286be45124325cc36cfc4a51', time: '2014-05-29 09:21:55' System info: host: 'Admins-Mac.local', ip: '192.168.0.178', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.1', java.version: '1.7.0_71' Session ID: 6da466a5-3e93-4c32-9e33-306931e05035 Driver info: io.appium.java_client.AppiumDriver Capabilities [{platformVersion=7.1, app=/Users/admin/Downloads/TestApp.app, platform=MAC, databaseEnabled=false, javascriptEnabled=true, deviceName=iPhone 5s, platformName=iOS, browserName=iOS, appium-version=1.3.3, webStorageEnabled=false, networkConnectionEnabled=false, desired={platformVersion=7.1, app=/Users/admin/Downloads/TestApp.app, platformName=iOS, deviceName=iPhone 5s, appium-version=1.3.3}, locationContextEnabled=false, warnings={}, takesScreenshot=true}] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) 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:600) at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:82) at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268) at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:79) at AppiumDemo.simpleTest(AppiumDemo.java:47) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.junit.runner.JUnitCore.run(JUnitCore.java:160) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) Process finished with exit code 255 

我find了这种情况下的解决scheme! Appium支持WebDriver API,所以也许因为它默认的元素是web元素。 所以网页元素没有点击,但有点击,移动元素有点击,而不是点击。 在我们这个例子中,每个元素都应该被声明为移动元素。 所以如果我将我的button声明为Mobile元素,它将具有tapfunction。 🙂

 MobileElement btn = (MobileElement) ad.findElement(By.name("ComputeSumButton")); ... btn.tap(1,1);