Skip to content

Commit 4ece3a9

Browse files
authored
Release 1.2.1
* Fixed bug with dump and minor improvements to automatic withs
1 parent 2bc60ab commit 4ece3a9

File tree

7 files changed

+26
-17
lines changed

7 files changed

+26
-17
lines changed

src/Testura.Android.PageObjectCreator.Tests/Services/OptimalWithServiceTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void SetUp()
2424
public void GetOptimalWith_WhenOnlyHavingOneNodeAndResourceId_ShouldGetResourceId()
2525
{
2626
var node = new Node(new XElement("node", new XAttribute("resource-id", "test")), null);
27-
var withs = _uniqueWithFinderService.GetUniqueWiths(node, new List<Node>() { node });
27+
var withs = _uniqueWithFinderService.GetUniqueWiths(node, new List<Node>() { node }, false);
2828
Assert.AreEqual(1, withs.Withs.Count);
2929
Assert.AreEqual(AttributeTags.ResourceId, withs.Withs.First());
3030
}
@@ -33,7 +33,7 @@ public void GetOptimalWith_WhenOnlyHavingOneNodeAndResourceId_ShouldGetResourceI
3333
public void GetOptimalWith_WhenOnlyHavingOneNodeResourceIdIsEmpty_ShouldNotGetResourceId()
3434
{
3535
var node = new Node(new XElement("node", new XAttribute("resource-id", ""), new XAttribute("package", "test")), null);
36-
var withs = _uniqueWithFinderService.GetUniqueWiths(node, new List<Node>() { node });
36+
var withs = _uniqueWithFinderService.GetUniqueWiths(node, new List<Node>() { node }, false);
3737
Assert.AreEqual(1, withs.Withs.Count);
3838
Assert.AreEqual(AttributeTags.Package, withs.Withs.First());
3939
}
@@ -43,7 +43,7 @@ public void GetOptimalWith_WhenOnlyHavingTwoWithSameResoruceId_ShouldGetPackage(
4343
{
4444
var node = new Node(new XElement("node", new XAttribute("resource-id", "test"), new XAttribute("package", "test")), null);
4545
var secondNode = new Node(new XElement("node", new XAttribute("resource-id", "test")), null);
46-
var withs = _uniqueWithFinderService.GetUniqueWiths(node, new List<Node>() { node, secondNode });
46+
var withs = _uniqueWithFinderService.GetUniqueWiths(node, new List<Node>() { node, secondNode }, false);
4747
Assert.AreEqual(1, withs.Withs.Count);
4848
Assert.AreEqual(AttributeTags.Package, withs.Withs.First());
4949
}
@@ -54,7 +54,7 @@ public void GetOptimalWith_WhenOnlyHavingSameResourceIdAndPackageAsTwoOther_Shou
5454
var node = new Node(new XElement("node", new XAttribute("resource-id", "test"), new XAttribute("package", "test")), null);
5555
var secondNode = new Node(new XElement("node", new XAttribute("resource-id", "test")), null);
5656
var thirdNode = new Node(new XElement("node", new XAttribute("package", "test")), null);
57-
var withs = _uniqueWithFinderService.GetUniqueWiths(node, new List<Node>() { node, secondNode, thirdNode });
57+
var withs = _uniqueWithFinderService.GetUniqueWiths(node, new List<Node>() { node, secondNode, thirdNode }, false);
5858
Assert.AreEqual(2, withs.Withs.Count);
5959
Assert.AreEqual(AttributeTags.ResourceId, withs.Withs.First());
6060
Assert.AreEqual(AttributeTags.Package, withs.Withs.Last());
@@ -68,7 +68,7 @@ public void GetOptimalWith_WhenNoUniqueValuesAndHaveToUseParent_ShouldGetParent(
6868
parent.Children.Add(node);
6969
var secondNode = new Node(new XElement("node", new XAttribute("package", "test"), new XAttribute("resource-id", "test")), null);
7070
var thirdNode = new Node(new XElement("node", new XAttribute("resource-id", "test"), new XAttribute("package", "test")), null);
71-
var withs = _uniqueWithFinderService.GetUniqueWiths(node, new List<Node>() { node, secondNode, thirdNode, parent });
71+
var withs = _uniqueWithFinderService.GetUniqueWiths(node, new List<Node>() { node, secondNode, thirdNode, parent }, false);
7272
Assert.AreEqual(1, withs.Withs.Count);
7373
Assert.IsNotNull(withs.Parent);
7474
Assert.AreEqual(AttributeTags.ResourceId, withs.Withs.First());
@@ -84,7 +84,7 @@ public void GetOptimalWith_WhenNoUniqueValuesAndHaveToUseParentAndParentsOtherCh
8484
parent.Children.Add(otherChildNode);
8585
var secondNode = new Node(new XElement("node", new XAttribute("package", "test"), new XAttribute("resource-id", "test")), null);
8686
var thirdNode = new Node(new XElement("node", new XAttribute("resource-id", "test"), new XAttribute("package", "test")), null);
87-
var withs = _uniqueWithFinderService.GetUniqueWiths(node, new List<Node>() { node, secondNode, thirdNode, parent, otherChildNode});
87+
var withs = _uniqueWithFinderService.GetUniqueWiths(node, new List<Node>() { node, secondNode, thirdNode, parent, otherChildNode}, false);
8888
Assert.AreEqual(1, withs.Withs.Count);
8989
Assert.IsNotNull(withs.Parent);
9090
Assert.AreEqual(AttributeTags.Package, withs.Withs.First());

src/Testura.Android.PageObjectCreator/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@
3939
// You can specify all the values or you can default the Build and Revision Numbers
4040
// by using the '*' as shown below:
4141
// [assembly: AssemblyVersion("1.0.*")]
42-
[assembly: AssemblyVersion("1.2.0.0")]
43-
[assembly: AssemblyFileVersion("1.2.0.0")]
42+
[assembly: AssemblyVersion("1.2.1.0")]
43+
[assembly: AssemblyFileVersion("1.2.1.0")]

src/Testura.Android.PageObjectCreator/Services/DumpService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ private void TraverseElement(XElement element, Node node)
111111
private string DumpScreen(string serial)
112112
{
113113
var savePath = Path.Combine(AssemblyDirectory, "dump.xml");
114+
var files = _terminal.ExecuteCmdCommand("adb.exe", "-s", serial, "shell", "ls", "/sdcard/");
115+
if (files.Contains("dump.xml"))
116+
{
117+
_terminal.ExecuteCmdCommand("adb.exe", "-s", serial, "shell", "rm", "/sdcard/dump.xml");
118+
}
119+
114120
_terminal.ExecuteCmdCommand("adb.exe", "-s", serial, "shell", "uiautomator", "dump", "/sdcard/dump.xml");
115121
_terminal.ExecuteCmdCommand("adb.exe", "-s", serial, "pull", "/sdcard/dump.xml", AssemblyDirectory);
116122
return savePath;

src/Testura.Android.PageObjectCreator/Services/IUniqueWithFinderService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ namespace Testura.Android.PageObjectCreator.Services
66
{
77
public interface IUniqueWithFinderService
88
{
9-
AutoSelectedWith GetUniqueWiths(Node selectedNode, IList<Node> allNode);
9+
AutoSelectedWith GetUniqueWiths(Node selectedNode, IList<Node> allNode, bool allowTextAndIndex);
1010
}
1111
}

src/Testura.Android.PageObjectCreator/Services/UniqueWithFinderService.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ public UniqueWithFinderService()
2424
};
2525
}
2626

27-
public AutoSelectedWith GetUniqueWiths(Node selectedNode, IList<Node> allNode)
27+
public AutoSelectedWith GetUniqueWiths(Node selectedNode, IList<Node> allNode, bool allowTextAndIndex)
2828
{
2929
var combinations = GetAllCombinations(_attributesPriority);
3030

31-
// We can not use only text or index.
32-
combinations.Remove(combinations.FirstOrDefault(c => c.Count == 1 && c.First() == AttributeTags.Text));
33-
combinations.Remove(combinations.FirstOrDefault(c => c.Count == 1 && c.First() == AttributeTags.Index));
31+
if (!allowTextAndIndex)
32+
{
33+
// We can not use only text or index.
34+
combinations.Remove(combinations.FirstOrDefault(c => c.Count == 1 && c.First() == AttributeTags.Text));
35+
combinations.Remove(combinations.FirstOrDefault(c => c.Count == 1 && c.First() == AttributeTags.Index));
36+
}
3437

3538
foreach (var combination in combinations)
3639
{
@@ -49,8 +52,8 @@ public AutoSelectedWith GetUniqueWiths(Node selectedNode, IList<Node> allNode)
4952

5053
if (selectedNode.Parent != null)
5154
{
52-
var uniqueParent = GetUniqueWiths(selectedNode.Parent, allNode);
53-
var currentNodeUniqueWiths = GetUniqueWiths(selectedNode, selectedNode.Parent.Children);
55+
var uniqueParent = GetUniqueWiths(selectedNode.Parent, allNode, true);
56+
var currentNodeUniqueWiths = GetUniqueWiths(selectedNode, selectedNode.Parent.Children, true);
5457
currentNodeUniqueWiths.Parent = uniqueParent;
5558
return currentNodeUniqueWiths;
5659
}

src/Testura.Android.PageObjectCreator/ViewModels/ScreenViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public bool AddNode(Node node)
7777
Name = name,
7878
Node = node,
7979
FindWith = new List<AttributeTags>(),
80-
AutoSelectedWith = _uniqueWithFinderService.GetUniqueWiths(node, _topNode.AllNodes()),
80+
AutoSelectedWith = _uniqueWithFinderService.GetUniqueWiths(node, _topNode.AllNodes(), false),
8181
DisplayName = "Automatic"
8282
};
8383
MessengerInstance.Send(new AddUiObjectInfoMessage { UiNodeInfo = uiNodeInfo });

src/Testura.Android.PageObjectCreator/ViewModels/WithViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private void Save()
131131

132132
if (UseUniqueWiths)
133133
{
134-
UiObjectInfo.AutoSelectedWith = _uniqueWithFinderService.GetUniqueWiths(UiObjectInfo.Node, _allNodes);
134+
UiObjectInfo.AutoSelectedWith = _uniqueWithFinderService.GetUniqueWiths(UiObjectInfo.Node, _allNodes, false);
135135
}
136136
else
137137
{

0 commit comments

Comments
 (0)