Fixed flaky test 'CanInfluenceHeadDuringPrerender'. (#24624)
This commit is contained in:
parent
9d783c5b76
commit
6c35e2e84d
|
|
@ -88,44 +88,31 @@ namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests
|
|||
{
|
||||
Navigate("/prerendered/prerendered-head");
|
||||
|
||||
var metaWithBindings = Browser.FindElement(By.Id("meta-with-bindings"));
|
||||
var metaNoBindings = Browser.FindElement(By.Id("meta-no-bindings"));
|
||||
|
||||
// Validate updated head during prerender
|
||||
Browser.Equal("Initial title", () => Browser.Title);
|
||||
Browser.Equal("Initial meta content", () => metaWithBindings.GetAttribute("content"));
|
||||
Browser.Equal("Immutable meta content", () => metaNoBindings.GetAttribute("content"));
|
||||
Browser.Equal("Initial meta content", () => GetMetaWithBindings().GetAttribute("content"));
|
||||
Browser.Equal("Immutable meta content", () => GetMetaWithoutBindings().GetAttribute("content"));
|
||||
|
||||
BeginInteractivity();
|
||||
|
||||
// Wait for elements to be recreated with internal ids to permit mutation
|
||||
metaWithBindings = WaitForNewElement(metaWithBindings, "meta-with-bindings");
|
||||
metaNoBindings = WaitForNewElement(metaNoBindings, "meta-no-bindings");
|
||||
// Wait until the component has rerendered
|
||||
Browser.Exists(By.Id("interactive-indicator"));
|
||||
|
||||
// Validate updated head after prerender
|
||||
Browser.Equal("Initial title", () => Browser.Title);
|
||||
Browser.Equal("Initial meta content", () => metaWithBindings.GetAttribute("content"));
|
||||
Browser.Equal("Immutable meta content", () => metaNoBindings.GetAttribute("content"));
|
||||
Browser.Equal("Initial meta content", () => GetMetaWithBindings().GetAttribute("content"));
|
||||
Browser.Equal("Immutable meta content", () => GetMetaWithoutBindings().GetAttribute("content"));
|
||||
|
||||
// Change parameter of meta component
|
||||
var inputMetaBinding = Browser.FindElement(By.Id("input-meta-binding"));
|
||||
inputMetaBinding.Clear();
|
||||
inputMetaBinding.SendKeys("Updated meta content\n");
|
||||
|
||||
// Wait for meta tag to be recreated with new attributes
|
||||
metaWithBindings = WaitForNewElement(metaWithBindings, "meta-with-bindings");
|
||||
|
||||
// Validate new meta content attribute
|
||||
Browser.Equal("Updated meta content", () => metaWithBindings.GetAttribute("content"));
|
||||
Browser.Equal("Updated meta content", () => GetMetaWithBindings().GetAttribute("content"));
|
||||
|
||||
IWebElement WaitForNewElement(IWebElement existingElement, string id)
|
||||
{
|
||||
var newElement = existingElement;
|
||||
|
||||
Browser.NotEqual(existingElement, () => newElement = Browser.FindElement(By.Id(id)) ?? newElement);
|
||||
|
||||
return newElement;
|
||||
}
|
||||
IWebElement GetMetaWithBindings() => Browser.FindElement(By.Id("meta-with-bindings"));
|
||||
IWebElement GetMetaWithoutBindings() => Browser.FindElement(By.Id("meta-no-bindings"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -23,7 +23,23 @@
|
|||
|
||||
<Meta id="meta-no-bindings" content="Immutable meta content" />
|
||||
|
||||
@if (isInteractive)
|
||||
{
|
||||
<span id="interactive-indicator">Interactive mode enabled.</span>
|
||||
}
|
||||
|
||||
@code {
|
||||
private string title = "Initial title";
|
||||
private string metaContent = "Initial meta content";
|
||||
|
||||
private bool isInteractive;
|
||||
|
||||
protected override void OnAfterRender(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
isInteractive = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue