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
9 changes: 9 additions & 0 deletions Winium/Winium.Mobile.Connectivity/AppType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Winium.Mobile.Connectivity
{
public enum AppType
{
XAP = Microsoft.Phone.Tools.Deploy.TypeOfApp.XAP,
APPX = Microsoft.Phone.Tools.Deploy.TypeOfApp.APPX,
APPXBUNDLE = Microsoft.Phone.Tools.Deploy.TypeOfApp.APPXBUNDLE
}
}
32 changes: 31 additions & 1 deletion Winium/Winium.Mobile.Connectivity/Deployer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,31 @@ public string DeviceName

private IRemoteApplication RemoteApplication { get; set; }

public AppType AppType { get; private set; }

#endregion

#region Public Methods and Operators

public static AppType DetermineAppType(string packagePath)
{
var extension = Path.GetExtension(packagePath);
if (!string.IsNullOrEmpty(extension))
{
switch (extension.ToLower(CultureInfo.InvariantCulture))
{
case ".appxbundle":
return AppType.APPXBUNDLE;
case ".appx":
return AppType.APPX;
case ".xap":
return AppType.XAP;
}
}

throw new NotImplementedException("This file extension is not supported by the tool.");
}

public void Install(string appPath, List<string> dependencies)
{
this.InstallDependencies(dependencies);
Expand All @@ -99,6 +120,7 @@ public void UsePreInstalledApplication(string appPath)
{
var appManifest = Utils.ReadAppManifestInfoFromPackage(appPath);
this.RemoteApplication = this.Device.GetApplication(appManifest.ProductId);
this.AppType = DetermineAppType(appPath);
}

public void Launch()
Expand Down Expand Up @@ -136,7 +158,14 @@ public void SendFiles(List<KeyValuePair<string, string>> files)

public void Terminate()
{
throw new NotImplementedException("Deployer.Terminate");
if (this.AppType == AppType.XAP)
{
this.RemoteApplication.TerminateRunningInstances();
}
else
{
throw new NotImplementedException("Deployer.Terminate");
}
}

public void Uninstall()
Expand All @@ -162,6 +191,7 @@ private void InstallApp(string appPath)
var appManifestInfo = this.InstallApplicationPackage(appPath);
this.installed = true;
this.RemoteApplication = this.Device.GetApplication(appManifestInfo.ProductId);
this.AppType = DetermineAppType(appPath);
}

private IAppManifestInfo InstallApplicationPackage(string path)
Expand Down
2 changes: 2 additions & 0 deletions Winium/Winium.Mobile.Connectivity/IDeployer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public interface IDeployer

string DeviceName { get; }

AppType AppType { get; }

#endregion

