|
| 1 | +using System; |
| 2 | +using System.Drawing; |
| 3 | +using System.Windows.Automation; |
| 4 | +using System.Xml.Linq; |
| 5 | +using UiAutomation; |
| 6 | +using UiAutomationGRPC.Client.Framework; |
| 7 | + |
| 8 | +namespace UiAutomationGRPC.Client.Calc.Pages |
| 9 | +{ |
| 10 | + public class CalcPage : BasePageObject<CalcPage> |
| 11 | + { |
| 12 | + private readonly UiAutomationService.UiAutomationServiceClient _client; |
| 13 | + private readonly CalcPageLocators _locators; |
| 14 | + public CalcPage(UiAutomationService.UiAutomationServiceClient client) |
| 15 | + { |
| 16 | + // Optional: Wait for the app to be ready in constructor |
| 17 | + _client = client; |
| 18 | + _locators = new CalcPageLocators(client); |
| 19 | + _locators.ResultText.WaitForElementExist(); |
| 20 | + } |
| 21 | + |
| 22 | + public CalcPage ClickTwo() |
| 23 | + { |
| 24 | + _locators.ButtonTwo.Click(); |
| 25 | + return this; |
| 26 | + } |
| 27 | + |
| 28 | + public CalcPage ClickPlus() |
| 29 | + { |
| 30 | + _locators.ButtonPlus.Click(); |
| 31 | + return this; |
| 32 | + } |
| 33 | + |
| 34 | + public CalcPage ClickEqual() |
| 35 | + { |
| 36 | + _locators.ButtonEqual.Click(); |
| 37 | + return this; |
| 38 | + } |
| 39 | + |
| 40 | + public string GetResult() |
| 41 | + { |
| 42 | + return _locators.ResultText.Name(); |
| 43 | + } |
| 44 | + |
| 45 | + public CalcNavigationPaget<CalcPage> ClickNavigationButton() |
| 46 | + { |
| 47 | + _locators.ResultText.Name(); |
| 48 | + return new CalcNavigationPaget<CalcPage>(_client, this); |
| 49 | + } |
| 50 | + |
| 51 | + public CalcPage ClickResultText() |
| 52 | + { |
| 53 | + _locators.ResultText.Click(); |
| 54 | + return this; |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + public class CalcPageLocators |
| 59 | + { |
| 60 | + private readonly UiAutomationService.UiAutomationServiceClient _client; |
| 61 | + |
| 62 | + public CalcPageLocators(UiAutomationService.UiAutomationServiceClient client) => _client = client; |
| 63 | + |
| 64 | + private IAutomationElement CreateElement(Func<BaseSelector> selector) => new UiAutomationAdapter(_client, selector); |
| 65 | + |
| 66 | + private Selector Window => new Selector(new PropertyConditions().NameProperty("Calculator")); |
| 67 | + |
| 68 | + private IAutomationElement E(string automationId) => |
| 69 | + CreateElement(() => Window.Descendants(new PropertyConditions().AutomationIdProperty(automationId))); |
| 70 | + |
| 71 | + public IAutomationElement ButtonOne => E("num1Button"); |
| 72 | + public IAutomationElement ButtonTwo => E("num2Button"); |
| 73 | + public IAutomationElement ButtonPlus => E("plusButton"); |
| 74 | + public IAutomationElement ButtonEqual => E("equalButton"); |
| 75 | + public IAutomationElement ResultText => E("CalculatorResults"); |
| 76 | + public IAutomationElement NavigationButton => CreateElement(() => Window.Descendants().ControlType("Button").NameContain("Close Navigation")); |
| 77 | + |
| 78 | + |
| 79 | +} |
| 80 | +} |
0 commit comments