Skip to content

Use assertion library more consistently #26519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
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 @@ -15,7 +15,7 @@ public static IWebElement MountTestComponent<TComponent>(this IWebDriver browser
var testSelector = browser.WaitUntilTestSelectorReady();
testSelector.SelectByValue("none");
testSelector.SelectByValue(componentTypeName);
return browser.FindElement(By.TagName("app"));
return browser.Exists(By.TagName("app"));
}

public static SelectElement WaitUntilTestSelectorReady(this IWebDriver browser)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected override void InitializeAsyncCore()
{
Navigate(ServerPathBase, noReload: false);
Browser.MountTestComponent<GracefulTermination>();
Browser.Equal("Graceful Termination", () => Browser.FindElement(By.TagName("h1")).Text);
Browser.Equal("Graceful Termination", () => Browser.Exists(By.TagName("h1")).Text);

GracefulDisconnectCompletionSource = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
Sink = _serverFixture.Host.Services.GetRequiredService<TestSink>();
Expand Down Expand Up @@ -95,7 +95,7 @@ public async Task ClosingTheBrowserWindow_GracefullyDisconnects_WhenNavigatingAw
public async Task NavigatingToProtocolLink_DoesNotGracefullyDisconnect_TheCurrentCircuit()
{
// Arrange & Act
var element = Browser.FindElement(By.Id("mailto-link"));
var element = Browser.Exists(By.Id("mailto-link"));
element.Click();
await Task.WhenAny(Task.Delay(10000), GracefulDisconnectCompletionSource.Task);

Expand All @@ -108,7 +108,7 @@ public async Task NavigatingToProtocolLink_DoesNotGracefullyDisconnect_TheCurren
public async Task DownloadAction_DoesNotGracefullyDisconnect_TheCurrentCircuit()
{
// Arrange & Act
var element = Browser.FindElement(By.Id("download-link"));
var element = Browser.Exists(By.Id("download-link"));
element.Click();
await Task.WhenAny(Task.Delay(10000), GracefulDisconnectCompletionSource.Task);

Expand All @@ -121,7 +121,7 @@ public async Task DownloadAction_DoesNotGracefullyDisconnect_TheCurrentCircuit()
public async Task DownloadHref_DoesNotGracefullyDisconnect_TheCurrentCircuit()
{
// Arrange & Act
var element = Browser.FindElement(By.Id("download-href"));
var element = Browser.Exists(By.Id("download-href"));
element.Click();
await Task.WhenAny(Task.Delay(10000), GracefulDisconnectCompletionSource.Task);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public void PassingParametersToComponentsFromThePageWorks()

Browser.Exists(By.CssSelector(".interactive"));

var parameter1 = Browser.FindElement(By.CssSelector(".Param1"));
var parameter1 = Browser.Exists(By.CssSelector(".Param1"));
Assert.Equal(100, parameter1.FindElements(By.CssSelector("li")).Count);
Assert.Equal("99 99", parameter1.FindElement(By.CssSelector("li:last-child")).Text);

// The assigned value is of a more derived type than the declared model type. This check
// verifies we use the actual model type during round tripping.
var parameter2 = Browser.FindElement(By.CssSelector(".Param2"));
var parameter2 = Browser.Exists(By.CssSelector(".Param2"));
Assert.Equal("Value Derived-Value", parameter2.Text);

// This check verifies CaptureUnmatchedValues works
Expand All @@ -54,7 +54,7 @@ public void PassingParametersToComponentsFromThePageWorks()

private void BeginInteractivity()
{
Browser.FindElement(By.Id("load-boot-script")).Click();
Browser.Exists(By.Id("load-boot-script")).Click();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void CanRenderMultipleRootComponents()
{
Navigate("/multiple-components");

Browser.Exists(By.CssSelector(".greet-wrapper .greet"));
var greets = Browser.FindElements(By.CssSelector(".greet-wrapper .greet")).Select(e => e.Text).ToArray();

Assert.Equal(7, greets.Length); // 1 statically rendered + 5 prerendered + 1 server prerendered
Expand All @@ -73,7 +74,7 @@ public void CanRenderMultipleRootComponents()
Assert.Single(greets, "Hello Abraham");
Assert.Equal(2, greets.Where(g => g == "Hello Blue fish").Count());
Assert.Equal(3, greets.Where(g => string.Equals("Hello", g)).Count()); // 3 server prerendered without parameters
var content = Browser.FindElement(By.Id("test-container")).GetAttribute("innerHTML");
var content = Browser.Exists(By.Id("test-container")).GetAttribute("innerHTML");
var markers = ReadMarkers(content);
var componentSequence = markers.Select(m => m.Item1.PrerenderId != null).ToArray();
var expectedComponentSequence = new bool[]
Expand Down Expand Up @@ -123,7 +124,7 @@ public void CanRenderMultipleRootComponents()

private void BeginInteractivity()
{
Browser.FindElement(By.Id("load-boot-script")).Click();
Browser.Exists(By.Id("load-boot-script")).Click();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public void CanTransitionFromPrerenderedToInteractiveMode()
Navigate("/prerendered/prerendered-transition");

// Prerendered output shows "not connected"
Browser.Equal("not connected", () => Browser.FindElement(By.Id("connected-state")).Text);
Browser.Equal("not connected", () => Browser.Exists(By.Id("connected-state")).Text);

// Once connected, output changes
BeginInteractivity();
Browser.Equal("connected", () => Browser.FindElement(By.Id("connected-state")).Text);
Browser.Equal("connected", () => Browser.Exists(By.Id("connected-state")).Text);

// ... and now the counter works
Browser.FindElement(By.Id("increment-count")).Click();
Browser.Equal("1", () => Browser.FindElement(By.Id("count")).Text);
Browser.Exists(By.Id("increment-count")).Click();
Browser.Equal("1", () => Browser.Exists(By.Id("count")).Text);
}

[Fact]
Expand All @@ -51,7 +51,7 @@ public void PrerenderingWaitsForAsyncDisposableComponents()
Navigate("/prerendered/prerendered-async-disposal");

// Prerendered output shows "not connected"
Browser.Equal("After async disposal", () => Browser.FindElement(By.Id("disposal-message")).Text);
Browser.Equal("After async disposal", () => Browser.Exists(By.Id("disposal-message")).Text);
}

[Fact]
Expand All @@ -60,22 +60,22 @@ public void CanUseJSInteropFromOnAfterRenderAsync()
Navigate("/prerendered/prerendered-interop");

// Prerendered output can't use JSInterop
Browser.Equal("No value yet", () => Browser.FindElement(By.Id("val-get-by-interop")).Text);
Browser.Equal(string.Empty, () => Browser.FindElement(By.Id("val-set-by-interop")).GetAttribute("value"));
Browser.Equal("No value yet", () => Browser.Exists(By.Id("val-get-by-interop")).Text);
Browser.Equal(string.Empty, () => Browser.Exists(By.Id("val-set-by-interop")).GetAttribute("value"));

BeginInteractivity();

// Once connected, we can
Browser.Equal("Hello from interop call", () => Browser.FindElement(By.Id("val-get-by-interop")).Text);
Browser.Equal("Hello from interop call", () => Browser.FindElement(By.Id("val-set-by-interop")).GetAttribute("value"));
Browser.Equal("Hello from interop call", () => Browser.Exists(By.Id("val-get-by-interop")).Text);
Browser.Equal("Hello from interop call", () => Browser.Exists(By.Id("val-set-by-interop")).GetAttribute("value"));
}

[Fact]
public void IsCompatibleWithLazyLoadWebAssembly()
{
Navigate("/prerendered/WithLazyAssembly");

var button = Browser.FindElement(By.Id("use-package-button"));
var button = Browser.Exists(By.Id("use-package-button"));

button.Click();

Expand All @@ -93,13 +93,13 @@ public void CanReadUrlHashOnlyOnceConnected()
Navigate(url);
Browser.Equal(
_serverFixture.RootUri + urlWithoutHash,
() => Browser.FindElement(By.TagName("strong")).Text);
() => Browser.Exists(By.TagName("strong")).Text);

// Once connected, you do have access to the full URL
BeginInteractivity();
Browser.Equal(
_serverFixture.RootUri + url,
() => Browser.FindElement(By.TagName("strong")).Text);
() => Browser.Exists(By.TagName("strong")).Text);
}

[Theory]
Expand Down Expand Up @@ -130,17 +130,17 @@ public void CanAccessAuthenticationStateDuringStaticPrerendering(string initialU
// See that the authentication state is usable during the initial prerendering
SignInAs(initialUsername, null);
Navigate("/prerendered/prerendered-transition");
Browser.Equal($"Hello, {initialUsername ?? "anonymous"}!", () => Browser.FindElement(By.TagName("h1")).Text);
Browser.Equal($"Hello, {initialUsername ?? "anonymous"}!", () => Browser.Exists(By.TagName("h1")).Text);

// See that during connection, we update to whatever the latest authentication state now is
SignInAs(interactiveUsername, null, useSeparateTab: true);
BeginInteractivity();
Browser.Equal($"Hello, {interactiveUsername ?? "anonymous"}!", () => Browser.FindElement(By.TagName("h1")).Text);
Browser.Equal($"Hello, {interactiveUsername ?? "anonymous"}!", () => Browser.Exists(By.TagName("h1")).Text);
}

private void BeginInteractivity()
{
Browser.FindElement(By.Id("load-boot-script")).Click();
Browser.Exists(By.Id("load-boot-script")).Click();
}

private void AssertLogDoesNotContainCriticalMessages(params string[] messages)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ protected override void InitializeAsyncCore()
public void LocalStoragePersistsOnRefresh()
{
// Local storage initially cleared
var incrementLocalButton = Browser.FindElement(By.Id("increment-local"));
var localCount = Browser.FindElement(By.Id("local-count"));
var incrementLocalButton = Browser.Exists(By.Id("increment-local"));
var localCount = Browser.Exists(By.Id("local-count"));
Browser.Equal("0", () => localCount.Text);

// Local storage updates
Expand All @@ -55,16 +55,16 @@ public void LocalStoragePersistsOnRefresh()
Browser.Navigate().Refresh();
Browser.MountTestComponent<ProtectedBrowserStorageUsageComponent>();

localCount = Browser.FindElement(By.Id("local-count"));
localCount = Browser.Exists(By.Id("local-count"));
Browser.Equal("1", () => localCount.Text);
}

[Fact]
public void LocalStoragePersistsAcrossTabs()
{
// Local storage initially cleared
var incrementLocalButton = Browser.FindElement(By.Id("increment-local"));
var localCount = Browser.FindElement(By.Id("local-count"));
var incrementLocalButton = Browser.Exists(By.Id("increment-local"));
var localCount = Browser.Exists(By.Id("local-count"));
Browser.Equal("0", () => localCount.Text);

// Local storage updates in current tab
Expand All @@ -73,16 +73,16 @@ public void LocalStoragePersistsAcrossTabs()

// Local storage persists across tabs
OpenNewSession();
localCount = Browser.FindElement(By.Id("local-count"));
localCount = Browser.Exists(By.Id("local-count"));
Browser.Equal("1", () => localCount.Text);
}

[Fact]
public void SessionStoragePersistsOnRefresh()
{
// Session storage initially cleared
var incrementSessionButton = Browser.FindElement(By.Id("increment-session"));
var sessionCount = Browser.FindElement(By.Id("session-count"));
var incrementSessionButton = Browser.Exists(By.Id("increment-session"));
var sessionCount = Browser.Exists(By.Id("session-count"));
Browser.Equal("0", () => sessionCount.Text);

// Session storage updates
Expand All @@ -93,16 +93,16 @@ public void SessionStoragePersistsOnRefresh()
Browser.Navigate().Refresh();
Browser.MountTestComponent<ProtectedBrowserStorageUsageComponent>();

sessionCount = Browser.FindElement(By.Id("session-count"));
sessionCount = Browser.Exists(By.Id("session-count"));
Browser.Equal("1", () => sessionCount.Text);
}

[Fact]
public void SessionStorageDoesNotPersistAcrossTabs()
{
// Session storage initially cleared
var incrementSessionButton = Browser.FindElement(By.Id("increment-session"));
var sessionCount = Browser.FindElement(By.Id("session-count"));
var incrementSessionButton = Browser.Exists(By.Id("increment-session"));
var sessionCount = Browser.Exists(By.Id("session-count"));
Browser.Equal("0", () => sessionCount.Text);

// Session storage updates in current tab
Expand All @@ -111,7 +111,7 @@ public void SessionStorageDoesNotPersistAcrossTabs()

// Session storage does not persist across tabs
OpenNewSession();
sessionCount = Browser.FindElement(By.Id("session-count"));
sessionCount = Browser.Exists(By.Id("session-count"));
Browser.Equal("0", () => sessionCount.Text);
}

Expand All @@ -130,7 +130,7 @@ private void OpenNewSession()
Keys.Command :
Keys.Control;

var newTabLink = Browser.FindElement(By.Id("new-tab"));
var newTabLink = Browser.Exists(By.Id("new-tab"));
var action = new Actions(Browser);
action.KeyDown(modifierKey).MoveToElement(newTabLink).Click().KeyUp(modifierKey).Perform();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public override void CanSetCultureAndParseCultureSensitiveNumbersAndDates(string

protected override void SetCulture(string culture)
{
var selector = new SelectElement(Browser.FindElement(By.Id("culture-selector")));
var selector = new SelectElement(Browser.Exists(By.Id("culture-selector")));
selector.SelectByValue(culture);

// Click the link to return back to the test page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ public void DotNetExceptionDetailsAreNotLoggedByDefault()
var actualValues = new Dictionary<string, string>();

// Act
var interopButton = Browser.FindElement(By.Id("btn-interop"));
var interopButton = Browser.Exists(By.Id("btn-interop"));
interopButton.Click();

Browser.Exists(By.Id("done-with-interop"));

foreach (var expectedValue in expectedValues)
{
var currentValue = Browser.FindElement(By.Id(expectedValue.Key));
var currentValue = Browser.Exists(By.Id(expectedValue.Key));
actualValues.Add(expectedValue.Key, currentValue.Text);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected override void InitializeAsyncCore()
public async Task LongRunningJavaScriptFunctionsResultInCancellationAndWorkingAppAfterFunctionCompletion()
{
// Act & Assert
var interopButton = Browser.FindElement(By.Id("btn-interop"));
var interopButton = Browser.Exists(By.Id("btn-interop"));
interopButton.Click();

Browser.Exists(By.Id("done-with-interop"));
Expand All @@ -43,7 +43,7 @@ public async Task LongRunningJavaScriptFunctionsResultInCancellationAndWorkingAp
// wait 10 seconds, js method completes in 5 seconds, after this point it would have triggered a completion for sure.
await Task.Delay(10000);

var circuitFunctional = Browser.FindElement(By.Id("circuit-functional"));
var circuitFunctional = Browser.Exists(By.Id("circuit-functional"));
circuitFunctional.Click();

Browser.Exists(By.Id("done-circuit-functional"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected override void InitializeAsyncCore()
[InlineData("fr-FR", "Bonjour!")]
public void CanSetCultureAndReadLocalizedResources(string culture, string message)
{
var selector = new SelectElement(Browser.FindElement(By.Id("culture-selector")));
var selector = new SelectElement(Browser.Exists(By.Id("culture-selector")));
selector.SelectByValue(culture);

// Click the link to return back to the test page
Expand All @@ -47,7 +47,7 @@ public void CanSetCultureAndReadLocalizedResources(string culture, string messag
var cultureDisplay = Browser.Exists(By.Id("culture-name-display"));
Assert.Equal($"Culture is: {culture}", cultureDisplay.Text);

var messageDisplay = Browser.FindElement(By.Id("message-display"));
var messageDisplay = Browser.Exists(By.Id("message-display"));
Assert.Equal(message, messageDisplay.Text);
}
}
Expand Down
Loading