Improve reliability of globalization E2E tests (#13678)

This commit is contained in:
Steve Sanderson 2019-09-06 16:20:14 +01:00 committed by GitHub
parent 43e232d5d5
commit 91a6fcc93d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 33 deletions

View File

@ -41,16 +41,7 @@ namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests
public void CanSetCultureAndParseCultueSensitiveNumbersAndDates(string culture)
{
var cultureInfo = CultureInfo.GetCultureInfo(culture);
var selector = new SelectElement(Browser.FindElement(By.Id("culture-selector")));
selector.SelectByValue(culture);
// That should have triggered a redirect, wait for the main test selector to come up.
MountTestComponent<GlobalizationBindCases>();
WaitUntilExists(By.Id("globalization-cases"));
var cultureDisplay = WaitUntilExists(By.Id("culture-name-display"));
Assert.Equal($"Culture is: {culture}", cultureDisplay.Text);
SetCulture(culture);
// int
var input = Browser.FindElement(By.Id("input_type_text_int"));
@ -113,16 +104,7 @@ namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests
public void CanSetCultureAndParseCultureInvariantNumbersAndDatesWithInputFields(string culture)
{
var cultureInfo = CultureInfo.GetCultureInfo(culture);
var selector = new SelectElement(Browser.FindElement(By.Id("culture-selector")));
selector.SelectByValue(culture);
// That should have triggered a redirect, wait for the main test selector to come up.
MountTestComponent<GlobalizationBindCases>();
WaitUntilExists(By.Id("globalization-cases"));
var cultureDisplay = WaitUntilExists(By.Id("culture-name-display"));
Assert.Equal($"Culture is: {culture}", cultureDisplay.Text);
SetCulture(culture);
// int
var input = Browser.FindElement(By.Id("input_type_number_int"));
@ -179,16 +161,7 @@ namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests
public void CanSetCultureAndParseCultureInvariantNumbersAndDatesWithFormComponents(string culture)
{
var cultureInfo = CultureInfo.GetCultureInfo(culture);
var selector = new SelectElement(Browser.FindElement(By.Id("culture-selector")));
selector.SelectByValue(culture);
// That should have triggered a redirect, wait for the main test selector to come up.
MountTestComponent<GlobalizationBindCases>();
WaitUntilExists(By.Id("globalization-cases"));
var cultureDisplay = WaitUntilExists(By.Id("culture-name-display"));
Assert.Equal($"Culture is: {culture}", cultureDisplay.Text);
SetCulture(culture);
// int
var input = Browser.FindElement(By.Id("inputnumber_int"));
@ -247,5 +220,21 @@ namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests
element.SendKeys(Keys.Control + "a");
element.SendKeys(text);
}
private void SetCulture(string culture)
{
var selector = new SelectElement(Browser.FindElement(By.Id("culture-selector")));
selector.SelectByValue(culture);
// Click the link to return back to the test page
WaitUntilExists(By.ClassName("return-from-culture-setter")).Click();
// That should have triggered a page load, so wait for the main test selector to come up.
MountTestComponent<GlobalizationBindCases>();
WaitUntilExists(By.Id("globalization-cases"));
var cultureDisplay = WaitUntilExists(By.Id("culture-name-display"));
Assert.Equal($"Culture is: {culture}", cultureDisplay.Text);
}
}
}

View File

@ -40,7 +40,10 @@ namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests
var selector = new SelectElement(Browser.FindElement(By.Id("culture-selector")));
selector.SelectByValue(culture);
// That should have triggered a redirect, wait for the main test selector to come up.
// Click the link to return back to the test page
WaitUntilExists(By.ClassName("return-from-culture-setter")).Click();
// That should have triggered a page load, so wait for the main test selector to come up.
MountTestComponent<LocalizedText>();
var cultureDisplay = WaitUntilExists(By.Id("culture-name-display"));

View File

@ -12,7 +12,7 @@
{
// Included fragment to preserve choice of Blazor client or server.
var redirect = new Uri(NavigationManager.Uri).GetComponents(UriComponents.PathAndQuery | UriComponents.Fragment, UriFormat.UriEscaped);
var query = $"?culture={Uri.EscapeDataString((string)e.Value)}&redirectUri={redirect}";
var query = $"?culture={Uri.EscapeDataString((string)e.Value)}&redirectUri={Uri.EscapeDataString(redirect)}";
NavigationManager.NavigateTo("/Culture/SetCulture" + query, forceLoad: true);
}
}

View File

@ -1,5 +1,8 @@
using System.Text.Encodings.Web;
using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Net.Http.Headers;
namespace Components.TestServer.Controllers
{
@ -15,7 +18,10 @@ namespace Components.TestServer.Controllers
CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(culture)));
}
return LocalRedirect(redirectUri);
var htmlEncoder = HtmlEncoder.Default;
var html = $"<h1>Culture has been changed to {htmlEncoder.Encode(culture)}</h1>" +
$"<a class='return-from-culture-setter' href='{htmlEncoder.Encode(redirectUri)}'>Return to previous page</a>";
return Content(html, "text/html");
}
}
}