Skip to content

Commit

Permalink
#258 Throw more detailed exceptions in ControlListScopeLocator
Browse files Browse the repository at this point in the history
  • Loading branch information
YevgeniyShunevych committed Apr 25, 2019
1 parent 43410f6 commit c165aaf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/Atata/Components/ControlList`2.cs
Expand Up @@ -235,6 +235,10 @@ private void InitItemFindAttribute(FindAttribute findAttribute)
protected TItem CreateItem(IScopeLocator scopeLocator, string name)
{
TItem item = CreateItem(name);

if (scopeLocator is ControlListScopeLocator controlListScopeLocator)
controlListScopeLocator.ElementName = item.ComponentFullName;

item.ScopeLocator = scopeLocator;

return item;
Expand Down
28 changes: 24 additions & 4 deletions src/Atata/ScopeSearch/ControlListScopeLocator.cs
Expand Up @@ -14,6 +14,8 @@ public ControlListScopeLocator(Func<SearchOptions, IEnumerable<IWebElement>> pre
this.predicate = predicate;
}

public string ElementName { get; set; }

public IWebElement GetElement(SearchOptions searchOptions = null, string xPathCondition = null)
{
searchOptions = searchOptions ?? new SearchOptions();
Expand All @@ -24,9 +26,18 @@ public IWebElement GetElement(SearchOptions searchOptions = null, string xPathCo
});

if (element == null && !searchOptions.IsSafely)
throw ExceptionFactory.CreateForNoSuchElement();
{
throw ExceptionFactory.CreateForNoSuchElement(
new SearchFailureData
{
ElementName = ElementName,
SearchOptions = searchOptions
});
}
else
return element;
{
return element;
}
}

public IWebElement[] GetElements(SearchOptions searchOptions = null, string xPathCondition = null)
Expand All @@ -49,9 +60,18 @@ public bool IsMissing(SearchOptions searchOptions = null, string xPathCondition
});

if (!isMissing && !searchOptions.IsSafely)
throw ExceptionFactory.CreateForNotMissingElement();
{
throw ExceptionFactory.CreateForNotMissingElement(
new SearchFailureData
{
ElementName = ElementName,
SearchOptions = searchOptions
});
}
else
return isMissing;
{
return isMissing;
}
}
}
}

0 comments on commit c165aaf

Please sign in to comment.