Skip to content

Commit

Permalink
Add timeouts capability
Browse files Browse the repository at this point in the history
  • Loading branch information
aristotelos committed Apr 23, 2024
1 parent 8da1140 commit a0340cd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
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
16 changes: 15 additions & 1 deletion 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 @@ -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 a0340cd

Please sign in to comment.