Skip to content

Commit 86416c3

Browse files
committed
Fix issue with custom filters not working for control lookup
GetElementMatchingCriteria is invoked with a collection of UIControl. However, different control entitie initialize filter argument with different types e.g. AutomationElement, IWebElment, etc. This causes a mismatch and script fails to execute. To adresss this we can either initialize filter argument with type of UIControl for all type of ControlEntity or each ControlEntity must ensure to invoke GetElementMatchingCriteria by converting collection of UIControl to collection of api control e.g. collection of AutomationElement. We decided on the first approach as it provides access to all the methods availble on UIControl. However, if someone needs access to the actual API controls, they need to add additional imports and reference before they can use UIControl.GetApiControl<T> which is a bit incovenient if frequently required.
1 parent f627f94 commit 86416c3

File tree

6 files changed

+15
-52
lines changed

6 files changed

+15
-52
lines changed

src/Pixel.Automation.Core.Components/Entities/ControlEntity.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,16 @@ public IControlIdentity ControlDetails
134134

135135
}
136136

137-
protected abstract void InitializeFilter();
137+
/// <summary>
138+
/// Initialize the Filter Argument.
139+
/// </summary>
140+
protected virtual void InitializeFilter()
141+
{
142+
if (this.Filter == null)
143+
{
144+
this.Filter = new PredicateArgument<UIControl>() { CanChangeType = false };
145+
}
146+
}
138147

139148
public ControlEntity(string name = "Control Entity", string tag = "ControlEntity") : base(name, tag)
140149
{

src/Pixel.Automation.Image.Matching.Components/ImageControlEntity.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,7 @@ public ImageSearchScope ImageSearchScope
8484
[DataMember]
8585
[Display(Name = "Area on screen", GroupName = "Search Strategy", Order = 15)]
8686
[Description("Target window within which image lookup will be restricted")]
87-
public Argument AreaOnScreen { get; set; } = new InArgument<BoundingBox>() { Mode = ArgumentMode.DataBound };
88-
89-
///<inheritdoc/>
90-
protected override void InitializeFilter()
91-
{
92-
if (this.Filter == null)
93-
{
94-
this.Filter = new PredicateArgument<BoundingBox>() { CanChangeType = false };
95-
}
96-
}
87+
public Argument AreaOnScreen { get; set; } = new InArgument<BoundingBox>() { Mode = ArgumentMode.DataBound };
9788

9889
///<inheritdoc/>
9990
public override async Task<UIControl> GetControl()

src/Pixel.Automation.Java.Access.Bridge.Components/JavaControlEntity.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
using Pixel.Automation.Core.Arguments;
2-
using Pixel.Automation.Core.Components;
1+
using Pixel.Automation.Core.Components;
32
using Pixel.Automation.Core.Controls;
43
using Pixel.Automation.Core.Enums;
54
using Serilog;
65
using System;
76
using System.Collections.Generic;
87
using System.Threading.Tasks;
9-
using WindowsAccessBridgeInterop;
108

119
namespace Pixel.Automation.Java.Access.Bridge.Components
1210
{
@@ -15,15 +13,7 @@ public class JavaControlEntity : ControlEntity
1513
private readonly ILogger logger = Log.ForContext<JavaControlEntity>();
1614

1715
private UIControl control;
18-
19-
protected override void InitializeFilter()
20-
{
21-
if (this.Filter == null)
22-
{
23-
this.Filter = new PredicateArgument<AccessibleContextNode>();
24-
}
25-
}
26-
16+
2717
/// <summary>
2818
/// Clear the located control once entity is processed
2919
/// </summary>

src/Pixel.Automation.UIA.Components/WinControlEntity.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
extern alias uiaComWrapper;
2-
using Pixel.Automation.Core.Arguments;
32
using Pixel.Automation.Core.Components;
43
using Pixel.Automation.Core.Controls;
54
using Pixel.Automation.Core.Enums;
65
using Serilog;
76
using System;
87
using System.Collections.Generic;
98
using System.Threading.Tasks;
10-
using uiaComWrapper::System.Windows.Automation;
119

1210
namespace Pixel.Automation.UIA.Components
1311
{
@@ -16,15 +14,7 @@ public class WinControlEntity : ControlEntity
1614
private readonly ILogger logger = Log.ForContext<WinControlEntity>();
1715

1816
private UIControl control;
19-
20-
protected override void InitializeFilter()
21-
{
22-
if (this.Filter == null)
23-
{
24-
this.Filter = new PredicateArgument<AutomationElement>();
25-
}
26-
}
27-
17+
2818
/// <summary>
2919
/// Clear the located control once entity is processed
3020
/// </summary>

src/Pixel.Automation.Web.Playwright.Components/WebControlEntity.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,7 @@ public class WebControlEntity : ControlEntity
1111
{
1212
private readonly ILogger logger = Log.ForContext<WebControlEntity>();
1313

14-
private UIControl control;
15-
16-
protected override void InitializeFilter()
17-
{
18-
if (this.Filter == null)
19-
{
20-
this.Filter = new PredicateArgument<ILocator>();
21-
}
22-
}
14+
private UIControl control;
2315

2416
/// <summary>
2517
/// Clear the located control once entity is processed

src/Pixel.Automation.Web.Selenium.Components/WebControlEntity.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using OpenQA.Selenium;
2-
using Pixel.Automation.Core.Arguments;
32
using Pixel.Automation.Core.Components;
43
using Pixel.Automation.Core.Controls;
54
using Pixel.Automation.Core.Enums;
@@ -17,14 +16,6 @@ public class WebControlEntity : ControlEntity
1716

1817
private UIControl control;
1918

20-
protected override void InitializeFilter()
21-
{
22-
if (this.Filter == null)
23-
{
24-
this.Filter = new PredicateArgument<IWebElement>();
25-
}
26-
}
27-
2819
/// <summary>
2920
/// Clear the located control once entity is processed
3021
/// </summary>

0 commit comments

Comments
 (0)