org.openqa.selenium.SessionNotCreatedException:无法创建新会话。 (原始错误:请求新会话但其中一个正在进行中)

时间:2015-08-17 10:25:43

标签: java ios appium

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

我的能力是 @BeforeMethod public void setUp()抛出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)

4 个答案:

答案 0 :(得分:6)

这是因为前一个会话没有正确关闭,并且在测试中抛出异常时会发生这种情况。重新启动appium服务器并尝试它,它应该解决问题。

或者,如果您将appium作为节点进程启动,则可以提供选项'--session-override true',这样可以避免此问题

答案 1 :(得分:3)

以下内容对我有用。我正在通过连接Android设备进行测试。请根据您的需要进行更改并申请,现在应该可以使用。

        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);

答案 2 :(得分:1)

如果在appium app上,请选择设置 -

下的Override Existing Sessions复选框

enter image description here

答案 3 :(得分:0)

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