Skip to content

Commit

Permalink
Fixed bug in UiAutomatorSerer and NodeFinder (#66)
Browse files Browse the repository at this point in the history
- Fixed error handling in UiAutomatorServer
- Fixed FoundNodes when first where filter return zero nodes
  • Loading branch information
MilleBo authored Mar 11, 2022
1 parent da5a590 commit 5c43d50
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/Testura.Android/Device/AndroidDeviceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void DisposeDevice(IAndroidDevice device)
{
lock (BusyDevices)
{
DeviceLogger.Log($"[ANDROIDDEVICEFACTORY]Disposing device {device.Serial}", DeviceLogger.LogLevel.Info);
DeviceLogger.Log($"Disposing device {device.Serial}", DeviceLogger.LogLevel.Info);
device.StopServer();
if (BusyDevices.Any(b => b.configuration.Serial == device.Serial))
{
Expand Down Expand Up @@ -136,7 +136,7 @@ private DeviceConfiguration GetConfiguration(IList<DeviceConfiguration> possible
var availableDevice = possibleDevices.FirstOrDefault(p => IsDeviceAvailable(p.Serial));
if (availableDevice != null)
{
DeviceLogger.Log($"[ANDROIDDEVICEFACTORY] Device available: {availableDevice.Serial}", DeviceLogger.LogLevel.Info);
DeviceLogger.Log($" Device available: {availableDevice.Serial}", DeviceLogger.LogLevel.Info);
BusyDevices.Add((availableDevice, DateTime.Now));
return availableDevice;
}
Expand All @@ -145,7 +145,7 @@ private DeviceConfiguration GetConfiguration(IList<DeviceConfiguration> possible
Thread.Sleep(_timeBetweenChecks);
}

throw new AndroidDeviceFactoryException($"[ANDROIDDEVICEFACTORY] Could not find any available devices after {_maxWaitTime} minutes.");
throw new AndroidDeviceFactoryException($" Could not find any available devices after {_maxWaitTime} minutes.");
}

private void ReleaseTimedOutDevices()
Expand All @@ -165,7 +165,7 @@ private void ReleaseTimedOutDevices()
{
lock (BusyDevices)
{
DeviceLogger.Log($"[ANDROIDDEVICEFACTORY] Releasing device {device.configuration.Serial}", DeviceLogger.LogLevel.Info);
DeviceLogger.Log($" Releasing device {device.configuration.Serial}", DeviceLogger.LogLevel.Info);
BusyDevices.Remove(device);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Testura.Android/Device/Server/UiAutomatorServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ public bool InputText(string text)
/// <returns>True if we managed to perform interaction, otherwise false.</returns>
private bool SendInteractionRequest(string url, TimeSpan timeout)
{
var tries = 0;
while (tries < RequestTries)
var tries = RequestTries;
while (tries > 0)
{
DeviceLogger.Log("Sending interaction request", DeviceLogger.LogLevel.Debug);
var response = SendServerRequest(url, timeout);
Expand Down
6 changes: 6 additions & 0 deletions src/Testura.Android/Device/Ui/Nodes/NodeFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public IList<Node> FindNodes(IList<Node> nodes, IList<Where> wheres, string wild
{
var foundNodes = nodes.Where(n => where.NodeMatch(n, wildcard)).ToList();

// If we don't find any nodes with any of the where conditions, we return an empty list
if (!foundNodes.Any())
{
return new List<Node>();
}

if (!approvedNodes.Any())
{
approvedNodes = foundNodes;
Expand Down
4 changes: 2 additions & 2 deletions src/Testura.Android/Device/Ui/Search/Where.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static Where Class(string @class)
var searchValue = @class.Replace(Wildcard, wildcard);
return node.Class != null && node.Class.Equals(searchValue, StringComparison.OrdinalIgnoreCase);
},
$"content desc equals \"{@class}\"");
$"class equals \"{@class}\"");
}

/// <summary>
Expand Down Expand Up @@ -202,4 +202,4 @@ public static Where Lambda(Func<Node, bool> expression, string customErrorMessag
return new Where((n, w) => expression(n), customErrorMessage ?? "complex lambda");
}
}
}
}
9 changes: 5 additions & 4 deletions src/Testura.Android/Testura.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
<PackageVersion>4.1.2</PackageVersion>
<Version>4.1.2</Version>
<PackageVersion>4.1.3</PackageVersion>
<Version>4.1.3</Version>
<Authors>Mille Bostrom</Authors>
<Copyright>Copyright 2021</Copyright>
<Title>Testura.Android</Title>
Expand All @@ -16,9 +16,10 @@
<PackageIconUrl>https://i.ibb.co/nnSPd11/logo128-new.png</PackageIconUrl>
<PackageIcon>logo.png</PackageIcon>
<RepositoryUrl>https://github.com/Testura/Testura.Android</RepositoryUrl>
<PackageReleaseNotes>Release 4.1.2
<PackageReleaseNotes>Release 4.1.3

- Added more logging in device factory</PackageReleaseNotes>
- Fixed error handling in UiAutomatorServer
- Fixed FoundNodes when first where filter return zero nodes</PackageReleaseNotes>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
</PropertyGroup>

Expand Down

0 comments on commit 5c43d50

Please sign in to comment.