Skip to content

Commit

Permalink
Merge pull request #7 from NetlifeBackupSolutions/olevegard/appbar
Browse files Browse the repository at this point in the history
Changed click in Winium.StoreApps
  • Loading branch information
ole-vegard committed Oct 23, 2015
2 parents 3f799c0 + b404612 commit f2ca1de
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#region

using Winium.StoreApps.Driver.Automator;
using System;

#endregion

Expand All @@ -27,9 +28,12 @@ internal static bool ClickElement(Automator automator, string elementId)

protected override string DoImpl()
{
ClickElement(this.Automator, this.ExecutedCommand.Parameters["ID"].ToString());

return this.JsonResponse();
try {
return this.Automator.CommandForwarder.ForwardCommand(this.ExecutedCommand);
} catch (Exception e) {
ClickElement(this.Automator, this.ExecutedCommand.Parameters["ID"].ToString());
return this.JsonResponse();
}
}

#endregion
Expand Down
4 changes: 4 additions & 0 deletions Winium/Winium.StoreApps.InnerServer/Automator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ public string ProcessCommand(string content)
{
commandToExecute = new CloseAppCommand();
}
else if (command.Equals(DriverCommand.ClickElement))
{
commandToExecute = new ClickCommand {ElementId = elementId};
}
else
{
throw new NotImplementedException("Not implemented: " + command);
Expand Down
44 changes: 44 additions & 0 deletions Winium/Winium.StoreApps.InnerServer/Commands/ClickCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace Winium.StoreApps.InnerServer.Commands
{
#region

using Windows.UI.Xaml.Automation.Peers;
using Windows.UI.Xaml.Automation.Provider;
using Windows.UI.Xaml.Controls;
using Common;

#endregion

internal class ClickCommand : CommandBase
{
#region Public Properties

public string ElementId { private get; set; }

#endregion

#region Public Methods and Operators

protected override string DoImpl()
{
var element = this.Automator.ElementsRegistry.GetRegisteredElement(this.ElementId);
Button button = element.Element as Button;
if (button != null)
{
ButtonAutomationPeer peer = new ButtonAutomationPeer(button);
IInvokeProvider invokeProv = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
if (invokeProv != null)
{
invokeProv.Invoke();
return this.JsonResponse(ResponseStatus.Success, "");
}

return this.JsonResponse(ResponseStatus.UnknownError, "Failed to create invocation provider : " + this.ElementId);
}

return this.JsonResponse(ResponseStatus.UnknownError, "Element is not a button" + this.ElementId);
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<Compile Include="AutomationServer.cs" />
<Compile Include="Automator.cs" />
<Compile Include="Commands\GetElementRectCommand.cs" />
<Compile Include="Commands\ClickCommand.cs" />
<Compile Include="Commands\GetElementSizeCommand.cs" />
<Compile Include="ElementsRegistry.cs" />
<Compile Include="Commands\AlertCommand.cs" />
Expand Down

0 comments on commit f2ca1de

Please sign in to comment.