Hello Appium community,
I hope you’re doing well. I’m facing an issue while trying to start the Appium server programmatically in my C# project, and I’m seeking your assistance in resolving it.
Problem Description: I’m attempting to start the Appium server using the AppiumServiceBuilder
in C#, but I encounter the following error:
OpenQA.Selenium.Appium.Service.Exceptions.AppiumServerHasNotBeenStartedLocallyException
HResult=0x80131500
Message=The local appium server has not been started. The given Node.js executable: C:\Program Files\nodejs\node.exe Arguments: “C:\Users\mihail.amurov\AppData\Roaming\npm\node_modules\appium\build\lib\main.js” --port “4723” --address “127.0.0.1”.
Time 120000 ms for the service starting has been expired!
Environment Details:
- Operating System: Windows
- Node.js Version: v18.17.1
- NPM Version: 9.6.7
- Appium Version: 2.1.3
Troubleshooting Steps Taken:
- Checked Node.js and NPM versions, which meet the Appium requirements.
- Ensured that the specified paths to Node.js and the Appium main script are correct.
- Verified that there are no port conflicts on port 4723.
Additional Information:
- I’m running my code from [Your Development Environment].
- The Appium server starts successfully when launched manually:
- Manual Appium Command:
- I attempted to start the Appium server manually using the Appium command (
appium
).
Buthttp://127.0.0.1:4723/status
returns{ "value": { "ready": true, "message": "The server is ready to accept new connections", "build": { "version": "2.1.3" } } }}
And I encountered issues connecting to it after using my code (example at the bottom of this topic).
OpenQA.Selenium.WebDriverException HResult=0x80131500 Message=An unknown server-side error occurred while processing the command. Original error: WinAppDriver server is not listening within 10000ms timeout. Make sure it could be started manually Source=WebDriver StackTrace: at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary
2 parameters)
at OpenQA.Selenium.Appium.AppiumDriver1.Execute(String driverCommandToExecute, Dictionary
2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver…ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
at OpenQA.Selenium.Appium.AppiumDriver1..ctor(Uri remoteAddress, ICapabilities appiumOptions) at OpenQA.Selenium.Appium.Windows.WindowsDriver
1…ctor(Uri remoteAddress, AppiumOptions AppiumOptions)
at RunNotePad.Program.Main(String args) in C:\Users\mihail.amurov\source\repos\RunNotePad\RunNotePad\Program.cs:line 30
`
POST requests to the server fail with status code 500.
Session in the Appium Inspector cannot be started:
- Manual WAD (.exe) Execution:
- I tried to start the Appium server by manually executing the WAD (
WinAppDriver.exe
), but I faced similar connectivity issues.
- Successful Manual Start Command:
- Interestingly, the Appium server starts successfully using the following command:
WinAppDriver.exe 4723
My code is successfully connected and executed, but the GEThttp://127.0.0.1:4723/status
returns{ "status": 13, "value": { "error": "unknown error", "message": "An unknown error occurred in the remote end while processing the command." } }
Session in the Appium Inspector cannot be started:
My code (lesson part):
AppiumServerLauncher.cs:
`using OpenQA.Selenium.Appium.Service;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RunNotePad.Utils
{
internal class AppiumServerLauncher
{
private AppiumLocalService appiumServer;
public AppiumServerLauncher()
{
appiumServer = new AppiumServiceBuilder()
.WithIPAddress("127.0.0.1")
.UsingPort(4723)
.UsingDriverExecutable(new FileInfo(@"C:\Program Files\nodejs\node.exe"))
.WithAppiumJS(new FileInfo(@"C:\Users\mihail.amurov\AppData\Roaming\npm\node_modules\appium\build\lib\main.js"))
.WithStartUpTimeOut(TimeSpan.FromMinutes(3))
.Build();
}
public void Start()
{
appiumServer.Start();
}
public void Close()
{
if (appiumServer != null && appiumServer.IsRunning)
{
appiumServer.Dispose();
}
}
}
}
Program.cs:
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Enums;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Support.UI;
using RunNotePad.Utils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace RunNotePad
{
internal class Program
{
static void Main(string[] args)
{
var server = new AppiumServerLauncher();
server.Start();
WindowsDriver<WindowsElement> notepadSession;
AppiumOptions desiredCapabilities = new AppiumOptions();
desiredCapabilities.AddAdditionalCapability("appium:automationName", "windows");
desiredCapabilities.AddAdditionalCapability("app", @"C:\Windows\System32\notepad.exe");
desiredCapabilities.AddAdditionalCapability(MobileCapabilityType.PlatformName, "Windows");
desiredCapabilities.AddAdditionalCapability(MobileCapabilityType.DeviceName, "WindowsPC");
notepadSession = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), desiredCapabilities);
if (notepadSession == null ) {
Console.WriteLine("App not started");
return;
}
Console.WriteLine($"Application title: {notepadSession.Title}");
notepadSession.Manage().Window.Maximize();
notepadSession.FindElement(By.Name("Text Editor")).SendKeys("New Test \n");
notepadSession.FindElement(By.Name("Text Editor")).SendKeys(DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"));
notepadSession.FindElement(By.Name("File")).Click();
notepadSession.FindElement(MobileBy.AccessibilityId("4")).Click();
notepadSession.Quit();
server.Close();
}
}
}
`
I kindly request your help in diagnosing and resolving this issue. If you have encountered a similar problem or have insights into possible solutions, your guidance would be greatly appreciated.
Thank you for your time and assistance.
Best regards, Mihail.
UPD:
Log file contains following lines:
2023-09-23 13:10:15:875 [Appium] Welcome to Appium v2.1.3
2023-09-23 13:10:15:878 [Appium] Non-default server args:
2023-09-23 13:10:15:879 [Appium] { address: ‘127.0.0.1’ }
2023-09-23 13:10:15:880 [Appium] Attempting to load driver windows…
2023-09-23 13:10:15:883 [Appium] Requiring driver at C:\Users\mihail.amurov.appium\node_modules\appium-windows-driver
2023-09-23 13:10:16:091 [Appium] Appium REST http interface listener started on http://127.0.0.1:4723
2023-09-23 13:10:16:091 [Appium] Available drivers:
2023-09-23 13:10:16:091 [Appium] - [email protected] (automationName ‘Windows’)
2023-09-23 13:10:16:092 [Appium] No plugins have been installed. Use the “appium plugin” command to install the one(s) you want to use.
2023-09-23 13:10:16:253 [HTTP] → GET /wd/hub/status
2023-09-23 13:10:16:253 [HTTP] {}
2023-09-23 13:10:16:260 [HTTP] No route found for /wd/hub/status
2023-09-23 13:10:16:264 [HTTP] ← GET /wd/hub/status 404 9 ms - 211
Why is /wd/hub/ path called when the the appium documentation stands on the following:
With Appium 1.x, the server would accept commands by default on http://localhost:4723/wd/hub. The /wd/hub base path was a legacy convention from the days of migrating from Selenium 1 to Selenium 2, and is no longer relevant. As such the default base path for the server is now /.