Search code examples
c#seleniumselenium-webdriverappiumappium-desktop

Appium set working directory of application session in C#


I am currently trying to run my application in Appium.

I have set the tests working directory to run where the application executable is and it is successfully launching the application however it fails to get any of the application settings that are within the directory of the executable file.

If I run the application directly it works fine.

What would be the best course of action? Here is what I have so far:

namespace MyApp.Tests.Appium.Tests
{
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using OpenQA.Selenium.Appium.Windows;
    using OpenQA.Selenium.Remote;
    using System;
    using System.IO;

    public class UITestBase : IDisposable
    {
        protected const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723";

        protected static WindowsDriver<WindowsElement> AppSession;

        protected UITestBase()
        {
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            var appUrl = Directory.GetCurrentDirectory() + "\\MyApp.exe";

            appCapabilities.SetCapability("app", appUrl);
            appCapabilities.SetCapability("deviceName", "WindowsPC");
            AppSession = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);
        }
    }
}

Solution

  • https://github.com/Microsoft/WinAppDriver

    Based off this you can set it via the code below:

    appCapabilities.SetCapability("appWorkingDir", Directory.GetCurrentDirectory());