Skip to content

Commit 6d0cbc6

Browse files
authored
Merge pull request #103 from FlaUI/ignore-not-matched-capabilities
Ignore not matched capabilities
2 parents 1441dde + 56181e3 commit 6d0cbc6

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/FlaUI.WebDriver.UITests/SessionTests.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,23 @@ public void NewSession_Timeouts_IsSupported()
106106
}
107107

108108
[Test]
109-
public void NewSession_NotSupportedCapability_Throws()
109+
public void NewSession_NotSupportedAppiumCapability_Throws()
110+
{
111+
var driverOptions = FlaUIDriverOptions.TestApp();
112+
driverOptions.AddAdditionalOption("appium:unknown", "value");
113+
114+
Assert.That(() => { using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions); },
115+
Throws.TypeOf<InvalidOperationException>().With.Message.EqualTo("The following capabilities could not be matched: 'appium:unknown' (SessionNotCreated)"));
116+
}
117+
118+
[Test]
119+
public void NewSession_UnknownExtensionCapability_Ignores()
110120
{
111121
var driverOptions = FlaUIDriverOptions.TestApp();
112122
driverOptions.AddAdditionalOption("unknown:unknown", "value");
113123

114-
Assert.That(() => new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions),
115-
Throws.TypeOf<InvalidOperationException>().With.Message.EqualTo("The following capabilities could not be matched: 'unknown:unknown' (SessionNotCreated)"));
124+
Assert.That(() => { using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions); },
125+
Throws.Nothing);
116126
}
117127

118128
[Test]

src/FlaUI.WebDriver/Controllers/SessionController.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,16 @@ private bool TryMatchCapabilities(MergedCapabilities capabilities, [MaybeNullWhe
200200
}
201201

202202
var notMatchedCapabilities = capabilities.Capabilities.Keys.Except(matchedCapabilities.Capabilities.Keys);
203+
var notMatchedStandardOrAppiumCapabilities = notMatchedCapabilities.Where(c => !c.Contains(":") || c.StartsWith("appium:"));
204+
if (notMatchedStandardOrAppiumCapabilities.Any())
205+
{
206+
// Do not ignore non-extension capabilities or appium capabilities
207+
mismatchIndication = $"The following capabilities could not be matched: '{string.Join("', '", notMatchedStandardOrAppiumCapabilities)}'";
208+
return false;
209+
}
203210
if (notMatchedCapabilities.Any())
204211
{
205-
mismatchIndication = $"The following capabilities could not be matched: '{string.Join("', '", notMatchedCapabilities)}'";
206-
return false;
212+
_logger.LogDebug("The following capabilities could not be matched and are ignored: '{NotMatchedCapabilities}'", string.Join("', '", notMatchedCapabilities));
207213
}
208214

209215
mismatchIndication = null;

0 commit comments

Comments
 (0)