I'm trying to automate a Windows application using Appium in C# with Visual Studio. Here's my code:
using NUnit.Framework;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;
using System;
namespace automated_test
{
public class Tests
{
private const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723";
private const string YourApplicationId = "OSSAP2";
protected WindowsDriver<WindowsElement>? session;
[SetUp]
public void Setup()
{
if (session == null)
{
AppiumOptions appiumOptions = new AppiumOptions();
appiumOptions.AddAdditionalCapability("app", @"C:\OSS2\OSSAPUpdate.exe");
appiumOptions.AddAdditionalCapability("deviceName", "WindowsPC");
try
{
session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appiumOptions);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);秒
}
}
[TearDown]
public void TearDown()
{
if (session != null)
{
session.Quit();
session = null;
}
}
[Test]
public void LoginTest()
{
var loginField = session.FindElementByAccessibilityId("txt_LoginID");
loginField.SendKeys("5165");
}
}
}
The code compiles and runs without errors, and I also have WinAppDriver running at http://127.0.0.1:4723. However, the application I'm trying to automate, which is located at C:\OSS2\OSSAPUpdate.exe, is not launching.
Here are some things that I have verified:
The path to OSSAPUpdate.exe is correct. My machine is in Developer Mode. WinAppDriver is running with administrative privileges. The versions of Visual Studio, Appium, and Selenium are all up-to-date and compatible. Despite these, I'm still unable to launch the application. I would appreciate any help or suggestions on what else I could try.