Java 应用程序:无法绑定侦听器

Java 应用程序:无法绑定侦听器,java,android,appium,Java,Android,Appium,我正在尝试进行我的第一个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.addArgume

我正在尝试进行我的第一个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);
System.out.println(“正在创建的驱动程序…”);
命令行命令=新命令行(“cmd”);
command.addArgument(“/c”,false);
command.addArgument(“C:\\Appium\\node.exe”,false);
command.addArgument(“C:\\Appium\\node\u modules\\Appium\\bin\\Appium.js”,false);
addArgument(“--address”,false);
addArgument(“127.0.0.1”,false);
addArgument(“--bootstrap port”,false);
command.addArgument(“4723”,false);
addArgument(“--no reset”,false);
addArgument(“--log”,false);
command.addArgument(“C:\\Users\\eliyahu.n\\appiumLogs.txt”,false);
DefaultExecuteSultHandler resultHandler=新的DefaultExecuteSultHandler();
执行者=新的默认执行者();
执行者。设置ExitValue(1);
executor.execute(命令,resultHandler);
DesiredCapabilities=新的DesiredCapabilities();
能力。设置能力(“平台名”、“安卓”);
setCapability(“newCommandTimeout”,0);
能力。设置能力(“deviceName”、“Redmi”);
capabilities.setCapability(“app”,“C:\\Users\\eliyahu.n\\*****.com.apk”);
capabilities.setCapability(“appPackage”、“com.ls.*****”);
capabilities.setCapability(“appActivity”、“com.ls.*********.activity.SplashActivity”);
睡眠(8000);
驱动程序=新的AndroidDriver(新的URL(“http://127.0.0.1:4723/wd/hub(能力),;
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)
[36minfo[39m:[debug]正在执行cmd:C:\Users\eliyahu.n\sdk\platform tools\adb.exe-s 5dibrcyl9999999 shell“pm列表包-3 com.ls.**”
已安装[36minfo[39m:[调试]应用程序
[36minfo[39m:[调试]将系统:4723转发到设备:4724
[36minfo[39m:[debug]正在执行cmd:C:\Users\eliyahu.n\sdk\platform tools\adb.exe-s 5DIBRCYL99999999前向tcp:4723 tcp:4724
[36minfo[39m:[调试]正在停止logcat捕获
[36minfo[39m:[debug]Logcat终止,代码为null,信号为SIGTERM
[36minfo[39m:[debug]已发送关机命令,正在等待UiAutomator停止。。。
[33mwarn[39m:UiAutomator没有足够快地关闭,称它消失了
[36minfo[39m:[debug]清理android对象
[36minfo[39m:[debug]正在清理应用程序会话
[36minfo[39m:[debug]错误:命令失败:C:\Windows\system32\cmd.exe/s/C“C:\Users\eliyahu.n\sdk\platform tools\adb.exe-s 5dibrcyl9999999999转发tcp:4723 tcp:4724”
错误:无法绑定侦听器:无法绑定到127.0.0.1:4723:每个套接字地址(协议/网络地址/端口)通常只允许使用一次。(10048)
在ChildProcess.exithandler(child_process.js:751:12)
在ChildProcess.emit(events.js:110:17)
在maybeClose(child_process.js:1016:16)
在套接字上。(child_process.js:1184:11)
在Socket.emit(events.js:107:17)
at Pipe.close(net.js:484:11)
[36minfo[39m:[debug]响应客户端时出现错误:{“status”:33,“value”:{“message”:“无法创建新会话。(原始错误:命令失败:C:\\Windows\\system32\\cmd.exe/s/C\”C:\\Users\\eliyahu.n\\sdk\\platform tools\\adb.exe-s 5dibrcyl999999999转发tcp:4723 tcp:4724\“\n错误:无法绑定侦听器:无法绑定到127.0.0.1:4723:每个套接字地址(协议/网络地址/端口)通常只允许使用一次。(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 5dibrcyl9999999 forward tcp:4723 tcp:4724\,“origValue”:“命令失败:C:\\Windows\\system32\\cmd.exe/s/C\”C:\\Users\\eliyahu.n\\sdk\\platform tools\\adb.exe-s 5DIBRCYL99999999 forward tcp:4723 tcp:4724\\n错误:无法绑定侦听器:无法绑定到127.0.0.1:4723:每个套接字地址(协议/网络地址/端口)通常只允许使用一次。(10048)\r\n“},“sessionId”:null}

[36minfo[39m:[37m通过更改以下代码,问题得以解决

command.addArgument("--bootstrap-port",false);  
command.addArgument("4723",false);  

command.addArgument("--bootstrap-port",true);  
command.addArgument("4725",true);