Skip to content

Commit

Permalink
[UITesting, Catalyst] Fixed DragAndDropUITests to be more reliable (#…
Browse files Browse the repository at this point in the history
…25146)

* [UITesting, Catalyst] Fixed DragAndDropUITests to be more reliable

* updated code changes

* Modified code changes

* Modified code changes

* Modified test cases

* Modified the test cases

* Addressed a review changes

* Modified a test cases

* Added missing changes

* Modified a drop test cases

* Fix the UI test case failure

---------

Co-authored-by: Shalini-Ashokan <[email protected]>
  • Loading branch information
NirmalKumarYuvaraj and Shalini-Ashokan authored Dec 9, 2024
1 parent bdf5a9a commit a02e7f6
Show file tree
Hide file tree
Showing 7 changed files with 284 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,15 @@
</StackLayout>
</ScrollView>
</Grid>
<Label x:Name="events" AutomationId="DragEventsLabel" Text="EventsLabel: "/>
<!-- DragStarting Labels-->

<Label x:Name="dragStartEvent" AutomationId="DragStartEventsLabel" Text="DragStartEvents: "/>
<Label x:Name="dragOverEvent" AutomationId="DragOverEventsLabel" Text="DragOverEvents: "/>
<Label x:Name="dragCompletedEvent" AutomationId="DragCompletedEventsLabel" Text="DragCompletedEvents: "/>
<Label x:Name="dragLeaveEvent" AutomationId="DragLeaveEventsLabel" Text="DragLeaveEvents: "/>
<Label x:Name="ranibowColors" AutomationId="RainBowColorsLabel" Text="RainbowColorsAdd: "/>
<Label x:Name="dropEvent" AutomationId="DropEventsLabel" Text="DropEvents: "/>

<!-- DragStarting Labels-->
<Label x:Name="dragStartRelativeSelf" AutomationId="DragStartRelativeSelf" Text="Drag Start relative to self:"/>
<Label x:Name="dragStartRelativeScreen" AutomationId="DragStartRelativeScreen" Text="Drag Start relative to screen:"/>
<Label x:Name="dragStartRelativeLabel" AutomationId="DragStartRelativeLabel" Text="Drag Start relative to this label:"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ public DragAndDropBetweenLayouts()
InitializeComponent();
}

void AddEvent(string name)
{
events.Text += $"{name},";
}

void OnDragStarting(object sender, DragStartingEventArgs e)
{
_emittedDragOver = false;
Expand All @@ -30,7 +25,7 @@ void OnDragStarting(object sender, DragStartingEventArgs e)
else
SLAllColors.Background = SolidColorBrush.LightBlue;

AddEvent(nameof(OnDragStarting));
dragStartEvent.Text = "DragStarting";

dragStartRelativeSelf.Text = $"Drag Start relative to self: {(int)e.GetPosition(label).Value.X},{(int)e.GetPosition(label).Value.Y}";
dragStartRelativeScreen.Text = $"Drag Start relative to screen: {(int)e.GetPosition(null).Value.X},{(int)e.GetPosition(null).Value.Y}";
Expand All @@ -46,7 +41,7 @@ void OnDropCompleted(object sender, DropCompletedEventArgs e)
else
SLAllColors.Background = SolidColorBrush.White;

AddEvent(nameof(OnDropCompleted));
dragCompletedEvent.Text = "DropCompleted";
}

void OnDragOver(object sender, DragEventArgs e)
Expand All @@ -66,7 +61,7 @@ void OnDragOver(object sender, DragEventArgs e)

if (!_emittedDragOver) // This can generate a lot of noise, only add it once
{
AddEvent(nameof(OnDragOver));
dragOverEvent.Text = "DragOver";
_emittedDragOver = true;
}

Expand All @@ -89,7 +84,7 @@ void OnDragLeave(object sender, DragEventArgs e)

sl.Background = SolidColorBrush.LightBlue;

AddEvent(nameof(OnDragLeave));
dragLeaveEvent.Text= "DragLeave";
}

void OnDrop(object sender, DropEventArgs e)
Expand All @@ -109,13 +104,12 @@ void OnDrop(object sender, DropEventArgs e)
{
SLAllColors.Children.Remove(color);
SLRainbow.Children.Add(color);
AddEvent($"RainbowColorsAdd:{color.Text}");
ranibowColors.Text = $"RainbowColorsAdd:{color.Text}";
}
else
{
SLRainbow.Children.Remove(color);
SLAllColors.Children.Add(color);
AddEvent($"AllColorsAdd:{color.Text}");
}

