Skip to content

Commit f1154ae

Browse files
author
Roei Sabag
committed
fix UiA driver with Selenium Grid 3.141
1 parent 0400540 commit f1154ae

File tree

4 files changed

+67
-7
lines changed

4 files changed

+67
-7
lines changed

src/Gravity.Abstraction.Tests/Base/TestSuite.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected TestSuite()
2727
public static bool CreateRemoteDriver(string onDriver, string onTest, TestContext onContext)
2828
{
2929
// setup
30-
var driverParams = System.Text.Json.JsonSerializer.Serialize(new
30+
var driverParams = JsonSerializer.Serialize(new
3131
{
3232
Driver = onDriver,
3333
DriverBinaries = $"{onContext.Properties["Grid.Endpoint"]}",
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using Newtonsoft.Json.Linq;
2+
3+
using OpenQA.Selenium.Remote;
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Reflection;
9+
using System.Text;
10+
using System.Text.Json;
11+
using System.Threading.Tasks;
12+
13+
namespace Gravity.Abstraction.Uia
14+
{
15+
public class UiaCommandExecutor : HttpCommandExecutor
16+
{
17+
public UiaCommandExecutor(Uri addressOfRemoteServer, TimeSpan timeout)
18+
: base(addressOfRemoteServer, timeout)
19+
{ }
20+
21+
public UiaCommandExecutor(Uri addressOfRemoteServer, TimeSpan timeout, bool enableKeepAlive)
22+
: base(addressOfRemoteServer, timeout, enableKeepAlive)
23+
{ }
24+
25+
protected override void OnSendingRemoteHttpRequest(SendingRemoteHttpRequestEventArgs eventArgs)
26+
{
27+
// setup
28+
var json = JObject.Parse(eventArgs.RequestBody);
29+
var filed = eventArgs.GetType().GetField("requestBody", BindingFlags.Instance | BindingFlags.NonPublic);
30+
31+
// clean capabilites
32+
json.Remove("capabilities");
33+
filed.SetValue(eventArgs, $"{json}");
34+
35+
// clear
36+
base.OnSendingRemoteHttpRequest(eventArgs);
37+
}
38+
}
39+
}

src/Gravity.Abstraction/Uia/UiaDriver.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public UiaDriver(Uri remoteAddress, ICapabilities desiredCapabilities)
5555
/// <summary>
5656
/// initializes a new instance of the <see cref="UiDriver"/> class using the specified <see cref="UiaDriverService"/>
5757
/// </summary>
58-
/// <param name="service">the <see cref="ChromeDriverService"/> to use.</param>
59-
/// <param name="options">The <see cref="ChromeOptions"/> to be used with the Chrome driver.</param>
58+
/// <param name="service">the <see cref="UiaDriverService"/> to use.</param>
59+
/// <param name="options">The <see cref="UiaOptions"/> to be used with the Chrome driver.</param>
6060
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
6161
public UiaDriver(UiaDriverService service, UiaOptions options, TimeSpan commandTimeout)
6262
: base(new DriverServiceCommandExecutor(service, commandTimeout), options.ToCapabilities())
@@ -68,6 +68,15 @@ public UiaDriver(Uri remoteAddress, ICapabilities desiredCapabilities, TimeSpan
6868
: base(remoteAddress, desiredCapabilities, commandTimeout)
6969
{ }
7070

71+
/// <summary>
72+
/// Initializes a new instance of the <see cref="RemoteWebDriver"/> class
73+
/// </summary>
74+
/// <param name="commandExecutor">An <see cref="ICommandExecutor"/> object which executes commands for the driver.</param>
75+
/// <param name="desiredCapabilities">An <see cref="ICapabilities"/> object containing the desired capabilities of the browser.</param>
76+
public UiaDriver(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
77+
: base(commandExecutor, desiredCapabilities)
78+
{ }
79+
7180
/// <summary>
7281
/// gets the capabilities as a dictionary
7382
/// </summary>

src/Gravity.Abstraction/WebDriver/DriverFactory.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
using System.Text.Json;
2828
using System.Diagnostics.CodeAnalysis;
2929
using OpenQA.Selenium.Uia;
30+
using Gravity.Abstraction.Uia;
3031

3132
namespace Gravity.Abstraction.WebDriver
3233
{
@@ -87,7 +88,15 @@ public IWebDriver Create()
8788
var method = GetMethod(driver, isRemote);
8889

8990
// generate driver
90-
return (IWebDriver)method.Invoke(this, new object[] { driverBinaries });
91+
try
92+
{
93+
return (IWebDriver)method.Invoke(this, new object[] { driverBinaries });
94+
}
95+
catch (Exception e)
96+
{
97+
98+
throw;
99+
}
91100
}
92101
#endregion
93102

@@ -218,11 +227,14 @@ private IWebDriver GetRemoteDriver(string driverBinaries)
218227
// get constructor arguments
219228
var options = GetOptions<UiaOptions, UiaOptionsParams>(platformName: "WINDOWS");
220229
var capabilities = GetCapabilities(options, _capabilities);
230+
options.BrowserVersion = string.IsNullOrEmpty(options.BrowserVersion) ? "1.0" : options.BrowserVersion;
231+
221232

222233
// factor web driver
223-
return _commandTimeout == 0
224-
? new UiaDriver(new Uri(driverBinaries), capabilities)
225-
: new UiaDriver(new Uri(driverBinaries), capabilities, TimeSpan.FromSeconds(_commandTimeout));
234+
var executor = _commandTimeout == 0
235+
? new UiaCommandExecutor(new Uri(driverBinaries), TimeSpan.FromSeconds(60))
236+
: new UiaCommandExecutor(new Uri(driverBinaries), TimeSpan.FromSeconds(_commandTimeout));
237+
return new UiaDriver(executor, capabilities);
226238
}
227239
#endregion
228240

0 commit comments

Comments
 (0)