Skip to content

Commit c7123cb

Browse files
committed
Add MAUI AutomationId to generic element info
1 parent 723c84e commit c7123cb

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Rename MemoryInfo.AllocatedBytes to MemoryInfo.TotalAllocatedBytes ([#4243](https://github.com/getsentry/sentry-dotnet/pull/4243))
88
- Replace libcurl with .NET HttpClient for sentry-native ([#4222](https://github.com/getsentry/sentry-dotnet/pull/4222))
9+
- Add .NET MAUI `AutomationId` element information to breadcrumbs ([#4248](https://github.com/getsentry/sentry-dotnet/pull/4248))
910

1011
### Fixes
1112

src/Sentry.Maui/Internal/Extensions.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,26 @@ public static void AddElementInfo(this IDictionary<string, string> data,
5353
// The element ID seems to be mostly useless noise
5454
//data.Add(prefix + nameof(element.Id), element.Id.ToString());
5555

56-
if (element.StyleId != null)
56+
if (element.AutomationId is { } automationId)
57+
{
58+
data.Add(prefix + nameof(Element.AutomationId), automationId);
59+
}
60+
61+
if (element.StyleId is { } styleId)
5762
{
5863
// The StyleId correlates to the element's name if one is set in XAML
5964
// TODO: Is there a better way to get this?
60-
data.Add(prefix + "Name", element.StyleId);
65+
data.Add(prefix + "Name", styleId);
6166
}
6267

63-
if (options.IncludeTitleInBreadcrumbs && element is ITitledElement { Title: { } } titledElement)
68+
if (options.IncludeTitleInBreadcrumbs && element is ITitledElement { Title: { } title })
6469
{
65-
data.Add(prefix + nameof(titledElement.Title), titledElement.Title);
70+
data.Add(prefix + nameof(ITitledElement.Title), title);
6671
}
6772

68-
if (options.IncludeTextInBreadcrumbs && element is IText { Text: { } } textElement)
73+
if (options.IncludeTextInBreadcrumbs && element is IText { Text: { } text })
6974
{
70-
data.Add(prefix + nameof(textElement.Text), textElement.Text);
75+
data.Add(prefix + nameof(IText.Text), text);
7176
}
7277
}
7378

test/Sentry.Maui.Tests/MauiEventsBinderTests.Element.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public void Element_ChildEvents_AddsBreadcrumb(string eventName)
1515
_fixture.Binder.HandleElementEvents(parent);
1616

1717
var child = new MockElement("child");
18+
child.AutomationId = "child-automation-id";
1819

1920
// Act
2021
parent.RaiseEvent(eventName, new ElementEventArgs(child));
@@ -28,6 +29,7 @@ public void Element_ChildEvents_AddsBreadcrumb(string eventName)
2829
crumb.Data.Should().Contain($"{nameof(MockElement)}.Name", "parent");
2930
crumb.Data.Should().Contain("Element", nameof(MockElement));
3031
crumb.Data.Should().Contain("Element.Name", "child");
32+
crumb.Data.Should().Contain("Element.AutomationId", "child-automation-id");
3133
}
3234

3335
[Theory]

0 commit comments

Comments
 (0)