Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assert, Verify and other commands in Selenium WebDriver using C#

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?

like image 263
asma Avatar asked Feb 06 '13 06:02

asma


People also ask

What is assert and verify command in selenium?

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.

What are the assert commands in selenium?

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.

What is assert in selenium C#?

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.


1 Answers

NUnit was required to test this. And you have to add its dll and then add namespace as

using NUnit.Framework;

like image 79
asma Avatar answered Oct 20 '22 15:10

asma