Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Microsoft.Maui.TestCases.Tests;

public class WebViewFeatureTests : _GalleryUITest
{
const int ApplyTapMaxAttempts = 3;
public const string WebViewFeatureMatrix = "WebView Feature Matrix";
public override string GalleryPageName => WebViewFeatureMatrix;
public const string Options = "Options";
Expand All @@ -28,6 +29,28 @@ public WebViewFeatureTests(TestDevice device)
{
}

public void TapApplyAndWaitForMainPage()
{
Exception? lastError = null;

for (var attempt = 1; attempt <= ApplyTapMaxAttempts; attempt++)
{
try
{
App.WaitForElement(Apply);
App.Tap(Apply);
App.WaitForElementTillPageNavigationSettled(Options);
return;
}
catch (Exception ex)
{
lastError = ex;
}
}

Assert.Fail($"Failed to tap '{Apply}' toolbar item and return to main page after {ApplyTapMaxAttempts} attempts. Last error: {lastError}");
}

[Test, Order(1)]
[Category(UITestCategories.WebView)]
public void WebView_ValidateDefaultValues_VerifyInitialState()
Expand All @@ -46,20 +69,15 @@ public void WebView_VerifyCanGoBackForward()
App.Tap(Options);
App.WaitForElement("HtmlSourceButton");
App.Tap("HtmlSourceButton");
App.WaitForElement(Apply);
App.Tap(Apply);
App.WaitForElement(Options);
TapApplyAndWaitForMainPage();
App.Tap(Options);
App.WaitForElement("MicrosoftUrlButton");
App.Tap("MicrosoftUrlButton");
App.WaitForElement(Apply);
App.Tap(Apply);
App.WaitForElement(Options);
TapApplyAndWaitForMainPage();
App.Tap(Options);
App.WaitForElement("GithubUrlButton");
App.Tap("GithubUrlButton");
App.WaitForElement(Apply);
App.Tap(Apply);
TapApplyAndWaitForMainPage();
App.WaitForElement(CanGoBackLabel, timeout: TimeSpan.FromSeconds(3));
Assert.That(App.FindElement(CanGoBackLabel).GetText(), Is.EqualTo("True"));
App.WaitForElement(GoBackButton);
Expand All @@ -78,8 +96,7 @@ public void WebView_SetHtmlSource_VerifyJavaScript()
App.Tap(Options);
App.WaitForElement(HtmlSourceButton);
App.Tap(HtmlSourceButton);
App.WaitForElement(Apply);
App.Tap(Apply);
TapApplyAndWaitForMainPage();
App.WaitForElement(EvaluateJSButton);
App.Tap(EvaluateJSButton);
App.WaitForElement(JSResultLabel);
Expand All @@ -95,9 +112,7 @@ public void WebView_SetUrlSource_VerifyNavigatingEvent()
App.Tap(Options);
App.WaitForElement(GithubUrlButton);
App.Tap(GithubUrlButton);
App.WaitForElement(Apply);
App.Tap(Apply);
App.WaitForElementTillPageNavigationSettled(Options);
TapApplyAndWaitForMainPage();
var navigatingText = App.FindElement(NavigatingStatusLabel).GetText();
Assert.That(navigatingText, Is.Not.Null.And.Not.Empty);
}
Expand All @@ -110,9 +125,7 @@ public void WebView_SetUrlSource_VerifyNavigatedEvent()
App.Tap(Options);
App.WaitForElement(GithubUrlButton);
App.Tap(GithubUrlButton);
App.WaitForElement(Apply);
App.Tap(Apply);
App.WaitForElementTillPageNavigationSettled(Options);
TapApplyAndWaitForMainPage();
var navigatedText = App.FindElement(NavigatedStatusLabel).GetText();
Assert.That(navigatedText, Is.EqualTo("Navigated: Success"));
}
Expand All @@ -125,9 +138,7 @@ public void WebView_SetHtmlSource_VerifyNavigatingEvent()
App.Tap(Options);
App.WaitForElement(HtmlSourceButton);
App.Tap(HtmlSourceButton);
App.WaitForElement(Apply);
App.Tap(Apply);
App.WaitForElementTillPageNavigationSettled(Options);
TapApplyAndWaitForMainPage();
var navigatingText = App.FindElement(NavigatingStatusLabel).GetText();
Assert.That(navigatingText, Is.Not.Null.And.Not.Empty);
}
Expand All @@ -140,9 +151,7 @@ public void WebView_SetHtmlSource_VerifyNavigatedEvent()
App.Tap(Options);
App.WaitForElement(HtmlSourceButton);
App.Tap(HtmlSourceButton);
App.WaitForElement(Apply);
App.Tap(Apply);
App.WaitForElementTillPageNavigationSettled(Options);
TapApplyAndWaitForMainPage();
var navigatedText = App.FindElement(NavigatedStatusLabel).GetText();
Assert.That(navigatedText, Is.EqualTo("Navigated: Success"));
}
Expand All @@ -157,9 +166,7 @@ public void WebView_TestCookieManagement_VerifyAddCookie()
App.Tap(AddTestCookieButton);
App.WaitForElement(HtmlSourceButton);
App.Tap(HtmlSourceButton);
App.WaitForElement(Apply);
App.Tap(Apply);
App.WaitForElementTillPageNavigationSettled(Options);
TapApplyAndWaitForMainPage();
var cookiesStatusText = App.FindElement(CookieStatusMainLabel).GetText();
Assert.That(cookiesStatusText, Does.Contain("Domain: localhost").And.Contain("Count: 1").And.Contain("DotNetMAUICookie = My cookie"));
}
Expand All @@ -174,9 +181,7 @@ public void WebView_TestCookieManagement_VerifyAddCookieWithUrlSource()
App.Tap(GithubUrlButton);
App.WaitForElement(AddTestCookieButton);
App.Tap(AddTestCookieButton);
App.WaitForElement(Apply);
App.Tap(Apply);
App.WaitForElementTillPageNavigationSettled(Options);
TapApplyAndWaitForMainPage();
var cookiesStatusText = App.FindElement(CookieStatusMainLabel).GetText();
Assert.That(cookiesStatusText, Does.Contain("Domain: github.com").And.Contain("Count: 1").And.Contain("DotNetMAUICookie = My cookie"));
}
Expand All @@ -191,9 +196,7 @@ public void WebView_TestCookieManagement_VerifyAddCookieAndEvaluateJavaScript()
App.Tap(AddTestCookieButton);
App.WaitForElement(HtmlSourceButton);
App.Tap(HtmlSourceButton);
App.WaitForElement(Apply);
App.Tap(Apply);
App.WaitForElementTillPageNavigationSettled(Options);
TapApplyAndWaitForMainPage();
App.WaitForElement(EvaluateJSButton);
App.Tap(EvaluateJSButton);
App.WaitForElement(JSResultLabel);
Expand All @@ -211,9 +214,7 @@ public void WebView_TestClearCookies_VerifyCookiesCleared()
App.Tap(Options);
App.WaitForElement(ClearCookiesButton);
App.Tap(ClearCookiesButton);
App.WaitForElement(Apply);
App.Tap(Apply);
App.WaitForElementTillPageNavigationSettled(Options);
TapApplyAndWaitForMainPage();
var clearCookiesText = App.FindElement(CookieStatusMainLabel).GetText();
Assert.That(clearCookiesText, Is.EqualTo("No cookies available."));
}
Expand All @@ -226,8 +227,7 @@ public void WebView_TestReloadMethod_VerifyReloadFunctionality()
App.Tap(Options);
App.WaitForElement(GithubUrlButton);
App.Tap(GithubUrlButton);
App.WaitForElement(Apply);
App.Tap(Apply);
TapApplyAndWaitForMainPage();
App.WaitForElement("ReloadButton");
App.Tap("ReloadButton");
var navigatedText = App.FindElement(NavigatedStatusLabel).GetText();
Expand All @@ -243,8 +243,7 @@ public void WebView_VerifyReloadFunctionalityForHtmlWebViewSource()
App.Tap(Options);
App.WaitForElement(HtmlSourceButton);
App.Tap(HtmlSourceButton);
App.WaitForElement(Apply);
App.Tap(Apply);
TapApplyAndWaitForMainPage();
App.WaitForElement("ReloadButton");
App.Tap("ReloadButton");
var navigatedText = App.FindElement(NavigatedStatusLabel).GetText();
Expand All @@ -260,8 +259,7 @@ public void WebView_TestEvaluateJavaScriptAsync_VerifyJavaScriptExecution()
App.Tap(Options);
App.WaitForElement("LoadPage1Button");
App.Tap("LoadPage1Button");
App.WaitForElement(Apply);
App.Tap(Apply);
TapApplyAndWaitForMainPage();
App.WaitForElement(EvaluateJSButton);
App.Tap(EvaluateJSButton);
App.WaitForElement(JSResultLabel);
Expand All @@ -277,8 +275,7 @@ public void WebView_TestEvaluateJavaScriptAsync_VerifyJavaScriptExecutionWithMul
App.Tap(Options);
App.WaitForElement("LoadMultiplePagesButton");
App.Tap("LoadMultiplePagesButton");
App.WaitForElement(Apply);
App.Tap(Apply);
TapApplyAndWaitForMainPage();
App.WaitForElement(EvaluateJSButton);
App.Tap(EvaluateJSButton);
App.WaitForElement(JSResultLabel);
Expand All @@ -296,9 +293,7 @@ public void WebView_SetIsVisibleFalse_VerifyWebViewHidden()
App.Tap(GithubUrlButton);
App.WaitForElement("IsVisibleFalse");
App.Tap("IsVisibleFalse");
App.WaitForElement(Apply);
App.Tap(Apply);
App.WaitForElementTillPageNavigationSettled(Options);
TapApplyAndWaitForMainPage();
App.WaitForNoElement(WebViewControl);
}

Expand All @@ -311,9 +306,7 @@ public void VerifyWebViewWithShadow()
App.Tap(Options);
App.WaitForElement("ShadowTrue");
App.Tap("ShadowTrue");
App.WaitForElement(Apply);
App.Tap(Apply);
App.WaitForElementTillPageNavigationSettled(Options, timeout: TimeSpan.FromSeconds(3));
TapApplyAndWaitForMainPage();
VerifyScreenshot(tolerance: 0.5, retryTimeout: TimeSpan.FromSeconds(2));
}
#endif
Expand Down
Loading