microsoft / WinAppDriver

Windows Application Driver
MIT License
3.6k stars 1.39k forks source link

Issues with WAS and clickOnce application (C# and Python) #1444

Closed adamsjoe closed 3 years ago

adamsjoe commented 3 years ago

I'm looking to do some automation on a clickOnce application. When the application launches, it shows a dialog with yes/no buttons - before going to the main application.

I am able to launch the application and get the popup - but then get an error:

Failed to locate opened application window with appId: < path to the appref-ms > and processId yyyy

I have confirmed (using inspect.exe) that the procesId for the popup is not the one showing up in the error message. The appId is also the full path to the appref-ms file (which does seem odd, but the application does launch, so maybe that is ok..) Also seeing an HTTP 500 error appearing on the WAD output no matter which language I use.

I can't see the way around this.

I'll include both my Pythn and C# to see if anyone has any insight?

Currently using 1.2.1 from the releases page of WAP.

Python code:

import unittest
from appium import webdriver

class TestStuff(unittest.TestCase):

    @classmethod

    def setUpClass(self):
        #set up appium
        desired_caps = {}
        desired_caps["app"] = r"<path to .appref-ms>"
        self.driver = webdriver.Remote(command_executor='http://127.0.0.1:4723',desired_capabilities= desired_caps)            

    @classmethod
    def tearDownClass(self):
        self.driver.quit()

    def test_initialize(self):
        self.driver.find_element_by_name("No").click()

if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(TestStuff)
    unittest.TextTestRunner(verbosity=2).run(suite)

C# code:

using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium;
using System;
using System.Threading;

namespace WAPTest
{
    public class WAPSession
    {
        protected const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723";
        private const string theApp = @"path goes here.appref-ms";

        protected static WindowsDriver<WindowsElement> session;       

        public static void Setup(TestContext context)
        {
            if (session == null)
            {
                DesiredCapabilities appCapabilities = new DesiredCapabilities();
                appCapabilities.SetCapability("app", theApp);
                appCapabilities.SetCapability("deviceName", "WindowsPC");
                session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);

                Assert.IsNotNull(session);

            }
        }

        public static void TearDown()
        {
            // Close the application and delete the session
            if (session != null)
            {
                session.Close();

                session.Quit();
                session = null;
            }
        }

    }
}
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using System.Threading;
using System;

namespace WAPTest
{
    [TestClass]
    public class Abracadabra : WAPSession
    {
        [TestMethod]
        public void Tada()
        {
            Thread.Sleep(TimeSpan.FromSeconds(2));
        }

        [ClassInitialize]
        public static void ClassInitialize(TestContext context)
        {
            Setup(context);
        }

        [ClassCleanup]
        public static void ClassCleanup()
        {
            TearDown();
        }
    }
}
adamsjoe commented 3 years ago

Ok this is a bit of an easy question.
Does WinAppDriver support ClickOnce applications?

adamsjoe commented 3 years ago

I have found a way round this - python only, but I suspect C# will be the same. After a bit of investigation, I tried to launch the application under test the same way as each language does, that is using the full path and I got errors as I did with winappdriver. Launching the app from within the directory worked fine.

With this, I found that adding a working directory makes this work.