I have almost searched every forum/website related to Selenium WebDriver but still unable to find the solution that how to user Assertions and Verifications in Selenium WebDriver using C#.
Here is my code where I just want to put a sample assertion in the code written below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
namespace Healthfleet
{
class Login
{
static void Main(string[] args)
{
IWebDriver driver = new ChromeDriver(@"D:\Downloads");
driver.Navigate().GoToUrl("https://test.com/");
IWebElement username = driver.FindElement(By.Id("username"));
IWebElement password = driver.FindElement(By.Id("password"));
username.SendKeys("[email protected]");
password.SendKeys("test");
IWebElement loginButton = driver.FindElement(By.Id("Login"));
loginButton.Click();
}
}
}
I need to check if username = test or not by using assertion but I am unable to find any Assert class or method.
Am I missing some namespace which contains the Assert class or any other idea?
In the case of the “Assert” command, as soon as the validation fails the execution of that particular test method is stopped. Following that the test method is marked as failed. Whereas, in the case of “Verify”, the test method continues execution even after the failure of an assertion statement.
In Selenium, Asserts are validations or checkpoints for an application. Assertions state confidently that application behavior is working as expected. One can say that Asserts in Selenium are used to validate the test cases. They help testers understand if tests have passed or failed.
The assertion verifies the boolean value returned by the condition. If the Boolean value is false, then the assertion passes the test. [TestMethod] public void AssertIsFalse() { //Test will pass because the condition returns "False" Assert.
NUnit was required to test this. And you have to add its dll and then add namespace as
using NUnit.Framework;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With