Skip to content

Commit

Permalink
Require appium:automationName
Browse files Browse the repository at this point in the history
Add required capability appium:automationName equal to FlaUI.
  • Loading branch information
aristotelos committed Apr 23, 2024
1 parent 3b03baa commit 42d59ed
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, `<package family name>!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\` |
Expand Down
28 changes: 20 additions & 8 deletions src/FlaUI.WebDriver.UITests/SessionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,30 @@ public void NewSession_PlatformNameMissing_ReturnsError()

var newSession = () => new RemoteWebDriver(WebDriverFixture.WebDriverUrl, emptyOptions);

Assert.That(newSession, Throws.TypeOf<InvalidOperationException>().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<InvalidOperationException>().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<InvalidOperationException>().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_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<InvalidOperationException>().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<InvalidOperationException>().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]
Expand Down Expand Up @@ -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),
Expand All @@ -83,7 +97,7 @@ public void NewSession_NotSupportedCapability_Throws()
driverOptions.AddAdditionalOption("unknown:unknown", "value");

Assert.That(() => new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions),
Throws.TypeOf<InvalidOperationException>().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<InvalidOperationException>().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]
Expand Down Expand Up @@ -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),
Expand All @@ -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<WebDriverArgumentException>().With.Message.EqualTo("Capability appium:appTopLevelWindowTitleMatch '(invalid' is not a valid regular expression: Invalid pattern '(invalid' at offset 8. Not enough )'s."));
Expand All @@ -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),
Expand Down
3 changes: 3 additions & 0 deletions src/FlaUI.WebDriver.UITests/TestUtil/FlaUIDriverOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static FlaUIDriverOptions App(string path)
{
PlatformName = "Windows"
};
options.AddAdditionalOption("appium:automationName", "FlaUI");
options.AddAdditionalOption("appium:app", path);
return options;
}
Expand All @@ -30,6 +31,7 @@ public static DriverOptions AppTopLevelWindow(string windowHandle)
{
PlatformName = "Windows"
};
options.AddAdditionalOption("appium:automationName", "FlaUI");
options.AddAdditionalOption("appium:appTopLevelWindow", windowHandle);
return options;
}
Expand All @@ -40,6 +42,7 @@ public static DriverOptions AppTopLevelWindowTitleMatch(string match)
{
PlatformName = "Windows"
};
options.AddAdditionalOption("appium:automationName", "FlaUI");
options.AddAdditionalOption("appium:appTopLevelWindowTitleMatch", match);
return options;
}
Expand Down
12 changes: 11 additions & 1 deletion src/FlaUI.WebDriver/Controllers/SessionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public async Task<ActionResult> 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))
Expand Down Expand Up @@ -117,6 +117,16 @@ private bool IsMatchingCapabilitySet(IDictionary<string, JsonElement> 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"]);
Expand Down

0 comments on commit 42d59ed

Please sign in to comment.