org.openqa.selenium.SessionNotCreatedException:无法创建新会话

时间:2017-09-22 09:28:51

标签: appium

当我运行我的appium测试用例时出现此错误,下面是我的程序

import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

public class Sample {

@Test
public void m1() throws MalformedURLException, InterruptedException{
    // Create object of desired class and specify android platform
    DesiredCapabilities capabilities = DesiredCapabilities.android();

    // set the capabilities to execute in chrome browser
    capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, BrowserType.CHROME);

    // set capability to execute our test in Android platform
    capabilities.setCapability(CapabilityType.PLATFORM, Platform.ANDROID);

    // need to define platform name
    capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");

    // set device name
    capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "My Mobile");

    // set version
    capabilities.setCapability(CapabilityType.VERSION, "6.0");

    // create object of url and assign appium server address
    URL url = new URL("http://127.0.0.1:4723/wd/hub");

    WebDriver driver = new AndroidDriver<>(url, capabilities);
    driver.get("http://www.facebook.com");
    System.out.println(driver.getTitle());
    driver.findElement(By.name("email")).sendKeys("suhailxxxxx@gmail.com");
    driver.findElement(By.name("pass")).sendKeys("xxxxxxxxx");
    Thread.sleep(10000);
}

}

以下是我在eclipse中遇到的问题

FAILED: m1
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: spawn "D:\softwares\Appium_New\android-sdk-windows\platform-tools\adb.exe" ENOENT) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 11.87 seconds
Build info: version: '3.5.3', revision: 'a88d25fe6b', time: '2017-08-29T12:54:15.039Z'
System info: host: 'ACC-H-SUHAAHME', ip: '172.18.201.83', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_144'
Driver info: driver.version: AndroidDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:215)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$24(ProtocolHandshake.java:359)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source)
at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.findFirst(Unknown Source)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:362)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:136)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:89)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:646)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
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:255)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:237)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:138)
at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:38)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:87)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:111)
at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:72)
at io.app.Sample.m1(Sample.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:645)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:851)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1177)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:756)
at org.testng.TestRunner.run(TestRunner.java:610)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
at org.testng.TestNG.runSuites(TestNG.java:1133)
at org.testng.TestNG.run(TestNG.java:1104)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)

这是我在appium服务器上的问题

  

info:[debug]使用快速重置?真正   info:[debug]准备会话设备   info:[debug]不检查app是否存在,因为我们假设它已经在设备上   info:检索设备   info:[debug]试图找到一个连接的Android设备   info:[debug]获取连接设备...   info:[debug]执行cmd:“D:\ softwares \ Appium_New \ android-sdk-windows \ platform-tools \ adb.exe”设备   info:[debug] 1个设备已连接   info:找到设备PBG6WSCEM7QSTK69   info:[debug]将设备ID设置为PBG6WSCEM7QSTK69   info:[debug]等待设备准备就绪并响应shell命令(timeout = 5)   info:[debug]执行cmd:“D:\ softwares \ Appium_New \ android-sdk-windows \ platform-tools \ adb.exe”-s PBG6WSCEM7QSTK69等待设备   info:[debug]重试restartAdb   info:[debug]执行cmd:“D:\ softwares \ Appium_New \ android-sdk-windows \ platform-tools \ adb.exe”-s PBG6WSCEM7QSTK69 kill-server   info:[debug]获取连接设备...   info:[debug]执行cmd:“D:\ softwares \ Appium_New \ android-sdk-windows \ platform-tools \ adb.exe”-s PBG6WSCEM7QSTK69设备   info:[debug] 1个设备已连接   info:[debug]等待设备准备就绪并响应shell命令(timeout = 5)   info:[debug]执行cmd:“D:\ softwares \ Appium_New \ android-sdk-windows \ platform-tools \ adb.exe”-s PBG6WSCEM7QSTK69等待设备   info:[debug]执行cmd:“D:\ softwares \ Appium_New \ android-sdk-windows \ platform-tools \ adb.exe”-s PBG6WSCEM7QSTK69 shell“echo'ready'”   info:[debug]启动logcat捕获   info:[debug]清理appium会话   错误:Logcat捕获失败:生成“D:\ softwares \ Appium_New \ android-sdk-windows \ platform-tools \ adb.exe”ENOENT   错误:无法启动Appium会话,错误是:错误:生成“D:\ softwares \ Appium_New \ android-sdk-windows \ platform-tools \ adb.exe”ENOENT   info:[debug]错误:产生“D:\ softwares \ Appium_New \ android-sdk-windows \ platform-tools \ adb.exe”ENOENT       at exports._errnoException(util.js:746:11)       在Process.ChildProcess._handle.onexit(child_process.js:1054:32)       在child_process.js:1145:20       at process._tickDomainCallback(node.js:381:11)   info:[debug]响应客户端错误:{“status”:33,“value”:{“message”:“无法创建新会话。(原始错误:spawn \”D:\ softwares \ Appium_New \ android-sdk-windows \ platform-tools \ adb.exe \“ENOENT)”,“code”:“ENOENT”,“errno”:“ENOENT”,“syscall”:“spawn”D:\ softwares \ Appium_New \ Android的SDK-WINDOWS \平台工具\ adb.exe \ “”, “路径”: “\” d:\软件\ Appium_New \ Android的SDK-WINDOWS \平台工具\ adb.exe \ “”,“origValue “:”spawn \“D:\ softwares \ Appium_New \ android-sdk-windows \ platform-tools \ adb.exe \”ENOENT“},”sessionId“:null}   info:&lt; - POST / wd / hub / session 500 10417.138 ms - 510

3 个答案:

答案 0 :(得分:0)

请检查您的APPIUM服务器,它是否已启动。

答案 1 :(得分:0)

更新您的appium服务器,节点JS和npm然后尝试一下。它对我有用,我在更新到版本1.7.1之后使用了appium server 1.4。

答案 2 :(得分:0)

您可以关闭当前的appium会话并重试。如果您仍然看到错误,那么您的appium版本是什么