0

I have taken two outputs which are IList<IWebElement> type from the UI and the Database. So now i need to compair the two IList<IWebElement> . Im using nunit. How to perform this.

2

You need to provide an IEqualityComparer that implements the Equals and the GetHashCode methods according to your logic of comparison.

class WebElementEqualityComparer : IEqualityComparer<IWebElement>
{
    public bool Equals(IWebElement w1, IWebElement w2)
    {
        return true; //put your comparison logic here
    }
    public int GetHashCode(IWebElement wx)
    {
        int hCode = 1111; //put your logic of creating a hash code from your IWebElement here
        return hCode.GetHashCode();
    }
}

Then you can use the above newly created comparer as below:

IList<IWebElement> db = ...// your IList comming from DB
IList<IWebElement> ui = ...// your IList comming from UI
// assert this value is true
Assert.IsTrue(db.SequenceEqual(ui, new WebElementEqualityComparer()));
// or false as expected
Assert.IsFalse(db.SequenceEqual(ui, new WebElementEqualityComparer()));

I hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.