From e27bff564866c3efa92ad1fc478e7e2c26aacec6 Mon Sep 17 00:00:00 2001 From: aristotelos Date: Wed, 17 Apr 2024 08:50:19 +0200 Subject: [PATCH] Add Windows Store app support Enable launching Windows Store app using the `appium:app`` capability equal to `!App`. --- README.md | 14 +++++++------- src/FlaUI.WebDriver.UITests/SessionTests.cs | 11 +++++++++++ .../Controllers/SessionController.cs | 15 +++++++++++---- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index d016d2c..68efc88 100644 --- a/README.md +++ b/README.md @@ -21,13 +21,13 @@ FlaUI.WebDriver is a [W3C WebDriver2](https://www.w3.org/TR/webdriver2/) impleme The following capabilities are supported: -| Capability Name | Description | Example value | -| ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- | -| platformName | Must be set to `windows` (case-insensitive). | `windows` | -| appium:app | The path to the application. It is also possible to set app to `Root`. In such case the session will be invoked without any explicit target application. Either this capability, `appTopLevelWindow` or `appTopLevelWindowTitleMatch` must be provided on session startup. | `C:\Windows\System32\notepad.exe` | -| appium:appArguments | Application arguments string, for example `/?`. | -| appium:appTopLevelWindow | The hexadecimal handle of an existing application top level window to attach to, for example `0x12345` (should be of string type). Either this capability, `appTopLevelWindowTitleMatch` or `app` must be provided on session startup. | `0xC0B46` | -| appium:appTopLevelWindowTitleMatch | The title of an existing application top level window to attach to, for example `My App Window Title` (should be of string type). Either this capability, `appTopLevelWindow` or `app` must be provided on session startup. | `My App Window Title` or `My App Window Title - .*` | +| Capability Name | Description | Example value | +| ---------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- | +| platformName | Must be set to `windows` (case-insensitive). | `windows` | +| appium:app | The path to the application, or in case of an UWP app, `!App`. It is also possible to set app to `Root`. In such case the session will be invoked without any explicit target application. Either this capability, `appTopLevelWindow` or `appTopLevelWindowTitleMatch` must be provided on session startup. | `C:\Windows\System32\notepad.exe`, `Microsoft.WindowsCalculator_8wekyb3d8bbwe!App` | +| appium:appArguments | Application arguments string, for example `/?`. | | +| appium:appTopLevelWindow | The hexadecimal handle of an existing application top level window to attach to, for example `0x12345` (should be of string type). Either this capability, `appTopLevelWindowTitleMatch` or `app` must be provided on session startup. | `0xC0B46` | +| appium:appTopLevelWindowTitleMatch | The title of an existing application top level window to attach to, for example `My App Window Title` (should be of string type). Either this capability, `appTopLevelWindow` or `app` must be provided on session startup. | `My App Window Title` or `My App Window Title - .*` | ## Getting Started diff --git a/src/FlaUI.WebDriver.UITests/SessionTests.cs b/src/FlaUI.WebDriver.UITests/SessionTests.cs index b925a97..40c7501 100644 --- a/src/FlaUI.WebDriver.UITests/SessionTests.cs +++ b/src/FlaUI.WebDriver.UITests/SessionTests.cs @@ -102,6 +102,17 @@ public void NewSession_MultipleMatchingAppTopLevelWindowTitleMatch_ReturnsError( Assert.That(newSession, Throws.TypeOf().With.Message.EqualTo("Found multiple (2) processes with main window title matching 'FlaUI WPF Test App'")); } + [Test] + public void NewSession_UwpApp_IsSupported() + { + var driverOptions = FlaUIDriverOptions.App("Microsoft.WindowsCalculator_8wekyb3d8bbwe!App"); + using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions); + + var title = driver.Title; + + Assert.That(title, Is.EqualTo("Calculator")); + } + [Test] public void NewSession_AppTopLevelWindowTitleMatchNotFound_ReturnsError() { diff --git a/src/FlaUI.WebDriver/Controllers/SessionController.cs b/src/FlaUI.WebDriver/Controllers/SessionController.cs index 3645ab0..a0bc3a4 100644 --- a/src/FlaUI.WebDriver/Controllers/SessionController.cs +++ b/src/FlaUI.WebDriver/Controllers/SessionController.cs @@ -48,13 +48,20 @@ public async Task CreateNewSession([FromBody] CreateSessionRequest { app = null; } - else - { + else + { capabilities.TryGetValue("appium:appArguments", out var appArguments); try { - var processStartInfo = new ProcessStartInfo(appPath, appArguments ?? ""); - app = Core.Application.Launch(processStartInfo); + if (appPath.EndsWith("!App")) + { + app = Core.Application.LaunchStoreApp(appPath, appArguments); + } + else + { + var processStartInfo = new ProcessStartInfo(appPath, appArguments ?? ""); + app = Core.Application.Launch(processStartInfo); + } } catch(Exception e) {