Skip to content

Commit

Permalink
Merge pull request #103 from FlaUI/ignore-not-matched-capabilities
Browse files Browse the repository at this point in the history
Ignore not matched capabilities
  • Loading branch information
aristotelos authored Oct 28, 2024
2 parents 1441dde + 56181e3 commit 6d0cbc6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
16 changes: 13 additions & 3 deletions src/FlaUI.WebDriver.UITests/SessionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,23 @@ public void NewSession_Timeouts_IsSupported()
}

[Test]
public void NewSession_NotSupportedCapability_Throws()
public void NewSession_NotSupportedAppiumCapability_Throws()
{
var driverOptions = FlaUIDriverOptions.TestApp();
driverOptions.AddAdditionalOption("appium:unknown", "value");

Assert.That(() => { using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions); },
Throws.TypeOf<InvalidOperationException>().With.Message.EqualTo("The following capabilities could not be matched: 'appium:unknown' (SessionNotCreated)"));
}

[Test]
public void NewSession_UnknownExtensionCapability_Ignores()
{
var driverOptions = FlaUIDriverOptions.TestApp();
driverOptions.AddAdditionalOption("unknown:unknown", "value");

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

[Test]
Expand Down
10 changes: 8 additions & 2 deletions src/FlaUI.WebDriver/Controllers/SessionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,16 @@ private bool TryMatchCapabilities(MergedCapabilities capabilities, [MaybeNullWhe
}

var notMatchedCapabilities = capabilities.Capabilities.Keys.Except(matchedCapabilities.Capabilities.Keys);
var notMatchedStandardOrAppiumCapabilities = notMatchedCapabilities.Where(c => !c.Contains(":") || c.StartsWith("appium:"));
if (notMatchedStandardOrAppiumCapabilities.Any())
{
// Do not ignore non-extension capabilities or appium capabilities
mismatchIndication = $"The following capabilities could not be matched: '{string.Join("', '", notMatchedStandardOrAppiumCapabilities)}'";
return false;
}
if (notMatchedCapabilities.Any())
{
mismatchIndication = $"The following capabilities could not be matched: '{string.Join("', '", notMatchedCapabilities)}'";
return false;
_logger.LogDebug("The following capabilities could not be matched and are ignored: '{NotMatchedCapabilities}'", string.Join("', '", notMatchedCapabilities));
}

mismatchIndication = null;
Expand Down

0 comments on commit 6d0cbc6

Please sign in to comment.