microsoft / WinAppDriver

Windows Application Driver
MIT License
3.69k stars 1.4k forks source link

WinAppDriver not finding UWP app by ID even though the app is installed #835

Open nathan-alden-hp opened 5 years ago

nathan-alden-hp commented 5 years ago

Proof that my UWP app is installed (Visual Studio installs it when I run it in Debug configuration):

PS > Get-AppxPackage -AllUsers | ?{ $_.Name.Contains("52a95998-8cfa-43d7-96c9-06fc6d8ad1c5") }

Name                   : 52a95998-8cfa-43d7-96c9-06fc6d8ad1c5
Publisher              : CN=***
Architecture           : X64
ResourceId             :
Version                : 0.0.0.0
PackageFullName        : 52a95998-8cfa-43d7-96c9-06fc6d8ad1c5_0.0.0.0_x64__x38zh4nq6sjk4
InstallLocation        : C:\***\src\XamlUwpApp\bin\x64\Debug\AppX
IsFramework            : False
PackageFamilyName      : 52a95998-8cfa-43d7-96c9-06fc6d8ad1c5_x38zh4nq6sjk4
PublisherId            : x38zh4nq6sjk4
PackageUserInformation : {*** [***\***]: Installed}
IsResourcePackage      : False
IsBundle               : False
IsDevelopmentMode      : True
NonRemovable           : False
Dependencies           : {Microsoft.VCLibs.140.00.Debug_14.0.27508.1_x64__8wekyb3d8bbwe,
                         Microsoft.NET.CoreRuntime.1.1_1.1.27004.0_x64__8wekyb3d8bbwe}
IsPartiallyStaged      : False
SignatureKind          : None
Status                 : Ok

XAML:

<Button cm:Message.Attach="GenerateRandomEquation" Margin="10,10,10,0" Content="Generate" HorizontalAlignment="Center" AutomationProperties.AutomationId="UIGenerateRandomEquationButton" />

Test class:

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

namespace XamlUwpApp.FunctionalTests
{
    [TestClass]
    public class UnitTest1
    {
        public TestContext TestContext { get; set; }

        [TestMethod]
        public void TestMethod1()
        {
            var capabilities = new DesiredCapabilities();

            capabilities.SetCapability("app", "52a95998-8cfa-43d7-96c9-06fc6d8ad1c5_0.0.0.0_x64__x38zh4nq6sjk4!app");

            var windowsDriver = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723/"), capabilities);

            windowsDriver.FindElementByAccessibilityId("UIGenerateRandomEquationButton").Click();
        }
    }
}

WinAppDriver response:

==========================================
POST /session HTTP/1.1
Accept: application/json, image/png
Connection: Keep-Alive
Content-Length: 126
Content-Type: application/json;charset=utf-8
Host: 127.0.0.1:4723

{"desiredCapabilities":{"app":"52a95998-8cfa-43d7-96c9-06fc6d8ad1c5_0.0.0.0_x64__x38zh4nq6sjk4!app","platformName":"Windows"}}
HTTP/1.1 400 Bad Request
Content-Length: 110
Content-Type: application/json

{"status":100,"value":{"error":"invalid argument","message":"Value does not fall within the expected range."}}
hassanuz commented 5 years ago

Hi @nathan-alden-hp

Can you run get-StartApps via powershell and confirm the app name?

nathan-alden-hp commented 5 years ago
PS > Get-StartApps | ?{ $_.Name.Contains("XamlUwpApp") }

Name       AppID
----       -----
XamlUwpApp 52a95998-8cfa-43d7-96c9-06fc6d8ad1c5_x38zh4nq6sjk4!App
nathan-alden-hp commented 5 years ago

FWIW, I updated the Appium.WebDriver package to 4.0.0. I got some obsolete warnings, so I updated my test code to this:

var options = new AppiumOptions();

options.AddAdditionalCapability("app", "52a95998-8cfa-43d7-96c9-06fc6d8ad1c5_0.0.0.0_x64__x38zh4nq6sjk4!app");

var windowsDriver = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723/"), options);

windowsDriver.FindElementByAccessibilityId("UIGenerateRandomEquationButton").Click();

However, the driver still reports the same error.

Also note that this app is being side-loaded by using the Add-AppDevPackage.ps1 script generated by the Store app package build in Visual Studio. The self-signed certificate used to sign the bundle was added to the Trusted Root Certification Authorities store by the script.

hassanuz commented 5 years ago

Hi @nathan-alden-hp

Try passing in just the following for the AppID - since it looks like there is a variation what is being reported.

52a95998-8cfa-43d7-96c9-06fc6d8ad1c5_x38zh4nq6sjk4!App

If that doesn't work, then I'd recommend using a Desktop Session.

gauravrsys commented 5 years ago

Hello @hassanuz,

I am facing the similar issue. Not able to launch my app through App ID.

Could you please suggest me the fix?

Thanks Gaurav Agnihotri