You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

运行Android端Appium测试时遇配置失败错误

Appium测试突然全部报错:SessionNotCreatedException(响应码404,会话未知)

核心问题分析

测试用例原本运行正常,突然全部失败,核心错误为SessionNotCreatedException,提示无法启动新会话,响应码404,会话标识未知,问题出现在@BeforeClass的ConfigureAppium初始化方法中,说明会话创建环节出现异常。

排查与解决步骤

  • 强制重启所有相关服务与设备

    1. 关闭所有Appium服务进程(Windows任务管理器中杀掉node.exe进程)
    2. 重启Android模拟器/真机,执行adb devices验证设备正常在线
    3. 重新启动Appium服务后运行测试
  • 清理无效会话与端口占用

    1. 检查Appium默认端口4723是否被占用:执行netstat -ano | findstr 4723(Windows),若占用则终止对应进程或更换Appium启动端口
    2. 异常终止的会话可能残留缓存,重启Appium可彻底清理无效会话记录
  • 验证Capabilities配置

    1. 确认app路径有效性:检查C://Users//z0049922//eclipse-workspace//Appium//src//test//java//resources//ApiDemos-debug.apk文件是否存在,路径无拼写错误
    2. 核对deviceName与adb devices输出的设备名称完全一致
    3. 确保automationName: UIAutomator2对应的驱动已正确安装,可用Appium Doctor验证环境依赖
  • 检查版本兼容性
    当前使用Selenium 4.8.3,需确保Appium Java Client版本与之兼容,版本不匹配会导致会话创建失败。参考Appium官方兼容性说明,升级或降级对应依赖包。

  • 消除SLF4J日志警告(可选)
    项目中添加SLF4J日志实现依赖(如slf4j-simple),消除日志警告,避免干扰问题排查。

完整报错信息

[RemoteTestNG] detected TestNG version 7.4.0
SLF4J:未找到SLF4J提供程序。
SLF4J:默认使用无操作(NOP)日志记录实现
SLF4J:详情请查看相关文档
配置失败:@BeforeClass ConfigureAppium
org.openqa.selenium.SessionNotCreatedException:无法启动新会话。响应码404。消息:标识为75ad261c-e451-4504-8a07-92aa6195faf9的会话未知
Host info: host: 'WINL0PF27XF4G', ip: '10.126.53.194'
Build info: version: '4.8.3', revision: 'e5e76298c3'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '15.0.2'
Driver info: io.appium.java_client.android.AndroidDriver
Command: [null, newSession {capabilities=[{appium:deviceName=Emulator1, platformName=ANDROID, appium:automationName=UIAutomator2, appium:app=C://Users//z0049922//eclipse-workspace//Appium//src//test//java//resources//ApiDemos-debug.apk}], desiredCapabilities=Capabilities {appium:app: C://Users//z0049922//eclips..., appium:automationName: UIAutomator2, appium:deviceName: Emulator1, platformName: ANDROID}}]
Capabilities {appium:app: C://Users//z0049922//eclips..., appium:automationName: UIAutomator2, appium:deviceName: Emulator1, platformName: ANDROID}
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:148)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at io.appium.java_client.remote.AppiumProtocolHandshake.createSession(AppiumProtocolHandshake.java:133)
at io.appium.java_client.remote.AppiumProtocolHandshake.createSession(AppiumProtocolHandshake.java:102)
at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:194)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:262)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:229)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:157)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:80)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:92)
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:117)
at Srivalli.BaseTest.ConfigureAppium(BaseTest.java:30)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:62)
at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:385)
at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:321)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:176)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:122)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.testng.TestRunner.privateRun(TestRunner.java:794)
at org.testng.TestRunner.run(TestRunner.java:596)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:377)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332)
at org.testng.SuiteRunner.run(SuiteRunner.java:276)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
at org.testng.TestNG.runSuites(TestNG.java:1063)
at org.testng.TestNG.run(TestNG.java:1031)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

跳过:AppiumTest
org.openqa.selenium.SessionNotCreatedException:无法启动新会话。响应码404。消息:标识为75ad261c-e451-4504-8a07-92aa6195faf9的会话未知
Host info: host: 'WINL0PF27XF4G', ip: '10.126.53.194'
Build info: version: '4.8.3', revision: 'e5e76298c3'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '15.0.2'
Driver info: io.appium.java_client.android.AndroidDriver
Command: [null, newSession {capabilities=[{appium:deviceName=Emulator1, platformName=ANDROID, appium:automationName=UIAutomator2, appium:app=C://Users//z0049922//eclipse-workspace//Appium//src//test//java//resources//ApiDemos-debug.apk}], desiredCapabilities=Capabilities {appium:app: C://Users//z0049922//eclips..., appium:automationName: UIAutomator2, appium:deviceName: Emulator1, platformName: ANDROID}}]
Capabilities {appium:app: C://Users//z0049922//eclips..., appium:automationName: UIAutomator2, appium:deviceName: Emulator1, platformName: ANDROID}
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:148)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at io.appium.java_client.remote.AppiumProtocolHandshake.createSession(AppiumProtocolHandshake.java:133)
at io.appium.java_client.remote.AppiumProtocolHandshake.createSession(AppiumProtocolHandshake.java:102)
at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:194)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:262)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:229)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:157)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:80)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:92)
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:117)
at Srivalli.BaseTest.ConfigureAppium(BaseTest.java:30)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:62)
at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:385)
at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:321)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:176)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:122)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.testng.TestRunner.privateRun(TestRunner.java:794)
at org.testng.TestRunner.run(TestRunner.java:596)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:377)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332)
at org.testng.SuiteRunner.run(SuiteRunner.java:276)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
at org.testng.TestNG.runSuites(TestNG.java:1063)
at org.testng.TestNG.run(TestNG.java:1031)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

===============================================
默认测试
运行测试数:1,失败数:0,跳过数:1
配置失败数:1,配置跳过数:0

内容的提问来源于stack exchange,提问作者srivalli srikakolapu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 12:57:02