Skip to content
代码片段 群组 项目
未验证 提交 91a6fcc9 编辑于 作者: Steve Sanderson's avatar Steve Sanderson 提交者: GitHub
浏览文件

Improve reliability of globalization E2E tests (#13678)

上级 43e232d5
No related branches found
No related tags found
无相关合并请求
......@@ -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);
}
}
}
......@@ -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"));
......
......@@ -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);
}
}
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");
}
}
}
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册