dropRelativeLayout.Text = $"Drop relative to receiving layout: {(int)e.GetPosition(sl).Value.X},{(int)e.GetPosition(sl).Value.Y}";
Expand All @@ -125,7 +119,7 @@ void OnDrop(object sender, DropEventArgs e)
SLAllColors.Background = SolidColorBrush.White;
SLRainbow.Background = SolidColorBrush.White;

AddEvent(nameof(OnDrop));
dropEvent.Text = "Drop";
}

void ResetLayouts(object sender, System.EventArgs e)
Expand Down Expand Up @@ -166,7 +160,11 @@ Label RegenerateColorLabel(string color)

void ResetTestLabels()
{
events.Text = "EventsLabel: ";
dragStartEvent.Text = "DragStartEvents: ";
dragOverEvent.Text = "DragOverEvents: ";
dragCompletedEvent.Text = "DragCompletedEvents: ";
ranibowColors.Text = "RainbowColorsAdd: ";
dropEvent.Text = "DropEvents: ";

dragStartRelativeSelf.Text = "Drag Start relative to self:";
dragStartRelativeScreen.Text = "Drag Start relative to screen:";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
</Label.GestureRecognizers>
</Label>
</StackLayout>
<Label x:Name="events" AutomationId="DragEventsLabel" Text="EventsLabel">
<Label.GestureRecognizers>
<DropGestureRecognizer></DropGestureRecognizer>
</Label.GestureRecognizers>
</Label>
</StackLayout>

<Label x:Name="dragStartEvent" AutomationId="DragStartEventsLabel" Text="DragStartEvents: "/>
<Label x:Name="dragOverEvent" AutomationId="DragOverEventsLabel" Text="DragOverEvents: "/>
<Label x:Name="dragLeaveEvent" AutomationId="DragLeaveEventsLabel" Text="DragLeaveEvents: "/>
<Label x:Name="dropEvent" AutomationId="DropEventsLabel" Text="DropEventsLabel: "/>
<Label x:Name="dropCompletedEvent" AutomationId="DropCompletedEventsLabel" Text="DropCompletedEvents: "/>
</StackLayout>
</ContentView>
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,29 @@ public DragAndDropEventArgs()
InitializeComponent();
}

void AddEvent(string name)
{
events.Text += $"{name},";
}

