Notes: This tests project doesn't focus on building a framework for Selenium, but uses selenium library with Fluent Assertion library to demonstrate uses for Assertion.
Packages | Version |
---|---|
Target Framework | netcoreapp3.1 |
FluentAssertions | 5.10.3 |
nunit | 3.12.0 |
NUnit3TestAdapter | 3.17.0 |
Selenium.Support | 3.14.0 |
Selenium.WebDriver | 3.14.0 |
WebDriverManager | 2.11.0 |
Before running this project I would check for the .Net SDK installed on my machine then either right click on the project name in
Visual Studio Solution Explorer --> Properties --> Application
and change the Target framework. Or you can follow the instruction on the following link How to target Multiple Framework to change at .csproj
file.
string message = "Welcome user John Smith";
Evaluates string starts with specific character(s) from the above example if we want to check if the message has the word Welcome
.
message.Should().StartWith("Welcome");
Evaluates string ends with specific character(s) from the above example if we want to check if the message has John Smith
.
message.Should().EndWith("John Smith");
Evaluates that string contains a series of character(s) from above example if we want to check if the word user
exist.
message.Should().Contain("user");
Assertion Scope batches multiple assertions so that when evaluating multiple facts, FluentAssertions
throws one collective exception summary at the end of the scope for all failures.
using (new AssertionScope())
{
message.Should().StartWith("Welcome")
.And.EndWith("John Smith")
.And.Contain("user");
}
<ul class="list-group" id="unorderedList">
<li class="list-group-item">Apple</li>
<li class="list-group-item">Orange</li>
<li class="list-group-item">Lychee</li>
<li class="list-group-item">Pomegranate</li>
<li class="list-group-item">Watermelon</li>
<li class="list-group-item">Mangosteen</li>
</ul>
Checking for a list of element is coming back as unique.
driver.FindElements(By.XPath(".//ul/li")).Select(e => e.Text)
.Should().OnlyHaveUniqueItems();
driver.FindElements(By.XPath(".//ul/li")).Select(e => e.Text)
.Should().BeInAscendingOrder();
For more information checkout the Fluent Assertion Official Documentation