Skip to content

Commit

Permalink
Release 0.12.0 (#32)
Browse files Browse the repository at this point in the history
* Added method to take a screenshot in the adb service 
* Removed IServiceLoader and the default service loader
* Changed "FunTimeCase" to "ActionTimeCase" 
* Fixed bug with TimeCase and how it didn't restart the timer correctly.
  • Loading branch information
MilleBo authored Jun 4, 2017
1 parent 5bb1083 commit 14be442
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 128 deletions.
43 changes: 33 additions & 10 deletions src/Testura.Android/Device/AndroidDevice.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System.Linq;
using Testura.Android.Device.Configurations;
using Testura.Android.Device.ServiceLoader;
using Testura.Android.Device.Services;
using Testura.Android.Device.Services.Default;
using Testura.Android.Device.Ui.Nodes;
using Testura.Android.Device.Ui.Server;
using Testura.Android.Util;
using Testura.Android.Util.Terminal;

namespace Testura.Android.Device
{
Expand All @@ -12,15 +15,25 @@ public class AndroidDevice : IAndroidDevice
/// Initializes a new instance of the <see cref="AndroidDevice"/> class.
/// </summary>
/// <param name="configuration">Device Configuration</param>
/// <param name="serviceLoader">A custom service loader</param>
public AndroidDevice(DeviceConfiguration configuration, IServiceLoader serviceLoader)
/// <param name="adbService">Service to handle communication with adb</param>
/// <param name="uiService">Service to handle UI</param>
/// <param name="settingsService">Service to handle settings</param>
/// <param name="activityService">Service to handle activities</param>
/// <param name="interactionService">Service to handle interaction with the device</param>
public AndroidDevice(
DeviceConfiguration configuration,
IAdbService adbService,
IUiService uiService,
ISettingsService settingsService,
IActivityService activityService,
IInteractionService interactionService)
{
Configuration = configuration;
Adb = serviceLoader.LoadAdbService(Configuration);
Ui = serviceLoader.LoadUiService(Configuration);
Settings = serviceLoader.LoadSettingsService(Configuration);
Activity = serviceLoader.LoadActivityService(Configuration);
Interaction = serviceLoader.LoadInteractionService(Configuration);
Adb = adbService;
Ui = uiService;
Settings = settingsService;
Activity = activityService;
Interaction = interactionService;
SetOwner();
InstallHelperApks();
}
Expand All @@ -30,15 +43,25 @@ public AndroidDevice(DeviceConfiguration configuration, IServiceLoader serviceLo
/// </summary>
/// <param name="configuration">Device Configuration</param>
public AndroidDevice(DeviceConfiguration configuration)
: this(configuration, new ServiceLoader.ServiceLoader())
{
Configuration = configuration;
Adb = new AdbService(new Terminal(configuration));
Ui = new UiService(
new ScreenDumper(new UiAutomatorServer(new Terminal(configuration), configuration.Port), configuration.DumpTries),
new NodeParser(),
new NodeFinder());
Settings = new SettingsService();
Activity = new ActivityService();
Interaction = new InteractionService();
SetOwner();
InstallHelperApks();
}

/// <summary>
/// Initializes a new instance of the <see cref="AndroidDevice"/> class.
/// </summary>
public AndroidDevice()
: this(new DeviceConfiguration(), new ServiceLoader.ServiceLoader())
: this(new DeviceConfiguration())
{
}

Expand Down
43 changes: 0 additions & 43 deletions src/Testura.Android/Device/ServiceLoader/IServiceLoader.cs

This file was deleted.

68 changes: 0 additions & 68 deletions src/Testura.Android/Device/ServiceLoader/ServiceLoader.cs

This file was deleted.

17 changes: 17 additions & 0 deletions src/Testura.Android/Device/Services/Default/AdbService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,23 @@ public void InstallApp(string path, bool shouldReinstall = true, bool shouldUseP
ExecuteCommand(arguments.ToArray());
}

/// <summary>
/// Take a screenshot of device display
/// </summary>
/// <param name="localPath">Save path for file</param>
public void Screencap(string localPath)
{
if (string.IsNullOrEmpty(localPath))
{
throw new ArgumentException("Argument is null or empty", nameof(localPath));
}

var remotePath = "sdcard/temp_screencap_1234.png";
ExecuteCommand("shell", "screencap", remotePath);
Pull(remotePath, localPath);
ExecuteCommand("shell", "rm", remotePath);
}

private string ExecuteCommand(params string[] arguments)
{
return _terminal.ExecuteAdbCommand(arguments);
Expand Down
6 changes: 6 additions & 0 deletions src/Testura.Android/Device/Services/IAdbService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,11 @@ public interface IAdbService
/// <param name="shouldReinstall">True if we should use the reinstall flag </param>
/// <param name="shouldUsePm">True if we should use the package manager flag</param>
void InstallApp(string path, bool shouldReinstall = true, bool shouldUsePm = false);

/// <summary>
/// Take a screenshot of device display
/// </summary>
/// <param name="localPath">Save path for file</param>
void Screencap(string localPath);
}
}
4 changes: 2 additions & 2 deletions src/Testura.Android/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.11.0.0")]
[assembly: AssemblyFileVersion("0.11.0.0")]
[assembly: AssemblyVersion("0.12.0.0")]
[assembly: AssemblyFileVersion("0.12.0.0")]
4 changes: 1 addition & 3 deletions src/Testura.Android/Testura.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
<ItemGroup>
<Compile Include="Device\AndroidDevice.cs" />
<Compile Include="Device\Extensions\IUiExtension.cs" />
<Compile Include="Device\ServiceLoader\ServiceLoader.cs" />
<Compile Include="Device\ServiceLoader\IServiceLoader.cs" />
<Compile Include="Device\Services\Default\ActivityService.cs" />
<Compile Include="Device\Services\Default\InteractionService.cs" />
<Compile Include="Device\Services\IActivityService.cs" />
Expand Down Expand Up @@ -96,7 +94,7 @@
<Compile Include="Util\Walker\Cases\Stop\StopCase.cs" />
<Compile Include="Util\Walker\Cases\Stop\FuncStopCase.cs" />
<Compile Include="Util\Walker\Cases\Tap\FuncTapCase.cs" />
<Compile Include="Util\Walker\Cases\Time\FunTimeCase.cs" />
<Compile Include="Util\Walker\Cases\Time\ActionTimeCase.cs" />
<Compile Include="Util\Walker\Cases\Time\TimeCase.cs" />
<Compile Include="Util\Walker\Input\IAppWalkerInput.cs" />
<Compile Include="Util\Walker\Input\SwipeAppWalkerInput.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

namespace Testura.Android.Util.Walker.Cases.Time
{
public class FunTimeCase : TimeCase
public class ActionTimeCase : TimeCase
{
private readonly Action<IAndroidDevice> _timeCase;

public FunTimeCase(double interval, Action<IAndroidDevice> timeCase)
public ActionTimeCase(double interval, Action<IAndroidDevice> timeCase)
: base(interval)
{
_timeCase = timeCase;
Expand Down
2 changes: 2 additions & 0 deletions src/Testura.Android/Util/Walker/Cases/Time/TimeCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public void StartTimer(IAndroidDevice device)
private void TimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs)
{
Execute();
_timer.Stop();
_timer.Start();
}
}
}

0 comments on commit 14be442

Please sign in to comment.