Last active
March 18, 2019 10:39
-
-
Save YevgeniyShunevych/0c771a32f654cd0172ffc9a52638d589 to your computer and use it in GitHub Desktop.
Custom Atata FindByXPathAttribute
This file contains 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
namespace Atata | |
{ | |
public class FindByPrecedingSpanAttribute : FindByXPathAttribute | |
{ | |
public FindByPrecedingSpanAttribute(params string[] terms) | |
: this(TermMatch.Equals, terms) | |
{ | |
} | |
public FindByPrecedingSpanAttribute(TermMatch match, params string[] terms) | |
: base(BuildXPath(match, terms)) | |
{ | |
} | |
private static string BuildXPath(TermMatch match, string[] terms) | |
{ | |
string termCondition = match.CreateXPathCondition(terms, "."); | |
return $"span[{termCondition}]/following-sibling::*"; | |
} | |
} | |
} |
This file contains 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
<div> | |
<span>Some1</span> | |
<div>Content 1</div> | |
</div> | |
<p> | |
<span>Some2</span> | |
<span>Content 2</span> | |
</p> |
This file contains 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 Atata; | |
namespace SomeApp.UITests | |
{ | |
using _ = SamplePage; | |
public class SamplePage : Page<_> | |
{ | |
[FindByPrecedingSpan("Some1")] | |
public Text<_> Some1 { get; private set; } | |
[FindByPrecedingSpan(TermMatch.Contains, "Some3", "Some2")] // Finds by "Some3" or "Some2" containing text. | |
public Text<_> Some2 { get; private set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment