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

Implement closeApp for silverlight apps #168

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<LangVersion>5</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
Expand Down
1 change: 1 addition & 0 deletions Winium/Winium.Mobile.Common/Winium.Mobile.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>5</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down
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
}
}
41 changes: 36 additions & 5 deletions Winium/Winium.Mobile.Connectivity/Deployer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public Deployer(string desiredDevice, bool strict)
{
throw new AutomationException(
string.Format(
"Could not find a device to launch. You requested '{0}', but the available devices were:\n{1}",
desiredDevice,
"Could not find a device to launch. You requested '{0}', but the available devices were:\n{1}",
desiredDevice,
Devices.Instance));
}

Expand All @@ -77,6 +77,8 @@ public string DeviceName
}
}

public AppType AppType { get; private set; }

#endregion

#region Properties
Expand All @@ -99,6 +101,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 @@ -134,9 +137,18 @@ public void SendFiles(List<KeyValuePair<string, string>> files)
}
}

public void Terminate()
public bool Terminate()
{
throw new NotImplementedException("Deployer.Terminate");
if (this.AppType == AppType.XAP)
{
this.RemoteApplication.TerminateRunningInstances();
return true;
}
else
{
Logger.Debug("Could not terminate application from outside.");
return false;
}
}

public void Uninstall()
Expand All @@ -152,16 +164,35 @@ public void Uninstall()

this.Device.Disconnect();
}

#endregion

#region Methods

private 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.");
}

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
4 changes: 3 additions & 1 deletion 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 All @@ -28,7 +30,7 @@ public interface IDeployer

void SendFile(string isoStoreRoot, string sourceDesktopFilePath, string targetDeviceFilePath);

void Terminate();
bool Terminate();

void Uninstall();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<LangVersion>5</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
Expand Down Expand Up @@ -66,6 +67,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Emulator\VirtualMachineException.cs" />
<Compile Include="Retry.cs" />
<Compile Include="AppType.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.Phone.Tools.Deploy.Patched\Microsoft.Phone.Tools.Deploy.Patched.csproj">
Expand Down
11 changes: 8 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,13 @@ 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));
var terminated = automator.Deployer.Terminate();
if (!terminated)
{
var remoteCommand = new Command(DriverCommand.CloseApp);
automator.CommandForwarder.ForwardCommand(remoteCommand);
Thread.Sleep(TimeSpan.FromMilliseconds(500));
}
}

#endregion
Expand Down
1 change: 1 addition & 0 deletions Winium/Winium.Mobile.Driver/Winium.Mobile.Driver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
<LangVersion>5</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
Expand Down
1 change: 1 addition & 0 deletions Winium/Winium.Mobile.Logging/Winium.Mobile.Logging.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>5</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<NoConfig>true</NoConfig>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>5</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>5</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<LangVersion>5</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down