1

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.

pony1229
  • 11
  • 2
  • Are you getting an exception? If so, please [edit] your question to include the full exception message and stack trace, and indicate which line of code is throwing the exception. – Greg Burghardt Aug 02 '23 at 18:48
  • Are you sure the application isn't launching in the background? The line `loginField.SendKeys("5165");` will throw an exception if it cannot type in the text field. If the test executes and passes, perhaps things are working, but working so quickly you cannot see it. Try adding `System.Threading.Thread.Sleep(10_000);` as the last line of your test. It should pause the test execution. – Greg Burghardt Aug 02 '23 at 19:47

0 Answers0