Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/.nuget/NuGet.Config
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
</packageRestore>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
<Reference Include="System.Drawing" />
<Reference Include="System.Messaging" />
<Reference Include="System.Windows.Forms" />
<Reference Include="WebDriver, Version=2.53.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Selenium.WebDriver.2.53.1\lib\net40\WebDriver.dll</HintPath>
<Reference Include="WebDriver, Version=3.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Selenium.WebDriver.3.3.0\lib\net40\WebDriver.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="WindowsBase" />
Expand Down Expand Up @@ -92,4 +92,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="2.6.4" targetFramework="net45" />
<package id="Selenium.WebDriver" version="2.53.1" targetFramework="net45" />
</packages>
<package id="Selenium.WebDriver" version="3.3.0" targetFramework="net45" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="WebDriver, Version=2.53.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Selenium.WebDriver.2.53.1\lib\net40\WebDriver.dll</HintPath>
<Reference Include="WebDriver, Version=3.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Selenium.WebDriver.3.3.0\lib\net40\WebDriver.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="WindowsBase" />
Expand Down Expand Up @@ -96,4 +96,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
4 changes: 2 additions & 2 deletions src/TestApps.Tests/WpfTestApplication.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="2.6.4" targetFramework="net45" />
<package id="Selenium.WebDriver" version="2.53.1" targetFramework="net45" />
</packages>
<package id="Selenium.WebDriver" version="3.3.0" targetFramework="net45" />
</packages>
12 changes: 3 additions & 9 deletions src/Winium.Desktop.Driver/Automator/Automator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ internal class Automator

#region Constructors and Destructors

public Automator(string session)
public Automator()
{
this.Session = session;
this.ElementsRegistry = new ElementsRegistry();
}

Expand All @@ -37,7 +36,7 @@ public Automator(string session)

public ElementsRegistry ElementsRegistry { get; private set; }

public string Session { get; private set; }
public string Session { get; set; }

public WiniumKeyboard WiniumKeyboard { get; set; }

