Assertions in LeanFT in C#.Net

Assertions can be added in the LeanFT tests using Verify class as shown in below example. Note that Verify class has below methods.

  1. AreEqual , AreNotEqual
  2. IsTrue, IsFalse
  3. StartsWith, Contains, EndsWith
  4. LessOrEqual, Less, Greater, GreaterOrEqual
  5. IsMatch
  6. IsNullOrEmpty, IsNotNullOrEmpty
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using HP.LFT.SDK;
using HP.LFT.Report;
using System.Diagnostics;
using System.Threading;
using HP.LFT.SDK.Web;
using System.Drawing;
using HP.LFT.Verifications;

namespace LeanFtTestProject1
{
    [TestClass]
    public class Assertions
    {
        [TestMethod]
        public void TestAssertions()
        {

            SDK.Init(new SdkConfiguration
            {
                ServerAddress = new Uri("ws://localhost:5095")
            });

            ReportConfiguration r = new ReportConfiguration();
            r.IsOverrideExisting = true;
            r.Title= "My LeanFT Report";
            Reporter.Init(r);

            IBrowser browser = BrowserFactory.Launch(BrowserType.InternetExplorer);

            // Navigate to www.softpost.org
            browser.Navigate("https://www.softpost.org/selenium-test-page/");

            // Find edit box using Xpath
            IEditField firstName = browser.Describe<IEditField>(new EditFieldDescription
            {
                XPath = "//input[@id='fn']"

            });

            firstName.SetValue("sagar");

            Verify.AreEqual("sagar", firstName.Value, 
                "Verifying the editbox value");

            browser.Close();

            Reporter.GenerateReport();
            SDK.Cleanup();
        }
    }
}

Below report shows that verification was successful.

LeanFT report assertions and verifications

LeanFT report assertions and verifications

You may also like...