我试图进行我的第一次Appium JAVA测试 这是我的代码:
System.out.println("driver being created...");
CommandLine command = new CommandLine("cmd");
command.addArgument(" /c",false);
command.addArgument("C:\\Appium\\node.exe",false);
command.addArgument("C:\\Appium\\node_modules\\appium\\bin\\appium.js",false);
command.addArgument("--address",false);
command.addArgument("127.0.0.1",false);
command.addArgument("--bootstrap-port",false);
command.addArgument("4723",false);
command.addArgument("--no-reset",false);
command.addArgument("--log",false);
command.addArgument("C:\\Users\\eliyahu.n\\appiumLogs.txt",false);
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
executor = new DefaultExecutor();
executor.setExitValue(1);
executor.execute(command, resultHandler);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("newCommandTimeout", 0);
capabilities.setCapability("deviceName", "Redmi");
capabilities.setCapability("app", "C:\\Users\\eliyahu.n\\******.com.apk");
capabilities.setCapability("appPackage","com.ls.******");
capabilities.setCapability("appActivity","com.ls.******.activity.SplashActivity");
Thread.sleep(8000);
driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
Appium试图开始但失败了 它启动appium,检测JAVA版本,检索设备,指示设备ID,设备API级别,然后关闭以下日志/错误:
[36minfo [39m: [debug] executing cmd: C:\Users\eliyahu.n\sdk\platform-tools\adb.exe -s 5DIBRCYL99999999 shell "pm list packages -3 com.ls.*****"
[36minfo [39m: [debug] App is installed
[36minfo [39m: [debug] Forwarding system:4723 to device:4724
[36minfo [39m: [debug] executing cmd: C:\Users\eliyahu.n\sdk\platform-tools\adb.exe -s 5DIBRCYL99999999 forward tcp:4723 tcp:4724
[36minfo [39m: [debug] Stopping logcat capture
[36minfo [39m: [debug] Logcat terminated with code null, signal SIGTERM
[36minfo [39m: [debug] Sent shutdown command, waiting for UiAutomator to stop...
[33mwarn [39m: UiAutomator did not shut down fast enough, calling it gone
[36minfo [39m: [debug] Cleaning up android objects
[36minfo [39m: [debug] Cleaning up appium session
[36minfo [39m: [debug] Error: Command failed: C:\Windows\system32\cmd.exe /s /c "C:\Users\eliyahu.n\sdk\platform-tools\adb.exe -s 5DIBRCYL99999999 forward tcp:4723 tcp:4724"
error: cannot bind listener: cannot bind to 127.0.0.1:4723: Only one usage of each socket address (protocol/network address/port) is normally permitted. (10048)
at ChildProcess.exithandler (child_process.js:751:12)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js:1016:16)
at Socket.<anonymous> (child_process.js:1184:11)
at Socket.emit (events.js:107:17)
at Pipe.close (net.js:484:11)
[36minfo [39m: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Command failed: C:\\Windows\\system32\\cmd.exe /s /c \"C:\\Users\\eliyahu.n\\sdk\\platform-tools\\adb.exe -s 5DIBRCYL99999999 forward tcp:4723 tcp:4724\"\nerror: cannot bind listener: cannot bind to 127.0.0.1:4723: Only one usage of each socket address (protocol/network address/port) is normally permitted. (10048)\r\n)","killed":false,"code":1,"signal":null,"cmd":"C:\\Windows\\system32\\cmd.exe /s /c \"C:\\Users\\eliyahu.n\\sdk\\platform-tools\\adb.exe -s 5DIBRCYL99999999 forward tcp:4723 tcp:4724\"","origValue":"Command failed: C:\\Windows\\system32\\cmd.exe /s /c \"C:\\Users\\eliyahu.n\\sdk\\platform-tools\\adb.exe -s 5DIBRCYL99999999 forward tcp:4723 tcp:4724\"\nerror: cannot bind listener: cannot bind to 127.0.0.1:4723: Only one usage of each socket address (protocol/network address/port) is normally permitted. (10048)\r\n"},"sessionId":null}
[36minfo [39m: [37m<-- POST /wd/hub/session [39m [31m500 [39m [90m 23274.689 ms - 944 [39m [90m [39m
[31merror [39m: Failed to start an Appium session, err was: Error: Command failed: C:\Windows\system32\cmd.exe /s /c "C:\Users\eliyahu.n\sdk\platform-tools\adb.exe -s 5DIBRCYL99999999 forward tcp:4723 tcp:4724"
error: cannot bind listener: cannot bind to 127.0.0.1:4723: Only one usage of each socket address (protocol/network address/port) is normally permitted. (10048)
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Command failed: C:\Windows\system32\cmd.exe /s /c "C:\Users\eliyahu.n\sdk\platform-tools\adb.exe -s 5DIBRCYL99999999 forward tcp:4723 tcp:4724"
error: cannot bind listener: cannot bind to 127.0.0.1:4723: Only one usage of each socket address (protocol/network address/port) is normally permitted. (10048)
) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:49:13 -0700'
System info: host: 'QA-PC', ip: '172.20.1.87', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_112'
Driver info: driver.version: AndroidDriver
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:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:161)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:64)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:69)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:40)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:141)
at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:36)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:114)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:132)
at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:92)
at MyFirstTest.setupTest(MyFirstTest.java:97)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
答案 0 :(得分:0)
通过更改以下代码来解决问题
command.addArgument("--bootstrap-port",false);
command.addArgument("4723",false);
到
command.addArgument("--bootstrap-port",true);
command.addArgument("4725",true);