Skip to content

Instantly share code, notes, and snippets.

@YevgeniyShunevych
Last active March 18, 2019 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YevgeniyShunevych/0c771a32f654cd0172ffc9a52638d589 to your computer and use it in GitHub Desktop.
Save YevgeniyShunevych/0c771a32f654cd0172ffc9a52638d589 to your computer and use it in GitHub Desktop.
Custom Atata FindByXPathAttribute
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::*";
}
}
}
<div>
<span>Some1</span>
<div>Content 1</div>
</div>
<p>
<span>Some2</span>
<span>Content 2</span>
</p>
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