Skip to content

Commit

Permalink
Merge pull request #22 from FlaUI/capabilities
Browse files Browse the repository at this point in the history
Capabilities
  • Loading branch information
aristotelos authored Apr 23, 2024
2 parents 8a250e5 + fc2ab29 commit 6cb32cb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class FlaUIDriverOptions : DriverOptions
{
PlatformName = "windows"
};
options.AddAdditionalOption("appium:automationName", "flaui");
options.AddAdditionalOption("appium:app", path);
return options;
}
Expand All @@ -79,6 +80,7 @@ import { remote } from 'webdriverio'
const driver = await remote({
capabilities: {
platformName: 'windows',
'appium:automationName': 'flaui'
'appium:app': 'C:\\YourApp.exe'
}
});
Expand Down
18 changes: 18 additions & 0 deletions src/FlaUI.WebDriver.UITests/SessionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using FlaUI.WebDriver.UITests.TestUtil;
using OpenQA.Selenium;
using System;
using System.Collections.Generic;

namespace FlaUI.WebDriver.UITests
{
Expand Down Expand Up @@ -90,6 +91,23 @@ public void NewSession_AppWorkingDir_IsSupported()
Assert.That(title, Is.EqualTo("FlaUI WPF Test App"));
}

[Test]
public void NewSession_Timeouts_IsSupported()
{
var driverOptions = FlaUIDriverOptions.TestApp();
driverOptions.AddAdditionalOption("timeouts", new Dictionary<string, int>()
{
["script"] = 10000,
["pageLoad"] = 50000,
["implicit"] = 3000
});
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);

Assert.That(driver.Manage().Timeouts().AsynchronousJavaScript, Is.EqualTo(TimeSpan.FromSeconds(10)));
Assert.That(driver.Manage().Timeouts().PageLoad, Is.EqualTo(TimeSpan.FromSeconds(50)));
Assert.That(driver.Manage().Timeouts().ImplicitWait, Is.EqualTo(TimeSpan.FromSeconds(3)));
}

[Test]
public void NewSession_NotSupportedCapability_Throws()
{
Expand Down
24 changes: 19 additions & 5 deletions src/FlaUI.WebDriver/Controllers/SessionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ public async Task<ActionResult> CreateNewSession([FromBody] CreateSessionRequest
{
session.NewCommandTimeout = TimeSpan.FromSeconds(newCommandTimeout);
}
if (capabilities.TryGetValue("timeouts", out var valueJson))
{
var timeoutsConfiguration = JsonSerializer.Deserialize<TimeoutsConfiguration>(valueJson);
if (timeoutsConfiguration == null)
{
throw WebDriverResponseException.InvalidArgument("Could not deserialize timeouts capability");
}
session.TimeoutsConfiguration = timeoutsConfiguration;
}
_sessionRepository.Add(session);
_logger.LogInformation("Created session with ID {SessionId} and capabilities {Capabilities}", session.SessionId, capabilities);
return await Task.FromResult(WebDriverResult.Success(new CreateSessionResponse()
Expand Down Expand Up @@ -133,24 +142,24 @@ private bool IsMatchingCapabilitySet(IDictionary<string, JsonElement> capabiliti

if (appPath != "Root")
{
if(TryGetStringCapability(capabilities, "appium:appArguments", out _))
if(capabilities.ContainsKey("appium:appArguments"))
{
matchedCapabilities.Add("appium:appArguments", capabilities["appium:appArguments"]);
}
if (!appPath.EndsWith("!App"))
{
if (TryGetStringCapability(capabilities, "appium:appWorkingDir", out _))
if (capabilities.ContainsKey("appium:appWorkingDir"))
{
matchedCapabilities.Add("appium:appWorkingDir", capabilities["appium:appWorkingDir"]);
}
}
}
}
else if (TryGetStringCapability(capabilities, "appium:appTopLevelWindow", out _))
else if (capabilities.ContainsKey("appium:appTopLevelWindow"))
{
matchedCapabilities.Add("appium:appTopLevelWindow", capabilities["appium:appTopLevelWindow"]);
}
else if (TryGetStringCapability(capabilities, "appium:appTopLevelWindowTitleMatch", out _))
else if (capabilities.ContainsKey("appium:appTopLevelWindowTitleMatch"))
{
matchedCapabilities.Add("appium:appTopLevelWindowTitleMatch", capabilities["appium:appTopLevelWindowTitleMatch"]);
}
Expand All @@ -159,11 +168,16 @@ private bool IsMatchingCapabilitySet(IDictionary<string, JsonElement> capabiliti
return false;
}

if (TryGetNumberCapability(capabilities, "appium:newCommandTimeout", out _))
if (capabilities.ContainsKey("appium:newCommandTimeout"))
{
matchedCapabilities.Add("appium:newCommandTimeout", capabilities["appium:newCommandTimeout"]); ;
}

if (capabilities.ContainsKey("timeouts"))
{
matchedCapabilities.Add("timeouts", capabilities["timeouts"]);
}

return matchedCapabilities.Count == capabilities.Count;
}

Expand Down

0 comments on commit 6cb32cb

Please sign in to comment.