#region Public Methods and Operators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="AppType.cs" />
<Compile Include="Deployer.cs" />
<Compile Include="DeployerFactory.cs" />
<Compile Include="Gestures\FlickGesture.cs" />
Expand Down
6 changes: 3 additions & 3 deletions Winium/Winium.Mobile.Driver/CommandExecutorDispatchTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public CommandExecutorBase GetExecutor(Command command)
{
var automator = Automator.Automator.InstanceForSession(command.SessionId);

if (automator.CurrentContext != DefaultContextNames.NativeAppContextName
&& !DriverBoundCommands.Contains(command.Name))
if (automator.CurrentContext != null && automator.CurrentContext != DefaultContextNames.NativeAppContextName)
{
return new CommandExecutorWebContextForward();
if (!DriverBoundCommands.Contains(command.Name))
return new CommandExecutorWebContextForward();
}

// TODO inject dependencies into command executor
Expand Down
14 changes: 11 additions & 3 deletions Winium/Winium.Mobile.Driver/CommandExecutors/CloseAppExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Winium.Mobile.Driver.CommandExecutors
{
using Connectivity;
using System;
using System.Threading;

Expand All @@ -12,9 +13,16 @@ internal class CloseAppExecutor : CommandExecutorBase

public static void CloseApp(Automator automator)
{
var remoteCommand = new Command(DriverCommand.CloseApp);
automator.CommandForwarder.ForwardCommand(remoteCommand);
Thread.Sleep(TimeSpan.FromMilliseconds(500));
if (automator.Deployer.AppType == AppType.XAP)
{
automator.Deployer.Terminate();
}
else
{
var remoteCommand = new Command(DriverCommand.CloseApp);
automator.CommandForwarder.ForwardCommand(remoteCommand);
Thread.Sleep(TimeSpan.FromMilliseconds(500));
}
}

#endregion
Expand Down
6 changes: 6 additions & 0 deletions Winium/Winium.Silverlight.InnerServer/AutomationServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Newtonsoft.Json;

using Winium.Mobile.Common;
using Microsoft.Phone.Controls;

public class AutomationServer
{
Expand Down Expand Up @@ -60,6 +61,11 @@ public void SetAutomator(UIElement visualRoot)
this.automator = new Automator(visualRoot);
}

public void SetBrowser(WebBrowser browser)
{
this.automator.browser = browser;
}

public async void Start()
{
if (this.isServerActive)
Expand Down
98 changes: 90 additions & 8 deletions Winium/Winium.Silverlight.InnerServer/Automator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

using Winium.Mobile.Common;
using Winium.Silverlight.InnerServer.Commands;
using Web.Commands;
using Web;
using Microsoft.Phone.Controls;

internal class Automator
{
Expand All @@ -19,6 +22,8 @@ public Automator(UIElement visualRoot)
{
this.VisualRoot = visualRoot;
this.WebElements = new AutomatorElements();
this.ContextsRegistry = new ContextsRegistry();
this.CurrentContext = ContextsRegistry.NativeAppContext;
}

#endregion
Expand All @@ -29,6 +34,13 @@ public Automator(UIElement visualRoot)

public AutomatorElements WebElements { get; private set; }

public string CurrentContext { get; set; }

public WebBrowser browser { get; set; }

public ContextsRegistry ContextsRegistry { get; private set; }


#endregion

#region Public Methods and Operators
Expand All @@ -51,14 +63,90 @@ public string ProcessCommand(string content)
elementId = elementIdObject.ToString();
}

CommandBase commandToExecute;
CommandBase commandToExecute = null;

if (command.Equals("ping"))
{
// Service command
return "<pong>";
}

if (command.Equals(DriverCommand.Contexts))
{
commandToExecute = new GetWebContextsCommand();
}
else if (command.Equals(DriverCommand.SetContext))
{
commandToExecute = new SetContextCommand();
}

// TODO: Refactor similar to CommandExecutors in OuterDriver
// TODO: Refactor similar to CommandExecutors in Driver
if (commandToExecute == null)
{
commandToExecute = this.CurrentContext == ContextsRegistry.NativeAppContext
? GetNativeAppCommandToExecute(command, elementId, parameters)
: this.GetWebCommandToExecute(requestData);
}



JToken sessionIdObject;
commandToExecute.Session = parameters.TryGetValue("SESSIONID", out sessionIdObject)
? sessionIdObject.ToString()
: string.Empty;

// TODO: Replace passing Automator to command with passing some kind of configuration
commandToExecute.Automator = this;
commandToExecute.Parameters = parameters;

var response = commandToExecute.Do();

return response;
}

private CommandBase GetWebCommandToExecute(Command request)
{
var command = request.Name;
WebCommandHandler commandToExecute;

var context = this.ContextsRegistry.GetContext(this.CurrentContext);

if (command.Equals(DriverCommand.Get))
{
commandToExecute = new GoToUrlCommandHandler();
}
else if (command.Equals(DriverCommand.FindElement))
{
commandToExecute = new FindElementCommandHandler();
}
else if (command.Equals(DriverCommand.ClickElement))
{
commandToExecute = new ClickElementCommandHandler();
}
else if (command.Equals(DriverCommand.SendKeysToElement))
{
commandToExecute = new SendKeysCommandHandler();
}
else if (command.Equals(DriverCommand.GetPageSource))
{
commandToExecute = new GetPageSourceCommandHandler();
}
else
{
throw new NotImplementedException("Not implemented: " + command);
}

commandToExecute.Atom = request.Atom;
commandToExecute.Context = context;

return commandToExecute;

}

private CommandBase GetNativeAppCommandToExecute(string command, string elementId, IDictionary<string, JToken> parameters)
{
CommandBase commandToExecute;
// TODO: Refactor similar to CommandExecutors in Driver
if (command.Equals(DriverCommand.GetAlertText))
{
Expand Down Expand Up @@ -148,13 +236,7 @@ public string ProcessCommand(string content)
throw new NotImplementedException("Not implemented: " + command);
}

// TODO: Replace passing Automator to command with passing some kind of configuration
commandToExecute.Automator = this;
commandToExecute.Parameters = parameters;

var response = commandToExecute.Do();

return response;
return commandToExecute;
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Winium.Silverlight.InnerServer.Commands
{
using System.Collections.Generic;
using System.Linq;
using Winium.Mobile.Common;

internal class GetWebContextsCommand : CommandBase
{
private static readonly IEnumerable<string> UnconditionalContexts = new[] { DefaultContextNames.NativeAppContextName };
public override string DoImpl()

{
var contexts = this.Automator.ContextsRegistry.GetAllContexts(this.Automator.browser);

return this.JsonResponse(ResponseStatus.Success, UnconditionalContexts.Union(contexts));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace Winium.Silverlight.InnerServer.Commands
{
#region

using Newtonsoft.Json.Linq;

using Mobile.Common;
using Mobile.Common.Exceptions;

#endregion
internal class SetContextCommand : CommandBase
{
public override string DoImpl()
{
JToken value;
if (!this.Parameters.TryGetValue("name", out value))
{
throw new AutomationException("Bad argument: name", ResponseStatus.UnknownCommand);
}

var name = value.ToObject<string>();

if (string.IsNullOrWhiteSpace(name))
{
name = DefaultContextNames.NativeAppContextName;
}

if (!name.Equals(DefaultContextNames.NativeAppContextName))
{
// check if context is still valid
this.Automator.ContextsRegistry.GetContext(name);
}

this.Automator.CurrentContext = name;

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