void DragStarting(object sender, DragStartingEventArgs e)
{
_emittedDragOver = false;
if (e.PlatformArgs is PlatformDragStartingEventArgs platformArgs)
{
#if IOS || MACCATALYST
if (platformArgs.Sender is not null)
AddEvent("DragStarting:" + nameof(platformArgs.Sender));
dragStartEvent.Text += $"{"DragStarting:" + nameof(platformArgs.Sender)},";
if (platformArgs.DragInteraction is not null)
AddEvent("DragStarting:" + nameof(platformArgs.DragInteraction));
dragStartEvent.Text += $"{"DragStarting:" + nameof(platformArgs.DragInteraction)},";
if (platformArgs.DragSession is not null)
AddEvent("DragStarting:" + nameof(platformArgs.DragSession));
dragStartEvent.Text += $"{"DragStarting:" + nameof(platformArgs.DragSession)},";
#elif ANDROID
if (platformArgs.Sender is not null)
AddEvent("DragStarting:" + nameof(platformArgs.Sender));
dragStartEvent.Text += $"{"DragStarting:" + nameof(platformArgs.Sender)},";
if (platformArgs.MotionEvent is not null)
AddEvent("DragStarting:" + nameof(platformArgs.MotionEvent));
dragStartEvent.Text += $"{"DragStarting:" + nameof(platformArgs.MotionEvent)},";
#elif WINDOWS
if (platformArgs.Sender is not null)
AddEvent("DragStarting:" + nameof(platformArgs.Sender));
dragStartEvent.Text += $"{"DragStarting:" + nameof(platformArgs.Sender)},";
if (platformArgs.DragStartingEventArgs is not null)
AddEvent("DragStarting:" + nameof(platformArgs.DragStartingEventArgs));
AddEvent("DragStarting:" + nameof(platformArgs.Handled));
dragStartEvent.Text += $"{"DragStarting:" + nameof(platformArgs.DragStartingEventArgs)},";
dragStartEvent.Text += $"{"DragStarting:" + nameof(platformArgs.Handled)},";
#endif
}
}
Expand All @@ -46,21 +41,21 @@ void DropCompleted(object sender, DropCompletedEventArgs e)
{
#if IOS || MACCATALYST
if (platformArgs.Sender is not null)
AddEvent("DropCompleted:" + nameof(platformArgs.Sender));
dropCompletedEvent.Text += $"{"DropCompleted:" + nameof(platformArgs.Sender)},";
if (platformArgs.DropInteraction is not null)
AddEvent("DropCompleted:" + nameof(platformArgs.DropInteraction));
dropCompletedEvent.Text += $"{"DropCompleted:" + nameof(platformArgs.DropInteraction)},";
if (platformArgs.DropSession is not null)
AddEvent("DropCompleted:" + nameof(platformArgs.DropSession));
dropCompletedEvent.Text += $"{"DropCompleted:" + nameof(platformArgs.DropSession)},";
#elif ANDROID
if (platformArgs.Sender is not null)
AddEvent("DropCompleted:" + nameof(platformArgs.Sender));
dropCompletedEvent.Text += $"{"DropCompleted:" + nameof(platformArgs.Sender)},";
if (platformArgs.DragEvent is not null)
AddEvent("DropCompleted:" + nameof(platformArgs.DragEvent));
dropCompletedEvent.Text += $"{"DropCompleted:" + nameof(platformArgs.DragEvent)},";
#elif WINDOWS
if (platformArgs.Sender is not null)
AddEvent("DropCompleted:" + nameof(platformArgs.Sender));
dropCompletedEvent.Text += $"{"DropCompleted:" + nameof(platformArgs.Sender)},";
if (platformArgs.DropCompletedEventArgs is not null)
AddEvent("DropCompleted:" + nameof(platformArgs.DropCompletedEventArgs));
dropCompletedEvent.Text += $"{"DropCompleted:" + nameof(platformArgs.DropCompletedEventArgs)},";
#endif
}
}
Expand All @@ -71,22 +66,22 @@ void DragLeave(object sender, DragEventArgs e)
{
#if IOS || MACCATALYST
if (platformArgs.Sender is not null)
AddEvent("DragLeave:" + nameof(platformArgs.Sender));
dragLeaveEvent.Text += $"{"DragLeave:" + nameof(platformArgs.Sender)},";
if (platformArgs.DropInteraction is not null)
AddEvent("DragLeave:" + nameof(platformArgs.DropInteraction));
dragLeaveEvent.Text += $"{"DragLeave:" + nameof(platformArgs.DropInteraction)},";
if (platformArgs.DropSession is not null)
AddEvent("DragLeave:" + nameof(platformArgs.DropSession));
dragLeaveEvent.Text += $"{"DragLeave:" + nameof(platformArgs.DropSession)},";
#elif ANDROID
if (platformArgs.Sender is not null)
AddEvent("DragLeave:" + nameof(platformArgs.Sender));
dragLeaveEvent.Text += $"{"DragLeave:" + nameof(platformArgs.Sender)},";
if (platformArgs.DragEvent is not null)
AddEvent("DragLeave:" + nameof(platformArgs.DragEvent));
dragLeaveEvent.Text += $"{"DragLeave:" + nameof(platformArgs.DragEvent)},";
#elif WINDOWS
if (platformArgs.Sender is not null)
AddEvent("DragLeave:" + nameof(platformArgs.Sender));
dragLeaveEvent.Text += $"{"DragLeave:" + nameof(platformArgs.Sender)},";
if (platformArgs.DragEventArgs is not null)
AddEvent("DragLeave:" + nameof(platformArgs.DragEventArgs));
AddEvent("DragLeave:" + nameof(platformArgs.Handled));
dragLeaveEvent.Text += $"{"DragLeave:" + nameof(platformArgs.DragEventArgs)},";
dragLeaveEvent.Text += $"{"DragLeave:" + nameof(platformArgs.Handled)},";
#endif
}
}
Expand All @@ -99,21 +94,21 @@ void DragOver(object sender, DragEventArgs e)
{
#if IOS || MACCATALYST
if (platformArgs.Sender is not null)
AddEvent("DragOver:" + nameof(platformArgs.Sender));
dragOverEvent.Text += $"{"DragOver:" + nameof(platformArgs.Sender)},";
if (platformArgs.DropInteraction is not null)
AddEvent("DragOver:" + nameof(platformArgs.DropInteraction));
dragOverEvent.Text += $"{"DragOver:" + nameof(platformArgs.DropInteraction)},";
if (platformArgs.DropSession is not null)
AddEvent("DragOver:" + nameof(platformArgs.DropSession));
dragOverEvent.Text += $"{"DragOver:" + nameof(platformArgs.DropSession)},";
#elif ANDROID
if (platformArgs.Sender is not null)
AddEvent("DragOver:" + nameof(platformArgs.Sender));
dragOverEvent.Text += $"{"DragOver:" + nameof(platformArgs.Sender)},";
if (platformArgs.DragEvent is not null)
AddEvent("DragOver:" + nameof(platformArgs.DragEvent));
dragOverEvent.Text += $"{"DragOver:" + nameof(platformArgs.DragEvent)},";
#elif WINDOWS
if (platformArgs.Sender is not null)
AddEvent("DragOver:" + nameof(platformArgs.Sender));
dragOverEvent.Text += $"{"DragOver:" + nameof(platformArgs.Sender)},";
if (platformArgs.DragEventArgs is not null)
AddEvent("DragOver:" + nameof(platformArgs.DragEventArgs));
dragOverEvent.Text += $"{"DragOver:" + nameof(platformArgs.DragEventArgs)},";
#endif
}
_emittedDragOver = true;
Expand All @@ -126,21 +121,21 @@ void Drop(object sender, DropEventArgs e)
{
#if IOS || MACCATALYST
if (platformArgs.Sender is not null)
AddEvent("Drop:" + nameof(platformArgs.Sender));
dropEvent.Text += $"{"Drop:" + nameof(platformArgs.Sender)},";
if (platformArgs.DropInteraction is not null)
AddEvent("Drop:" + nameof(platformArgs.DropInteraction));
dropEvent.Text += $"{"Drop:" + nameof(platformArgs.DropInteraction)},";
if (platformArgs.DropSession is not null)
AddEvent("Drop:" + nameof(platformArgs.DropSession));
dropEvent.Text += $"{"Drop:" + nameof(platformArgs.DropSession)},";
#elif ANDROID
if (platformArgs.Sender is not null)
AddEvent("Drop:" + nameof(platformArgs.Sender));
dropEvent.Text += $"{"Drop:" + nameof(platformArgs.Sender)},";
if (platformArgs.DragEvent is not null)
AddEvent("Drop:" + nameof(platformArgs.DragEvent));
dropEvent.Text += $"{"Drop:" + nameof(platformArgs.DragEvent)},";
#elif WINDOWS
if (platformArgs.Sender is not null)
AddEvent("Drop:" + nameof(platformArgs.Sender));
dropEvent.Text += $"{"Drop:" + nameof(platformArgs.Sender)},";
if (platformArgs.DragEventArgs is not null)
AddEvent("Drop:" + nameof(platformArgs.DragEventArgs));
dropEvent.Text += $"{"Drop:" + nameof(platformArgs.DragEventArgs)},";
#endif
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
</Label.GestureRecognizers>
</Label>
</StackLayout>
<Label x:Name="events" AutomationId="DragEventsLabel" Text="EventsLabel">
<Label.GestureRecognizers>
<DropGestureRecognizer></DropGestureRecognizer>
</Label.GestureRecognizers>
</Label>
</StackLayout>

<Label x:Name="dragStartEvent" AutomationId="DragStartEventsLabel" Text="DragStartEvents: "/>
<Label x:Name="dragOverEvent" AutomationId="DragOverEventsLabel" Text="DragOverEvents: "/>
<Label x:Name="dragCompletedEvent" AutomationId="DragCompletedEventsLabel" Text="DragCompletedEvents: "/>
<Label x:Name="dragLeaveEvent" AutomationId="DragLeaveEventsLabel" Text="DragLeaveEvents: "/>
<Label x:Name="dropEvent" AutomationId="DropEventsLabel" Text="DropEvents: "/>
</StackLayout>
</ContentView>
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,34 @@ public DragAndDropEvents()
InitializeComponent();
}

void AddEvent(string name)
{
events.Text += $"{name},";
}

void DragStarting(object sender, DragStartingEventArgs e)
{
_emittedDragOver = false;
AddEvent(nameof(DragStarting));
dragStartEvent.Text = "DragStarting";
}

void DropCompleted(object sender, DropCompletedEventArgs e)
{
AddEvent(nameof(DropCompleted));
dragCompletedEvent.Text = "DropCompleted";
}

void DragLeave(object sender, DragEventArgs e)
{
AddEvent(nameof(DragLeave));
dragLeaveEvent.Text = "DragLeave";
}

void DragOver(object sender, DragEventArgs e)
{
if (!_emittedDragOver) // This can generate a lot of noise, only add it once
{
AddEvent(nameof(DragOver));
dragOverEvent.Text = "DragOver";
_emittedDragOver = true;
}
}

void Drop(object sender, DropEventArgs e)
{
AddEvent(nameof(Drop));
dropEvent.Text = "Drop";
}
}
}
Loading

0 comments on commit a02e7f6

Please sign in to comment.