Skip to content

Commit ae23c1a

Browse files
committed
Add constructor using specifed remote address
1 parent a272271 commit ae23c1a

File tree

4 files changed

+58
-20
lines changed

4 files changed

+58
-20
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
namespace OpenQA.Selenium.Winium
2+
{
3+
#region using
4+
5+
using System;
6+
using System.Reflection;
7+
8+
using OpenQA.Selenium.Remote;
9+
10+
#endregion
11+
12+
internal static class CommandExecutorFactory
13+
{
14+
#region Public Methods and Operators
15+
16+
public static ICommandExecutor GetHttpCommandExecutor(Uri remoteAddress, TimeSpan commandTimeout)
17+
{
18+
var seleniumAssembly = Assembly.Load("WebDriver");
19+
var commandType = seleniumAssembly.GetType("OpenQA.Selenium.Remote.HttpCommandExecutor");
20+
ICommandExecutor commandExecutor = null;
21+
22+
if (null != commandType)
23+
{
24+
commandExecutor =
25+
Activator.CreateInstance(commandType, new object[] { remoteAddress, commandTimeout }) as
26+
ICommandExecutor;
27+
}
28+
29+
return commandExecutor;
30+
}
31+
32+
#endregion
33+
}
34+
}

dotnet/src/OpenQA.Selenium.Winium/OpenQA.Selenium.Winium.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
</Reference>
4141
</ItemGroup>
4242
<ItemGroup>
43+
<Compile Include="CommandExecutorFactory.cs" />
4344
<Compile Include="DesktopOptions.cs" />
4445
<Compile Include="IWiniumOptions.cs" />
4546
<Compile Include="Properties\AssemblyInfo.cs" />

dotnet/src/OpenQA.Selenium.Winium/WiniumDriver.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,28 @@ public WiniumDriver(WiniumDriverService service, IWiniumOptions options, TimeSpa
101101
this.InitWiniumDriverCommands();
102102
}
103103

104+
/// <summary>
105+
/// Initializes a new instance of the <see cref="WiniumDriver"/> class using the specified remote address and options.
106+
/// </summary>
107+
/// <param name="remoteAddress">URI containing the address of the WiniumDriver remote server (e.g. http://127.0.0.1:4444/wd/hub).</param>
108+
/// <param name="options">The <see cref="IWiniumOptions"/> object to be used with the Winium driver.</param>
109+
public WiniumDriver(Uri remoteAddress, IWiniumOptions options)
110+
: this(remoteAddress, options, RemoteWebDriver.DefaultCommandTimeout)
111+
{
112+
}
113+
114+
/// <summary>
115+
/// Initializes a new instance of the <see cref="WiniumDriver"/> class using the specified remote address, desired capabilities, and command timeout.
116+
/// </summary>
117+
/// <param name="remoteAddress">URI containing the address of the WiniumDriver remote server (e.g. http://127.0.0.1:4444/wd/hub).</param>
118+
/// <param name="options">The <see cref="IWiniumOptions"/> object to be used with the Winium driver.</param>
119+
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
120+
public WiniumDriver(Uri remoteAddress, IWiniumOptions options, TimeSpan commandTimeout)
121+
: base(CommandExecutorFactory.GetHttpCommandExecutor(remoteAddress, commandTimeout), options.ToCapabilities())
122+
{
123+
this.InitWiniumDriverCommands();
124+
}
125+
104126
#endregion
105127

106128
#region Methods

dotnet/src/OpenQA.Selenium.Winium/WiniumDriverCommandExecutor.cs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class WiniumDriverCommandExecutor : ICommandExecutor
2424
public WiniumDriverCommandExecutor(WiniumDriverService driverService, TimeSpan commandTimeout)
2525
{
2626
this.service = driverService;
27-
this.internalExecutor = GetHttpCommandExecutor(driverService.ServiceUrl, commandTimeout);
27+
this.internalExecutor = CommandExecutorFactory.GetHttpCommandExecutor(driverService.ServiceUrl, commandTimeout);
2828
}
2929

3030
#endregion
@@ -69,24 +69,5 @@ public Response Execute(Command commandToExecute)
6969
}
7070

7171
#endregion
72-
73-
#region Methods
74-
75-
private static ICommandExecutor GetHttpCommandExecutor(Uri remoteAddress, TimeSpan commandTimeout)
76-
{
77-
var seleniumAssembly = Assembly.Load("WebDriver");
78-
var commandType = seleniumAssembly.GetType("OpenQA.Selenium.Remote.HttpCommandExecutor");
79-
ICommandExecutor commandExecutor = null;
80-
81-
if (null != commandType)
82-
{
83-
commandExecutor =
84-
Activator.CreateInstance(commandType, new object[] { remoteAddress, commandTimeout }) as ICommandExecutor;
85-
}
86-
87-
return commandExecutor;
88-
}
89-
90-
#endregion
9172
}
9273
}

0 commit comments

Comments
 (0)