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

Appium+WinAppDriver配置受阻:双服务运行仍遇HTTP 500错误

解决Appium 5.x + WinAppDriver 端口冲突与连接问题

问题背景

从Appium 5.0.0开始,WinAppDriver不再被直接集成,需通过Appium作为代理对接,因此需同时运行Appium Server和WinAppDriver两个服务。为避免默认端口4723冲突,配置Appium Server运行在4723端口,WinAppDriver运行在4724端口,但启动C#测试代码时出现连接错误。

报错信息

C#应用报错

Unhandled Exception: OpenQA.Selenium.UnknownErrorException: An unknown server-side error occurred while processing the command. Original error: WinAppDriver server is not listening at http://127.0.0.1:4724. Make sure it is running and the provided wadUrl is correct
   at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse, String commandToExecute)
   at OpenQA.Selenium.WebDriver.<ExecuteAsync>d__63.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Appium.AppiumDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.WebDriver.StartSession(ICapabilities capabilities)
   at OpenQA.Selenium.WebDriver..ctor(ICommandExecutor executor, ICapabilities capabilities)
   at OpenQA.Selenium.Appium.AppiumDriver..ctor(Uri remoteAddress, ICapabilities appiumOptions)
   at OpenQA.Selenium.Appium.Windows.WindowsDriver..ctor(Uri remoteAddress, AppiumOptions AppiumOptions)
   at CalculatorTest.CalculatorSession.Main() in C:\Users\vitto\source\repos\ConsoleApp1\ConsoleApp1\Program.cs:line 26

C:\Users\vitto\source\repos\ConsoleApp1\ConsoleApp1\bin\Debug\ConsoleApp1.exe (process 127192) exited with code -532462766 (0xe0434352).

WinAppDriver控制台报错

GET /status HTTP/1.1
Accept: application/json, /
Accept-Encoding: gzip, compress, deflate, br
Connection: keep-alive
Content-Type: application/json; charset=utf-8
Host: 127.0.0.1:4724
User-Agent: appium

HTTP/1.1 500 Internal Error
Content-Length: 133
Content-Type: application/json

{"status":13,"value":{"error":"unknown error","message":"An unknown error occurred in the remote end while processing the command."}}

解决方案

1. 正确启动WinAppDriver

  • 必须以管理员身份打开命令提示符,执行以下命令启动WinAppDriver并指定端口:
    WinAppDriver.exe 4724
    
    直接双击WinAppDriver会默认使用4723端口,导致冲突;非管理员运行会出现权限不足的500错误。

2. 修正代码中的Capability配置

Appium 5.x中指定WinAppDriver地址的正确Capability名称是appium:winAppDriverUrl,而非appium:wadUrl。修正后的代码如下:

namespace CalculatorTest
{
    public class CalculatorSession
    {
        private const string AppiumServerUrl = "http://127.0.0.1:4723/";
        private const string CalculatorID = "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App";

        protected static WindowsDriver session;

        public static void Main()
        {
            AppiumOptions appiumOptions = new AppiumOptions
            {
                App = CalculatorID,
                PlatformName = "Windows",
                AutomationName = "Windows"
            };

            // 修正为正确的Capability名称
            appiumOptions.AddAdditionalAppiumOption("appium:winAppDriverUrl", "http://127.0.0.1:4724");

            session = new WindowsDriver(new Uri(AppiumServerUrl), appiumOptions);

            Assert.IsNotNull(session);
            Assert.IsNotNull(session.SessionId);

            session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1.5);
        }
    }
}

3. 验证端口与服务状态

  • 检查4724端口是否被占用:执行netstat -ano | findstr :4724,确认输出中包含WinAppDriver的进程ID。
  • 验证Appium服务正常:访问http://127.0.0.1:4723/wd/hub/status,返回JSON格式的状态信息说明服务正常。

4. 确保测试程序权限

  • 以管理员身份运行你的C#测试项目,避免访问Windows应用时出现权限限制。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 23:03:25