Skip to content

Commit 42d59ed

Browse files
committed
Require appium:automationName
Add required capability appium:automationName equal to FlaUI.
1 parent 3b03baa commit 42d59ed

4 files changed

Lines changed: 35 additions & 9 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The following capabilities are supported:
2424
| Capability Name | Description | Example value |
2525
| ---------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
2626
| platformName | Must be set to `windows` (case-insensitive). | `windows` |
27+
| appium:automationName | Must be set to `FlaUI` (case-insensitive). | `FlaUI` |
2728
| 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` |
2829
| appium:appArguments | Application arguments string, for example `/?`. | |
2930
| 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\` |

src/FlaUI.WebDriver.UITests/SessionTests.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,30 @@ public void NewSession_PlatformNameMissing_ReturnsError()
1616

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

19-
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)"));
19+
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)"));
20+
}
21+
22+
[Test]
23+
public void NewSession_AutomationNameMissing_ReturnsError()
24+
{
25+
var emptyOptions = FlaUIDriverOptions.Empty();
26+
emptyOptions.AddAdditionalOption("appium:platformName", "windows");
27+
28+
var newSession = () => new RemoteWebDriver(WebDriverFixture.WebDriverUrl, emptyOptions);
29+
30+
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)"));
2031
}
2132

2233
[Test]
2334
public void NewSession_AllAppCapabilitiesMissing_ReturnsError()
2435
{
2536
var emptyOptions = FlaUIDriverOptions.Empty();
2637
emptyOptions.AddAdditionalOption("appium:platformName", "windows");
38+
emptyOptions.AddAdditionalOption("appium:automationName", "windows");
39+
2740
var newSession = () => new RemoteWebDriver(WebDriverFixture.WebDriverUrl, emptyOptions);
2841

29-
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)"));
42+
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)"));
3043
}
3144

3245
[Test]
@@ -58,6 +71,7 @@ public void NewSession_AppNotAString_Throws(object value)
5871
{
5972
PlatformName = "Windows"
6073
};
74+
driverOptions.AddAdditionalOption("appium:automationName", "FlaUI");
6175
driverOptions.AddAdditionalOption("appium:app", value);
6276

6377
Assert.That(() => new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions),
@@ -83,7 +97,7 @@ public void NewSession_NotSupportedCapability_Throws()
8397
driverOptions.AddAdditionalOption("unknown:unknown", "value");
8498

8599
Assert.That(() => new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions),
86-
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)"));
100+
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)"));
87101
}
88102

89103
[Test]
@@ -179,6 +193,7 @@ public void NewSession_AppTopLevelWindowTitleMatchNotAString_Throws(object value
179193
{
180194
PlatformName = "Windows"
181195
};
196+
driverOptions.AddAdditionalOption("appium:automationName", "FlaUI");
182197
driverOptions.AddAdditionalOption("appium:appTopLevelWindowTitleMatch", value);
183198

184199
Assert.That(() => new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions),
@@ -188,11 +203,7 @@ public void NewSession_AppTopLevelWindowTitleMatchNotAString_Throws(object value
188203
[TestCase("(invalid")]
189204
public void NewSession_AppTopLevelWindowTitleMatchInvalidRegex_Throws(string value)
190205
{
191-
var driverOptions = new FlaUIDriverOptions()
192-
{
193-
PlatformName = "Windows"
194-
};
195-
driverOptions.AddAdditionalOption("appium:appTopLevelWindowTitleMatch", value);
206+
var driverOptions = FlaUIDriverOptions.AppTopLevelWindowTitleMatch(value);
196207

197208
Assert.That(() => new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions),
198209
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."));
@@ -217,6 +228,7 @@ public void NewSession_AppTopLevelWindowNotAString_ReturnsError(object value)
217228
{
218229
PlatformName = "Windows"
219230
};
231+
driverOptions.AddAdditionalOption("appium:automationName", "FlaUI");
220232
driverOptions.AddAdditionalOption("appium:appTopLevelWindow", value);
221233

222234
Assert.That(() => new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions),

src/FlaUI.WebDriver.UITests/TestUtil/FlaUIDriverOptions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public static FlaUIDriverOptions App(string path)
2020
{
2121
PlatformName = "Windows"
2222
};
23+
options.AddAdditionalOption("appium:automationName", "FlaUI");
2324
options.AddAdditionalOption("appium:app", path);
2425
return options;
2526
}
@@ -30,6 +31,7 @@ public static DriverOptions AppTopLevelWindow(string windowHandle)
3031
{
3132
PlatformName = "Windows"
3233
};
34+
options.AddAdditionalOption("appium:automationName", "FlaUI");
3335
options.AddAdditionalOption("appium:appTopLevelWindow", windowHandle);
3436
return options;
3537
}
@@ -40,6 +42,7 @@ public static DriverOptions AppTopLevelWindowTitleMatch(string match)
4042
{
4143
PlatformName = "Windows"
4244
};
45+
options.AddAdditionalOption("appium:automationName", "FlaUI");
4346
options.AddAdditionalOption("appium:appTopLevelWindowTitleMatch", match);
4447
return options;
4548
}

src/FlaUI.WebDriver/Controllers/SessionController.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public async Task<ActionResult> CreateNewSession([FromBody] CreateSessionRequest
4242
return WebDriverResult.Error(new ErrorResponse
4343
{
4444
ErrorCode = "session not created",
45-
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"
45+
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"
4646
});
4747
}
4848
if (TryGetStringCapability(capabilities, "appium:app", out var appPath))
@@ -117,6 +117,16 @@ private bool IsMatchingCapabilitySet(IDictionary<string, JsonElement> capabiliti
117117
return false;
118118
}
119119

120+
if (TryGetStringCapability(capabilities, "appium:automationName", out var automationName)
121+
&& automationName.ToLowerInvariant() == "flaui")
122+
{
123+
matchedCapabilities.Add("appium:automationName", capabilities["appium:automationName"]);
124+
}
125+
else
126+
{
127+
return false;
128+
}
129+
120130
if (TryGetStringCapability(capabilities, "appium:app", out var appPath))
121131
{
122132
matchedCapabilities.Add("appium:app", capabilities["appium:app"]);

0 commit comments

Comments
 (0)