Alerts
The browser's own dialogs. While one is open, the page cannot be used until the test accepts or dismisses it.
Result: No dialog yet
| Button | Dialog | Result after Accept | Result after Dismiss |
|---|---|---|---|
| Show an alert | Hello from the practice page. | Alert closed | Alert closed |
| Ask to confirm | Delete the item? | Deleted | Kept |
| Ask for a name | Your name? (default Guest) | Hello, Guest | No name given |
| Alert in 1.5 seconds | This alert waited 1.5 seconds. | Late alert closed | Late alert closed |
What to practise
- Check the text of each dialog, accept or dismiss it, and read the result.
- The last button opens its alert only after 1.5 seconds: the test has to wait for it.
In VAF: browser.Should().HaveAlert().HaveText("…").Accept().
Tested in VAF-Demo
A test of this page from VAF-Demo, written with shared steps: the test says what the user does, the steps hold the VAF chains.
[Test]
public void ConfirmAcceptedDeletes()
{
AlertsSteps.LetsAskToDelete();
AlertsSteps.LetsAccept("Delete the item?");
AlertsSteps.LetsCheckTheAnswer("Deleted");
}
On GitHub (opens in a new tab)
-
Page object
—
AlertsPage.cs: the locators of this page -
Native tests
—
AlertsTests.cs: the whole VAF chain in each test -
Shared steps
—
AlertsSteps.cs: the steps the test above calls -
Shared steps tests
—
AlertsStepsTests.cs: the tests of this page written with steps - The whole project and its README Latest test run (GitHub Actions)