Expand All @@ -61,13 +60,8 @@ public static Automator InstanceForSession(string sessionId)
{
if (instance == null)
{
if (sessionId == null)
{
sessionId = "AwesomeSession";
}

// TODO: Add actual support for sessions. Temporary return single Automator for any season
instance = new Automator(sessionId);
instance = new Automator();
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/Winium.Desktop.Driver/Automator/Capabilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ internal Capabilities()
{
this.App = string.Empty;
this.Arguments = string.Empty;
this.ResetDirectory = string.Empty;
this.ResetProcesses = false;
this.LaunchDelay = 0;
this.DebugConnectToRunningApp = false;
this.InnerPort = 9998;
Expand All @@ -27,12 +29,27 @@ internal Capabilities()

#region Public Properties

[JsonProperty("platformName")]
public static string PlatformName
{
get
{
return "Windows";
}
}

[JsonProperty("app")]
public string App { get; set; }

[JsonProperty("args")]
public string Arguments { get; set; }

[JsonProperty("resetDirectory")]
public string ResetDirectory { get; set; }

[JsonProperty("resetProcesses")]
public bool ResetProcesses { get; set; }

[JsonProperty("debugConnectToRunningApp")]
public bool DebugConnectToRunningApp { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Newtonsoft.Json;

using Winium.Desktop.Driver.Automator;
using Winium.Desktop.Driver.Exceptions;
using Winium.StoreApps.Common;
using Winium.StoreApps.Common.Exceptions;

Expand Down Expand Up @@ -52,6 +53,12 @@ public CommandResponse Do()
HttpStatusCode.NotImplemented,
this.JsonResponse(ResponseStatus.UnknownCommand, exception));
}
catch (SessionNotCreatedException exception)
{
return CommandResponse.Create(
HttpStatusCode.InternalServerError,
this.JsonResponse(ResponseStatus.SessionNotCreatedException, exception.GetBaseException()));
}
catch (Exception exception)
{
return CommandResponse.Create(
Expand All @@ -76,8 +83,13 @@ protected string JsonResponse()

protected string JsonResponse(ResponseStatus status, object value)
{
var session = this.Automator.Session;
if (status == ResponseStatus.SessionNotCreatedException)
{
this.Automator.Session = null;
}
return JsonConvert.SerializeObject(
new JsonResponse(this.Automator.Session, status, value),
new JsonResponse(session, status, value),
Formatting.Indented);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Winium.Desktop.Driver.CommandExecutors
{
#region using

using Winium.StoreApps.Common;

#endregion

internal class GetSessionCapabilitiesExecutor : CommandExecutorBase
{
#region Methods

protected override string DoImpl()
{
return this.JsonResponse(ResponseStatus.Success, this.Automator.ActualCapabilities);
}

#endregion
}
}
82 changes: 73 additions & 9 deletions src/Winium.Desktop.Driver/CommandExecutors/NewSessionExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
{
#region using

using System;
using System.IO;
using System.Diagnostics;
using System.Threading;

using Newtonsoft.Json;

using Winium.Cruciatus;
using Winium.Cruciatus.Settings;
using Winium.Desktop.Driver.Automator;
using Winium.Desktop.Driver.Exceptions;
using Winium.Desktop.Driver.Input;
using Winium.StoreApps.Common;

Expand All @@ -20,21 +24,81 @@ internal class NewSessionExecutor : CommandExecutorBase

protected override string DoImpl()
{
// It is easier to reparse desired capabilities as JSON instead of re-mapping keys to attributes and calling type conversions,
// so we will take possible one time performance hit by serializing Dictionary and deserializing it as Capabilities object
var serializedCapability =
JsonConvert.SerializeObject(this.ExecutedCommand.Parameters["desiredCapabilities"]);
this.Automator.ActualCapabilities = Capabilities.CapabilitiesFromJsonString(serializedCapability);
try
{
this.Automator.Session = Guid.NewGuid().ToString();
Logger.Debug("session for command: " + this.Automator.Session);

this.InitializeApplication(this.Automator.ActualCapabilities.DebugConnectToRunningApp);
this.InitializeKeyboardEmulator(this.Automator.ActualCapabilities.KeyboardSimulator);
// It is easier to reparse desired capabilities as JSON instead of re-mapping keys to attributes and calling type conversions,
// so we will take possible one time performance hit by serializing Dictionary and deserializing it as Capabilities object
var serializedCapability =
JsonConvert.SerializeObject(this.ExecutedCommand.Parameters["desiredCapabilities"]);
this.Automator.ActualCapabilities = Capabilities.CapabilitiesFromJsonString(serializedCapability);

// Gives sometime to load visuals (needed only in case of slow emulation)
Thread.Sleep(this.Automator.ActualCapabilities.LaunchDelay);
if (this.Automator.ActualCapabilities.ResetProcesses)
{
this.ResetProcesses(this.Automator.ActualCapabilities.App);
}
this.ResetDirectory(this.Automator.ActualCapabilities.ResetDirectory);
this.InitializeApplication(this.Automator.ActualCapabilities.DebugConnectToRunningApp);
this.InitializeKeyboardEmulator(this.Automator.ActualCapabilities.KeyboardSimulator);

// Gives sometime to load visuals (needed only in case of slow emulation)
Thread.Sleep(this.Automator.ActualCapabilities.LaunchDelay);
} catch(Exception e)
{
throw new SessionNotCreatedException(e.Message, e);
}

return this.JsonResponse(ResponseStatus.Success, this.Automator.ActualCapabilities);
}

private void ResetProcesses(string app)
{
string executable = app.Substring(app.LastIndexOf("\\") + 1);
string processName = executable.Substring(0, executable.LastIndexOf("."));
foreach (Process process in Process.GetProcesses())
{
Logger.Debug("Running process: " + process.ProcessName);
}
foreach (Process process in Process.GetProcessesByName(processName))
{
Logger.Debug("Killing process: " + process.ProcessName);
try
{
process.Kill();
}
catch (Exception e)
{
Logger.Info("Could not kill process: " + e.Message);
}
try
{
process.WaitForExit(10000);
} catch(Exception e)
{
Logger.Info("Could not wait for process to exit: " + e.Message);
}
}
}

private void ResetDirectory(string resetDirectory)
{
if (!string.IsNullOrEmpty(resetDirectory))
{
DirectoryInfo directory = new DirectoryInfo(resetDirectory);

foreach (FileInfo file in directory.GetFiles())
{
file.Delete();
}
foreach (DirectoryInfo subDirectory in directory.GetDirectories())
{
subDirectory.Delete(true);
}
}
}

private void InitializeApplication(bool debugDoNotDeploy = false)
{
var appPath = this.Automator.ActualCapabilities.App;
Expand Down
20 changes: 20 additions & 0 deletions src/Winium.Desktop.Driver/CommandExecutors/SetTimeoutExecutor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Winium.Desktop.Driver.CommandExecutors
{
#region using

using Winium.StoreApps.Common;

#endregion

internal class SetTimeoutExecutor : CommandExecutorBase
{
#region Methods

protected override string DoImpl()
{
return this.JsonResponse(ResponseStatus.Success, null);
}

#endregion
}
}
10 changes: 8 additions & 2 deletions src/Winium.Desktop.Driver/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@ internal class CommandLineOptions
HelpText = "write server log to file instead of stdout, increases log level to INFO")]
public string LogPath { get; set; }

[Option("port", Required = false, HelpText = "port to listen on")]
public int? Port { get; set; }
[Option("port", Required = false, DefaultValue = 9999, HelpText = "port to listen on")]
public int Port { get; set; }

[Option("url-base", Required = false, HelpText = "base URL path prefix for commands, e.g. wd/url")]
public string UrlBase { get; set; }

[Option("verbose", Required = false, HelpText = "log verbosely")]
public bool Verbose { get; set; }

[Option("version", Required = false, HelpText = "print version number and exit")]
public bool Version { get; set; }

[Option("nodeconfig", Required = false, HelpText = "configuration JSON file to register driver with selenium grid")]
public string NodeConfig { get; set; }

[Option("silent", Required = false, HelpText = "log nothing")]
public bool Silent { get; set; }

Expand Down
35 changes: 35 additions & 0 deletions src/Winium.Desktop.Driver/Exceptions/SessionNotCreatedException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace Winium.Desktop.Driver.Exceptions
{
#region

using System;

#endregion

public class SessionNotCreatedException : Exception
{

#region Constructors and Destructors

public SessionNotCreatedException()
{
}

public SessionNotCreatedException(string message)
: base(message)
{
}

public SessionNotCreatedException(string message, params object[] args)
: base(string.Format(message, args))
{
}

public SessionNotCreatedException(string message, Exception innerException)
: base(message, innerException)
{
}

#endregion
}
}
Loading