我想使用 C# 以编程方式启动 Appium 服务器。
当我使用 Appium 窗口手动启动 Appium 时,它启动成功:
但是当我经常自动运行它时,我会遇到一个异常:
"An unhandled exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll
Additional information: Unexpected error. System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:4723"
这是启动 Appium Server 的 c# 代码:
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "C:/Program Files (x86)/Appium/node.exe";
startInfo.Arguments = @"""C:/Program Files (x86)/Appium/node.exe lib/server/main.js"" --address 127.0.0.1 --port 4723 --session-override --platform-name Android --platform-version 23 --automation-name Appium --log-no-color";
process.StartInfo = startInfo;
process.Start();
capabilities = new DesiredCapabilities();
capabilities.SetCapability("deviceName", "Samsung S6");
capabilities.SetCapability("platformName", "Android");
capabilities.SetCapability("platformVersion", "5.0.2");
capabilities.SetCapability(CapabilityType.BrowserName, "Chrome");
driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4723/wd/hub"), capabilities, TimeSpan.FromSeconds(30));
我阅读了这些问题,但对我没有帮助:
Appium iOS automation using C#/Visual Studio
No connection could be made because the target machine actively refused it 127.0.0.1:3446
为什么当我手动启动 Appium 时成功启动,但是当我以同样的方式启动它时却被拒绝?
最佳答案
这可能是因为服务器实例已经在端口 4723 上运行,尝试将端口号更改为 5555 或任何随机 4 位数字。
关于C# 以编程方式启动 Appium - 目标机器主动拒绝它,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39447906/