Created
June 25, 2020 13:48
-
-
Save yashaka/61a6e2771312e07c42fc6eeadc62ea50 to your computer and use it in GitHub Desktop.
Bills.Tests/Core/SeleneCollectionExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using OpenQA.Selenium; | |
using static NSelene.Selene; | |
using NSelene; | |
using OpenQA.Selenium.Interactions; | |
using System; | |
using NSelene.Conditions; | |
using System.Linq; | |
using System.Collections.Generic; | |
namespace Bills.Tests.Core | |
{ | |
public static class SeleneCollectionExtensions | |
{ | |
public static int IndexOfElementBy(this SeleneCollection collection, Condition<SeleneElement> condition, int amongExpectedOfNumber=-1) | |
{ | |
if (amongExpectedOfNumber>0) | |
{ | |
collection.Should(Have.Count(amongExpectedOfNumber)); | |
} | |
collection.FindBy(condition).Should(Be.InDom); | |
return ((IEnumerable<SeleneElement>)collection) | |
.Select((Value, Index) => new {Value, Index}) | |
.Single(its => condition.Apply(its.Value)) | |
.Index; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment