Skip to content

Commit d772e21

Browse files
committed
fixed prompt find strategies
1 parent 6ec910d commit d772e21

File tree

2 files changed

+16
-44
lines changed

2 files changed

+16
-44
lines changed

src/Bellatrix.Desktop/llm/FindByPrompt.cs

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public class FindByPrompt : FindStrategy
3939
{
4040
private bool _tryResolveFromPages = true;
4141

42+
private WindowsDriver WrappedDriver => ServicesCollection.Current.Resolve<WindowsDriver>();
43+
4244
/// <summary>
4345
/// Initializes a new instance of the <see cref="FindByPrompt"/> class with the specified prompt value.
4446
/// </summary>
@@ -49,44 +51,24 @@ public FindByPrompt(string value, bool tryResolveFromPages = true) : base(value)
4951
_tryResolveFromPages = tryResolveFromPages;
5052
}
5153

52-
/// <summary>
53-
/// Locates a single AppiumElement using the resolved XPath.
54-
/// </summary>
55-
public override AppiumElement FindElement(WindowsDriver driver)
56-
{
57-
var location = driver.CurrentWindowHandle;
58-
var xpath = ResolveLocator(location, driver);
59-
return driver.FindElement(By.XPath(xpath));
60-
}
61-
62-
/// <summary>
63-
/// Locates all matching AppiumElements using the resolved XPath.
64-
/// </summary>
65-
public override IEnumerable<AppiumElement> FindAllElements(WindowsDriver driver)
66-
{
67-
var location = driver.CurrentWindowHandle;
68-
var xpath = ResolveLocator(location, driver);
69-
return driver.FindElements(By.XPath(xpath));
70-
}
71-
7254
/// <summary>
7355
/// Locates a single AppiumElement in the context of a parent element using the resolved XPath.
7456
/// </summary>
75-
public override AppiumElement FindElement(AppiumElement element)
57+
public override AppiumElement FindElement(ISearchContext searchContext)
7658
{
77-
var location = element.WrappedDriver.CurrentWindowHandle;
78-
var xpath = ResolveLocator(location, element.WrappedDriver as WindowsDriver);
79-
return element.FindElement(By.XPath(xpath));
59+
var location = WrappedDriver.CurrentWindowHandle;
60+
var xpath = ResolveLocator(location, WrappedDriver as WindowsDriver);
61+
return searchContext.FindElement(By.XPath(xpath)) as AppiumElement;
8062
}
8163

8264
/// <summary>
8365
/// Locates all matching AppiumElements in the context of a parent element using the resolved XPath.
8466
/// </summary>
85-
public override IEnumerable<AppiumElement> FindAllElements(AppiumElement element)
67+
public override IEnumerable<AppiumElement> FindAllElements(ISearchContext searchContext)
8668
{
87-
var location = element.WrappedDriver.CurrentWindowHandle;
88-
var xpath = ResolveLocator(location, element.WrappedDriver as WindowsDriver);
89-
return element.FindElements(By.XPath(xpath));
69+
var location = WrappedDriver.CurrentWindowHandle;
70+
var xpath = ResolveLocator(location, WrappedDriver as WindowsDriver);
71+
return searchContext.FindElements(By.XPath(xpath)).Select(el => el as AppiumElement);
9072
}
9173

9274
/// <summary>
Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System.Collections.Generic;
2+
using System.Linq;
23
using Bellatrix.Desktop.Locators;
34
using OpenQA.Selenium;
45
using OpenQA.Selenium.Appium;
5-
using OpenQA.Selenium.Appium.Windows;
66

77
namespace Bellatrix.Desktop.GettingStarted;
88

@@ -18,28 +18,18 @@ public FindNameStartingWithStrategy(string value)
1818
}
1919

2020
// 2. We override all available methods and use XPath expression for finding an element with Name starting with.
21-
public override AppiumElement FindElement(WindowsDriver searchContext)
21+
public override AppiumElement FindElement(ISearchContext searchContext)
2222
{
23-
return searchContext.FindElement(By.XPath(string.Format(XpathStartingWithExpression, Value)));
23+
return searchContext.FindElement(By.XPath(string.Format(XpathStartingWithExpression, Value))) as AppiumElement;
2424
}
2525

26-
public override IEnumerable<AppiumElement> FindAllElements(WindowsDriver searchContext)
26+
public override IEnumerable<AppiumElement> FindAllElements(ISearchContext searchContext)
2727
{
28-
return searchContext.FindElements(By.XPath(string.Format(XpathStartingWithExpression, Value)));
29-
}
30-
31-
public override AppiumElement FindElement(AppiumElement element)
32-
{
33-
return element.FindElement(By.XPath(string.Format(XpathStartingWithExpression, Value)));
34-
}
35-
36-
public override IEnumerable<AppiumElement> FindAllElements(AppiumElement element)
37-
{
38-
return element.FindElements(By.XPath(string.Format(XpathStartingWithExpression, Value)));
28+
return searchContext.FindElements(By.XPath(string.Format(XpathStartingWithExpression, Value))).Select(el => el as AppiumElement);
3929
}
4030

4131
public override string ToString()
4232
{
4333
return $"By Name starting with = {Value}";
4434
}
45-
}
35+
}

0 commit comments

Comments
 (0)