Browse Source

Use Name for AutomationId.

ui-automation-test
Steven Kirk 6 years ago
parent
commit
651106aed3
  1. 30
      samples/IntegrationTestApp/MainWindow.axaml
  2. 2
      src/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cs
  3. 29
      tests/Avalonia.IntegrationTests.Win32/AutomationTests.cs

30
samples/IntegrationTestApp/MainWindow.axaml

@ -5,16 +5,24 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="IntegrationTestApp.MainWindow"
Title="IntegrationTestApp">
<TabControl TabStripPlacement="Left" AutomationProperties.AutomationId="MainTabs">
<TabControl TabStripPlacement="Left" Name="MainTabs">
<TabItem Header="Automation">
<StackPanel>
<TextBlock Name="TextBlockWithName">TextBlockWithName</TextBlock>
<TextBlock Name="NotTheAutomationId" AutomationProperties.AutomationId="TextBlockWithNameAndAutomationId">
TextBlockWithNameAndAutomationId
</TextBlock>
</StackPanel>
</TabItem>
<TabItem Header="Button">
<StackPanel>
<Button AutomationProperties.AutomationId="DisabledButton" IsEnabled="False">
<Button Name="DisabledButton" IsEnabled="False">
Disabled Button
</Button>
<Button AutomationProperties.AutomationId="BasicButton">
<Button Name="BasicButton">
Basic Button
</Button>
<Button AutomationProperties.AutomationId="ButtonWithTextBlock">
<Button Name="ButtonWithTextBlock">
<TextBlock>Button with TextBlock</TextBlock>
</Button>
</StackPanel>
@ -22,23 +30,23 @@
<TabItem Header="CheckBox">
<StackPanel>
<CheckBox AutomationProperties.AutomationId="UncheckedCheckBox">Unchecked</CheckBox>
<CheckBox AutomationProperties.AutomationId="CheckedCheckBox" IsChecked="True">Checked</CheckBox>
<CheckBox AutomationProperties.AutomationId="ThreeStateCheckBox" IsThreeState="True" IsChecked="{x:Null}">ThreeState</CheckBox>
<CheckBox Name="UncheckedCheckBox">Unchecked</CheckBox>
<CheckBox Name="CheckedCheckBox" IsChecked="True">Checked</CheckBox>
<CheckBox Name="ThreeStateCheckBox" IsThreeState="True" IsChecked="{x:Null}">ThreeState</CheckBox>
</StackPanel>
</TabItem>
<TabItem Header="ComboBox">
<StackPanel>
<ComboBox AutomationProperties.AutomationId="UnselectedComboBox">
<ComboBox Name="UnselectedComboBox">
<ComboBoxItem>Foo</ComboBoxItem>
<ComboBoxItem>Bar</ComboBoxItem>
</ComboBox>
<ComboBox AutomationProperties.AutomationId="SelectedIndex0ComboBox" SelectedIndex="0">
<ComboBox Name="SelectedIndex0ComboBox" SelectedIndex="0">
<ComboBoxItem>Foo</ComboBoxItem>
<ComboBoxItem>Bar</ComboBoxItem>
</ComboBox>
<ComboBox AutomationProperties.AutomationId="SelectedIndex1ComboBox" SelectedIndex="1">
<ComboBox Name="SelectedIndex1ComboBox" SelectedIndex="1">
<ComboBoxItem>Foo</ComboBoxItem>
<ComboBoxItem>Bar</ComboBoxItem>
</ComboBox>

2
src/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cs

@ -43,7 +43,7 @@ namespace Avalonia.Automation.Peers
}
protected override void BringIntoViewCore() => Owner.BringIntoView();
protected override string? GetAutomationIdCore() => AutomationProperties.GetAutomationId(Owner);
protected override string? GetAutomationIdCore() => AutomationProperties.GetAutomationId(Owner) ?? Owner.Name;
protected override Rect GetBoundingRectangleCore() => GetBounds(Owner.TransformedBounds);
protected virtual IReadOnlyList<AutomationPeer>? GetChildrenCore()

29
tests/Avalonia.IntegrationTests.Win32/AutomationTests.cs

@ -0,0 +1,29 @@
using OpenQA.Selenium.Appium.Windows;
using Xunit;
namespace Avalonia.IntegrationTests.Win32
{
[Collection("Default")]
public class AutomationTests
{
private WindowsDriver<WindowsElement> _session;
public AutomationTests(TestAppFixture fixture)
{
_session = fixture.Session;
var tabs = _session.FindElementByAccessibilityId("MainTabs");
var tab = tabs.FindElementByName("Automation");
tab.Click();
}
[Fact]
public void AutomationId()
{
// AutomationID can be specified by the Name or AutomationProperties.AutomationId
// properties, with the latter taking precedence.
var byName = _session.FindElementByAccessibilityId("TextBlockWithName");
var byAutomationId = _session.FindElementByAccessibilityId("TextBlockWithNameAndAutomationId");
}
}
}
Loading…
Cancel
Save