Skip to content

Commit

Permalink
Fix Android Shell Navigation not properly waiting for end of transact…
Browse files Browse the repository at this point in the history
…ion (dotnet#26642)

* Fix Android Shell Navigation not properly waiting for end of transaction

* Fixes other random failing tests on Android
  • Loading branch information
albyrock87 authored Dec 15, 2024
1 parent d621121 commit f249086
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ protected virtual IShellObservableFragment GetOrCreateFragmentForTab(ShellSectio

protected virtual Task<bool> HandleFragmentUpdate(ShellNavigationSource navSource, ShellSection shellSection, Page page, bool animated)
{
TaskCompletionSource<bool> result = new TaskCompletionSource<bool>();
// We're using RunContinuationsAsynchronously because we don't want a subsequent navigation
// to start until the current one has finished.
// The AnimationFinished event is used to signal when the animation has completed,
// but that doesn't mean the fragment transaction has completed.
var result = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);

bool isForCurrentTab = shellSection == ShellSection;
bool initialUpdate = _fragmentMap.Count == 0;
if (!_fragmentMap.ContainsKey(ShellSection))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,34 @@ public Bugzilla42329(TestDevice testDevice) : base(testDevice)

[Test]
[Category(UITestCategories.ListView)]
public void MemoryLeakB42329()
public async Task MemoryLeakB42329()
{
App.WaitForElement(LabelPage1);
App.Tap(LabelPage1);

await WaitForFlyoutAnimation();
App.WaitForElement(Page2Title);
App.Tap(Page2Title);

await WaitForFlyoutAnimation();
App.WaitForElement(LabelPage2);
App.Tap(LabelPage2);

await WaitForFlyoutAnimation();
App.WaitForElement(Page3Title);
App.Tap(Page3Title);

#if ANDROID || WINDOWS //In random scenario, the destructor called upon the fourth navigation. So added one more navigation for Android and Windows to make this test work.
App.TapInFlyoutPageFlyout(Page2Title);
App.TapInFlyoutPageFlyout(Page3Title);
#endif
App.WaitForElement("Destructor called");
}

static async Task WaitForFlyoutAnimation()
{
// give it time to complete flyout animation
// sometimes the test runner is too fast and taps on wrong coordinates
await Task.Delay(100);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using System.Globalization;
using NUnit.Framework;
using NUnit.Framework.Legacy;
using UITest.Appium;
using UITest.Core;
Expand Down Expand Up @@ -39,6 +40,6 @@ public void WhenChangingBoxViewOpacityThenValueIsCorrectlySet()

string? GetCurrentOpacityStatus() => App.FindElement("CurrentOpacity").GetText();

string GetExpectedCurrentOpacityStatus(double expectedOpacity) => $"Current opacity is {expectedOpacity}";
string GetExpectedCurrentOpacityStatus(double expectedOpacity) => $"Current opacity is {expectedOpacity.ToString(CultureInfo.InvariantCulture)}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public void ValidateEntryClearButtonVisibilityBehavior()
App.Click("AddEntry");

// Click the new entry to see if there is the clear button or not. No such button should be present.
App.WaitForElement("Entry3");
App.Tap("Entry3");

VerifyScreenshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ public void FlyoutMenuShouldNotDisappearWhenNavigateUsingServices()
App.Tap("BackButton");
App.WaitForElement("Login");
App.Tap("Login");
#if ANDROID
App.Tap(AppiumQuery.ByXPath("//android.widget.ImageButton[@content-desc='Open navigation drawer']"));
#else
App.Tap(FlyoutIconAutomationId);
#endif
App.TapShellFlyoutIcon();
VerifyScreenshot();
}

Expand Down

0 comments on commit f249086

Please sign in to comment.