public XPathComponentScopeFindResult[] Execute(StrategyScopeLocatorExecutionData executionData) { ISearchContext scopeContext = executionData.ScopeSource.GetScopeContext( executionData.Component, SearchOptions.Safely(executionData.IsSafely)); if (scopeContext is null) { return(new XPathComponentScopeFindResult[0]); } foreach (var unit in executionData.LayerUnits) { XPathComponentScopeFindResult[] xPathResults = Execute(unit.Strategy, scopeContext, unit.ScopeLocateOptions, unit.SearchOptions); if (!xPathResults.Any()) { return(xPathResults); } IWebElement element = xPathResults.Select(x => x.Get()).FirstOrDefault(x => x != null); if (element is null) { if (!executionData.IsSafely) { XPathComponentScopeFindResult firstResult = xPathResults.First(); throw ExceptionFactory.CreateForNoSuchElement( new SearchFailureData { ElementName = $"layer of {executionData.Component.ComponentFullName}", By = By.XPath(firstResult.XPath), SearchOptions = firstResult.SearchOptions }); } else { return(new XPathComponentScopeFindResult[0]); } } scopeContext = unit.ScopeContextResolver.Resolve(element); } return(Execute(executionData.FinalUnit.Strategy, scopeContext, executionData.FinalUnit.ScopeLocateOptions, executionData.FinalUnit.SearchOptions)); }
public bool IsMissing(SearchOptions searchOptions = null, string xPathCondition = null) { searchOptions = searchOptions ?? new SearchOptions(); SearchOptions quickSearchOptions = searchOptions.Clone(); quickSearchOptions.IsSafely = true; quickSearchOptions.Timeout = TimeSpan.Zero; var driver = AtataContext.Current.Driver; StrategyScopeLocatorExecutionData executionData = _executionDataCollector.Get(quickSearchOptions); bool isMissing = driver.Try(searchOptions.Timeout, searchOptions.RetryInterval).Until(_ => { XPathComponentScopeFindResult[] xPathResults = _executor.Execute(executionData); if (xPathResults.Any()) { Dictionary <By, ISearchContext> byScopePairs = xPathResults.ToDictionary(x => x.CreateBy(xPathCondition), x => x.ScopeSource); return(driver.Try(TimeSpan.Zero).MissingAll(byScopePairs)); } else { return(true); } }); if (!searchOptions.IsSafely && !isMissing) { throw ExceptionFactory.CreateForNotMissingElement( new SearchFailureData { ElementName = executionData.Component.ComponentFullName, SearchOptions = searchOptions }); } else { return(isMissing); } }