Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull changes from NetlifeBackupSolutions/Winium.StoreApps fork #167

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
330f2d6
Improved exception handling
ole-vegard Sep 3, 2015
712c0a2
Updated README
ole-vegard Sep 3, 2015
98bff1a
Updated readme.md to point to gist
ole-vegard Sep 9, 2015
7be57cf
Use ToString on exceptions to get stack trace of inner exceptions too.
Sep 11, 2015
c9d80e6
Removed IsHitTestVisible from IsUserVisible
ole-vegard Sep 16, 2015
4fd1cf7
Added support for dependencies
ole-vegard Sep 25, 2015
7ed489d
Added 'Label' to InnerDrivers TextCommand
ole-vegard Oct 6, 2015
3117c34
Added support for AppBarButtons in IsUserVisible
ole-vegard Oct 6, 2015
f3d2518
Changed IsUserVisible
ole-vegard Oct 7, 2015
bcb44e9
Minor changes after code review
ole-vegard Oct 8, 2015
3f799c0
Merge pull request #6 from NetlifeBackupSolutions/olevegard/appbar
ole-vegard Oct 8, 2015
6dffd32
Changed click in Winium.StoreApps
ole-vegard Oct 22, 2015
b404612
Added id to error message
ole-vegard Oct 23, 2015
f2ca1de
Merge pull request #7 from NetlifeBackupSolutions/olevegard/appbar
ole-vegard Oct 23, 2015
c12a682
Added script for reading text file from local isolated storage
Nov 5, 2015
491256e
Merge branch 'temp'
Nov 5, 2015
3e1134f
MouseMoveToExecutor works with move_to_element_with_offset
Nov 6, 2015
8ccc359
Allow attributes from FrameworkElementExtensions.
Nov 17, 2015
5d505a0
Merge pull request #10 from NetlifeBackupSolutions/magnarn/attribute-…
magnarn Nov 17, 2015
00b92e5
Remove stale registrations of WiniumElement
Nov 19, 2015
19925c4
Fixed bug in AlertCommand
Nov 28, 2015
ca0391c
Fix project files for Release ARM build to store
runelabs Mar 17, 2016
4161ead
Use "pdbonly" for all Release configurations
runelabs Mar 17, 2016
49c71ff
Merge pull request #11 from NetlifeBackupSolutions/rune/CAPSOL-106/fi…
runelabs Mar 18, 2016
58c2a9f
Revert "Fix project files for Release ARM build to store"
runelabs Mar 18, 2016
308a476
Merge pull request #12 from NetlifeBackupSolutions/revert-11-rune/CAP…
runelabs Mar 18, 2016
71a28c4
Merge remote-tracking branch 'winium/master'
ole-vegard Apr 7, 2016
a944377
Refactor get attribute to use own accessor
ole-vegard Apr 11, 2016
ae709d6
Merge pull request #13 from NetlifeBackupSolutions/use_version_1.6.2
ole-vegard Jun 6, 2016
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

# Capture Winium tests

The Capture specific SystemTest documentation can be found [here.](https://gist.github.com/ole-vegard/05ae46c2d7accd170f9f)

<p align="right">
English description | <a href="README_RU.md">Описание на русском</a>
</p>
Expand Down
32 changes: 19 additions & 13 deletions Winium/Winium.Mobile.Connectivity/Deployer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,25 @@ public void SendFiles(List<KeyValuePair<string, string>> files)
}
}

public void InstallDependencies(List<string> dependencies )
{
if (dependencies == null || !dependencies.Any())
{
return;
}

foreach (var dependency in dependencies)
{
InstallDependency(dependency);
}
}

public void InstallDependency(string path)
{
var appManifest = Utils.ReadAppManifestInfoFromPackage(path);
Utils.InstallApplication(this.deviceInfo, appManifest, DeploymentOptions.None, path);
}

public void Terminate()
{
throw new NotImplementedException("Deployer.Terminate");
Expand Down Expand Up @@ -167,19 +186,6 @@ private IAppManifestInfo InstallApplicationPackage(string path)
return appManifest;
}

private void InstallDependencies(List<string> dependencies)
{
if (dependencies == null || !dependencies.Any())
{
return;
}

foreach (var dependency in dependencies)
{
this.InstallApplicationPackage(dependency);
}
}

#endregion
}
}
35 changes: 35 additions & 0 deletions Winium/Winium.StoreApps.Driver/Automator/Automator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,41 @@ private void InitializeDeployer()
return new Point(x, y);
}

public Rectangle? RequestElementRect(JToken element)
{
var command = new Command(
DriverCommand.GetElementRect,
new Dictionary<string, JToken> { { "ID", element } });

var responseBody = this.CommandForwarder.ForwardCommand(command);

var deserializeObject = JsonConvert.DeserializeObject<JsonResponse>(responseBody);

if (deserializeObject.Status != ResponseStatus.Success)
{
return null;
}

var locationObject = deserializeObject.Value as JObject;
if (locationObject == null)
{
return null;
}

var location = locationObject.ToObject<Dictionary<string, int>>();

if (location == null)
{
return null;
}

var x = location["x"];
var y = location["y"];
var width = location["width"];
var height = location["height"];
return new Rectangle(x, y, width, height);
}

#endregion

#region Methods
Expand Down
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Winium.StoreApps.Driver.CommandExecutors
using System.Collections.Generic;

namespace Winium.StoreApps.Driver.CommandExecutors
{
#region

Expand Down Expand Up @@ -50,6 +52,17 @@ internal object ExecuteMobileScript(string command)
return null;
}

