diff --git a/README.md b/README.md index e834017..e50f645 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ The following capabilities are supported: | Capability Name | Description | Example value | | ---------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- | | platformName | Must be set to `windows` (case-insensitive). | `windows` | +| appium:automationName | Must be set to `FlaUI` (case-insensitive). | `FlaUI` | | 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:appWorkingDir | Full path to the folder, which is going to be set as the working dir for the application under test. This is only applicable for classic apps. When this is used the `appium:app` may contain a relative file path. | `C:\MyApp\` | diff --git a/src/FlaUI.WebDriver.UITests/SessionTests.cs b/src/FlaUI.WebDriver.UITests/SessionTests.cs index 76e66c5..df6ac39 100644 --- a/src/FlaUI.WebDriver.UITests/SessionTests.cs +++ b/src/FlaUI.WebDriver.UITests/SessionTests.cs @@ -16,7 +16,18 @@ public void NewSession_PlatformNameMissing_ReturnsError() var newSession = () => new RemoteWebDriver(WebDriverFixture.WebDriverUrl, emptyOptions); - Assert.That(newSession, Throws.TypeOf().With.Message.EqualTo("Required capabilities did not match. Capability `platformName` with value `windows` is required, and one of appium:app, appium:appTopLevelWindow or appium:appTopLevelWindowTitleMatch must be passed as a capability (SessionNotCreated)")); + Assert.That(newSession, Throws.TypeOf().With.Message.EqualTo("Required capabilities did not match. Capability `platformName` with value `windows` is required, capability 'appium:automationName' with value `FlaUI` is required, and one of appium:app, appium:appTopLevelWindow or appium:appTopLevelWindowTitleMatch must be passed as a capability (SessionNotCreated)")); + } + + [Test] + public void NewSession_AutomationNameMissing_ReturnsError() + { + var emptyOptions = FlaUIDriverOptions.Empty(); + emptyOptions.AddAdditionalOption("appium:platformName", "windows"); + + var newSession = () => new RemoteWebDriver(WebDriverFixture.WebDriverUrl, emptyOptions); + + Assert.That(newSession, Throws.TypeOf().With.Message.EqualTo("Required capabilities did not match. Capability `platformName` with value `windows` is required, capability 'appium:automationName' with value `FlaUI` is required, and one of appium:app, appium:appTopLevelWindow or appium:appTopLevelWindowTitleMatch must be passed as a capability (SessionNotCreated)")); } [Test] @@ -24,9 +35,11 @@ public void NewSession_AllAppCapabilitiesMissing_ReturnsError() { var emptyOptions = FlaUIDriverOptions.Empty(); emptyOptions.AddAdditionalOption("appium:platformName", "windows"); + emptyOptions.AddAdditionalOption("appium:automationName", "windows"); + var newSession = () => new RemoteWebDriver(WebDriverFixture.WebDriverUrl, emptyOptions); - Assert.That(newSession, Throws.TypeOf().With.Message.EqualTo("Required capabilities did not match. Capability `platformName` with value `windows` is required, and one of appium:app, appium:appTopLevelWindow or appium:appTopLevelWindowTitleMatch must be passed as a capability (SessionNotCreated)")); + Assert.That(newSession, Throws.TypeOf().With.Message.EqualTo("Required capabilities did not match. Capability `platformName` with value `windows` is required, capability 'appium:automationName' with value `FlaUI` is required, and one of appium:app, appium:appTopLevelWindow or appium:appTopLevelWindowTitleMatch must be passed as a capability (SessionNotCreated)")); } [Test] @@ -58,6 +71,7 @@ public void NewSession_AppNotAString_Throws(object value) { PlatformName = "Windows" }; + driverOptions.AddAdditionalOption("appium:automationName", "FlaUI"); driverOptions.AddAdditionalOption("appium:app", value); Assert.That(() => new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions), @@ -83,7 +97,7 @@ public void NewSession_NotSupportedCapability_Throws() driverOptions.AddAdditionalOption("unknown:unknown", "value"); Assert.That(() => new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions), - Throws.TypeOf().With.Message.EqualTo("Required capabilities did not match. Capability `platformName` with value `windows` is required, and one of appium:app, appium:appTopLevelWindow or appium:appTopLevelWindowTitleMatch must be passed as a capability (SessionNotCreated)")); + Throws.TypeOf().With.Message.EqualTo("Required capabilities did not match. Capability `platformName` with value `windows` is required, capability 'appium:automationName' with value `FlaUI` is required, and one of appium:app, appium:appTopLevelWindow or appium:appTopLevelWindowTitleMatch must be passed as a capability (SessionNotCreated)")); } [Test] @@ -179,6 +193,7 @@ public void NewSession_AppTopLevelWindowTitleMatchNotAString_Throws(object value { PlatformName = "Windows" }; + driverOptions.AddAdditionalOption("appium:automationName", "FlaUI"); driverOptions.AddAdditionalOption("appium:appTopLevelWindowTitleMatch", value); Assert.That(() => new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions), @@ -188,11 +203,7 @@ public void NewSession_AppTopLevelWindowTitleMatchNotAString_Throws(object value [TestCase("(invalid")] public void NewSession_AppTopLevelWindowTitleMatchInvalidRegex_Throws(string value) { - var driverOptions = new FlaUIDriverOptions() - { - PlatformName = "Windows" - }; - driverOptions.AddAdditionalOption("appium:appTopLevelWindowTitleMatch", value); + var driverOptions = FlaUIDriverOptions.AppTopLevelWindowTitleMatch(value); Assert.That(() => new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions), Throws.TypeOf().With.Message.EqualTo("Capability appium:appTopLevelWindowTitleMatch '(invalid' is not a valid regular expression: Invalid pattern '(invalid' at offset 8. Not enough )'s.")); @@ -217,6 +228,7 @@ public void NewSession_AppTopLevelWindowNotAString_ReturnsError(object value) { PlatformName = "Windows" }; + driverOptions.AddAdditionalOption("appium:automationName", "FlaUI"); driverOptions.AddAdditionalOption("appium:appTopLevelWindow", value); Assert.That(() => new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions), diff --git a/src/FlaUI.WebDriver.UITests/TestUtil/FlaUIDriverOptions.cs b/src/FlaUI.WebDriver.UITests/TestUtil/FlaUIDriverOptions.cs index e4421bc..ac1fb82 100644 --- a/src/FlaUI.WebDriver.UITests/TestUtil/FlaUIDriverOptions.cs +++ b/src/FlaUI.WebDriver.UITests/TestUtil/FlaUIDriverOptions.cs @@ -20,6 +20,7 @@ public static FlaUIDriverOptions App(string path) { PlatformName = "Windows" }; + options.AddAdditionalOption("appium:automationName", "FlaUI"); options.AddAdditionalOption("appium:app", path); return options; } @@ -30,6 +31,7 @@ public static DriverOptions AppTopLevelWindow(string windowHandle) { PlatformName = "Windows" }; + options.AddAdditionalOption("appium:automationName", "FlaUI"); options.AddAdditionalOption("appium:appTopLevelWindow", windowHandle); return options; } @@ -40,6 +42,7 @@ public static DriverOptions AppTopLevelWindowTitleMatch(string match) { PlatformName = "Windows" }; + options.AddAdditionalOption("appium:automationName", "FlaUI"); options.AddAdditionalOption("appium:appTopLevelWindowTitleMatch", match); return options; } diff --git a/src/FlaUI.WebDriver/Controllers/SessionController.cs b/src/FlaUI.WebDriver/Controllers/SessionController.cs index 6cef097..b1c0d2e 100644 --- a/src/FlaUI.WebDriver/Controllers/SessionController.cs +++ b/src/FlaUI.WebDriver/Controllers/SessionController.cs @@ -42,7 +42,7 @@ public async Task CreateNewSession([FromBody] CreateSessionRequest return WebDriverResult.Error(new ErrorResponse { ErrorCode = "session not created", - Message = "Required capabilities did not match. Capability `platformName` with value `windows` is required, and one of appium:app, appium:appTopLevelWindow or appium:appTopLevelWindowTitleMatch must be passed as a capability" + Message = "Required capabilities did not match. Capability `platformName` with value `windows` is required, capability 'appium:automationName' with value `FlaUI` is required, and one of appium:app, appium:appTopLevelWindow or appium:appTopLevelWindowTitleMatch must be passed as a capability" }); } if (TryGetStringCapability(capabilities, "appium:app", out var appPath)) @@ -117,6 +117,16 @@ private bool IsMatchingCapabilitySet(IDictionary capabiliti return false; } + if (TryGetStringCapability(capabilities, "appium:automationName", out var automationName) + && automationName.ToLowerInvariant() == "flaui") + { + matchedCapabilities.Add("appium:automationName", capabilities["appium:automationName"]); + } + else + { + return false; + } + if (TryGetStringCapability(capabilities, "appium:app", out var appPath)) { matchedCapabilities.Add("appium:app", capabilities["appium:app"]);