org.openqa.selenium.SessionNotCreatedException:无法创build新的会话。 (原始错误:请求新的会话,但正在进行中)

我正在使用Appium 1.4.8 for iOS。 我已经使用xcode在模拟器中构build了代码,并成功地启动了服务器以及Appium Inspector。 但是,当运行我的代码是抛出以下错误。

我的能力是@BeforeMethod public void setUp()throws MalformedURLException {

DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("appium-version", "1.0"); capabilities.setCapability("platformName", "iOS"); capabilities.setCapability("platformVersion", "8.4"); capabilities.setCapability("deviceName", "iPad 2"); capabilities.setCapability("app", "/Users/arunhs/Desktop/AppiumReq/SRC/build/Debug-iphonesimulator/ComplianceWire.app"); driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); 

}

 Error is: FAILED CONFIGURATION: @BeforeMethod setUp org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Requested a new session but one was in progress) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 447 milliseconds Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16' System info: host: 'N/A', ip: 'N/A', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.4', java.version: '1.7.0_79' Driver info: io.appium.java_client.AppiumDriver 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:206) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595) at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:88) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:128) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:155) at io.appium.java_client.AppiumDriver.(AppiumDriver.java:44) at com.selenium.test.DriverScript.setUp(DriverScript.java:68) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213) at org.testng.internal.Invoker.invokeMethod(Invoker.java:590) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:834) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1142) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108) at org.testng.TestRunner.privateRun(TestRunner.java:771) at org.testng.TestRunner.run(TestRunner.java:621) at org.testng.SuiteRunner.runTest(SuiteRunner.java:357) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310) at org.testng.SuiteRunner.run(SuiteRunner.java:259) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1176) at org.testng.TestNG.runSuitesLocally(TestNG.java:1101) at org.testng.TestNG.run(TestNG.java:1009) 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) 

发生这种情况是因为之前的会话没有正常closures,而且在testing中出现exception时会发生这种情况。 重新启动appium服务器并尝试它,它应该解决问题。

或者,如果将appium作为节点进程启动,则可以select'--session-override true' ,这样可以避免这个问题

以下是为我工作。 我正在通过连接Android设备进行testing。 请根据您的需要进行更改并申请,现在这个工作。

  DesiredCapabilities capabilities = new DesiredCapabilities().android(); capabilities.setCapability("no",true); capabilities.setCapability("newCommandTimeout", 100000); capabilities.setCapability("noReset", true); capabilities.setCapability(CapabilityType.BROWSER_NAME, ""); capabilities.setCapability(CapabilityType.VERSION, "4.4.2"); capabilities.setCapability("deviceName", "Galaxy nexus"); capabilities.setCapability("app", application.getAbsolutePath()); capabilities.setCapability("automationName", "selendroid"); capabilities.setCapability("noRest", true); driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); 

如果在appium应用程序,然后selectOverride Existing Sessionscheckbox下的设置 –

在这里输入图像说明

在function中添加deviceName有帮助。 在日志中,我可以找出丢失的东西。