internal object ExecuteStorageScript(string command)
{
switch (command)
{
case "ReadLocalTextFile":
return ReadLocalTextFileExecutor.ReadFile(this.Automator, ExecutedCommand);
default:
throw new AutomationException("Unknown storage command: " + command, ResponseStatus.UnknownCommand);
}
}

internal object ForwardCommand()
{
var responseBody = this.Automator.CommandForwarder.ForwardCommand(this.ExecutedCommand);
Expand Down Expand Up @@ -87,6 +100,9 @@ protected override string DoImpl()
case "mobile:":
response = this.ExecuteMobileScript(command);
break;
case "storage:":
response = this.ExecuteStorageScript(command);
break;
default:
response = this.ForwardCommand();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,26 @@ internal class MouseMoveToExecutor : CommandExecutorBase
protected override string DoImpl()
{
var elementId = Automator.GetValue<string>(this.ExecutedCommand.Parameters, "element");
Point coordinates;
if (elementId != null)
var xOffsetParam = this.ExecutedCommand.Parameters["xoffset"];
var yOffsetParam = this.ExecutedCommand.Parameters["yoffset"];

Point coordinates = new Point();
if (xOffsetParam != null && yOffsetParam != null)
{
coordinates = this.Automator.RequestElementLocation(elementId).GetValueOrDefault();
var xOffset = Convert.ToInt32(xOffsetParam, CultureInfo.InvariantCulture);
var yOffset = Convert.ToInt32(yOffsetParam, CultureInfo.InvariantCulture);
coordinates = new Point(xOffset, yOffset);

if (elementId != null)
{
var elementRect = Automator.RequestElementRect(elementId).GetValueOrDefault();
coordinates.X += elementRect.X;
coordinates.Y += elementRect.Y;
}
}
else
else if (elementId != null)
{
var xOffset = Convert.ToInt32(this.ExecutedCommand.Parameters["xoffset"], CultureInfo.InvariantCulture);
var yOffset = Convert.ToInt32(this.ExecutedCommand.Parameters["yoffset"], CultureInfo.InvariantCulture);
coordinates = new Point(xOffset, yOffset);
coordinates = this.Automator.RequestElementLocation(elementId).GetValueOrDefault();
}

this.Automator.EmulatorController.MoveCursorTo(coordinates);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Winium.StoreApps.Common.Exceptions;

namespace Winium.StoreApps.Driver.CommandExecutors
{
using System;
using System.Threading;

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

internal class ReadLocalTextFileExecutor : CommandExecutorBase
{
#region Public Methods and Operators

public static string ReadFile(Automator automator, Command command)
{
var args = command.Parameters["args"] as JArray;
if (args == null || args.Count == 0) {
throw new AutomationException("Missing file name", ResponseStatus.UnknownCommand);
}

var filename = args[0].ToString();
var filePath = Path.GetTempFileName();
automator.Deployer.ReceiveFile("Local", filename, filePath);
using (var file = File.OpenText(filePath)) {
return file.ReadToEnd();
}
}

#endregion

#region Methods

protected override string DoImpl()
{
var fileContent = ReadFile(this.Automator, this.ExecutedCommand);
return this.JsonResponse(ResponseStatus.Success, fileContent);
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<ItemGroup>
<Compile Include="Automator\Automator.cs" />
<Compile Include="Automator\Capabilities.cs" />
<Compile Include="CommandExecutors\ReadLocalTextFileExecutor.cs" />
<Compile Include="CommandExecutors\GetElementAttributeExecutor.cs" />
<Compile Include="CommandExecutors\CloseAppExecutor.cs" />
<Compile Include="CommandExecutors\LaunchAppExecutor.cs" />
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 @@ -157,6 +157,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
10 changes: 8 additions & 2 deletions Winium/Winium.StoreApps.InnerServer/Commands/AlertCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ protected override string DoImpl()
{
var buttonName = this.Action == With.Accept ? "Button1Host" : "Button2Host";

var popup = WiniumVirtualRoot.Current.OpenPopups.FirstOrDefault();
if (popup == null || !popup.ClassName.EndsWith(".ContentDialog"))
WiniumElement popup = null;
foreach (var winiumElement in WiniumVirtualRoot.Current.OpenPopups) {
if (winiumElement.ClassName.EndsWith(".ContentDialog")) {
popup = winiumElement;
break;
}
}
if (popup == null)
{
throw new AutomationException("No alert is displayed", ResponseStatus.NoAlertOpenError);
}
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
}
}
6 changes: 3 additions & 3 deletions Winium/Winium.StoreApps.InnerServer/Commands/CommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public string Do()
}
catch (AutomationException exception)
{
response = this.JsonResponse(exception.Status, exception);
response = this.JsonResponse(exception.Status, exception.ToString());
}
catch (Exception exception)
{
response = this.JsonResponse(ResponseStatus.UnknownError, exception);
response = this.JsonResponse(ResponseStatus.UnknownError, exception.ToString());
}

return response;
Expand Down Expand Up @@ -93,7 +93,7 @@ private static void InvokeSync(CoreDispatcher dispatcher, Action action)

if (exception != null)
{
throw exception;
throw new Exception("An exception occured while execuiting a command. ", exception);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ internal static object GetPropertyCascade(
return propertyObject;
}

if (element.TryGetExtensionProperty(key, out propertyObject))
{
return propertyObject;
}

return null;
}

Expand Down
Loading