Browse Source

Add CheckBox tests.

ui-automation-test
Steven Kirk 5 years ago
parent
commit
2e23333996
  1. 2
      .editorconfig
  2. 3
      Avalonia.sln
  3. 43
      samples/IntegrationTestApp/MainWindow.axaml
  4. 3
      src/Avalonia.Controls/Automation/Peers/ToggleButtonAutomationPeer.cs
  5. 72
      tests/Avalonia.IntegrationTests.Win32/CheckBoxTests.cs
  6. 11
      tests/Avalonia.IntegrationTests.Win32/TestAppFixture.cs

2
.editorconfig

@ -137,7 +137,7 @@ space_within_single_line_array_initializer_braces = true
csharp_wrap_before_ternary_opsigns = false csharp_wrap_before_ternary_opsigns = false
# Xaml files # Xaml files
[*.xaml] [*.{xaml,axaml}]
indent_size = 2 indent_size = 2
# Xml project files # Xml project files

3
Avalonia.sln

@ -234,7 +234,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MiniMvvm", "samples\MiniMvv
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IntegrationTestApp", "samples\IntegrationTestApp\IntegrationTestApp.csproj", "{676D6BFD-029D-4E43-BFC7-3892265CE251}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IntegrationTestApp", "samples\IntegrationTestApp\IntegrationTestApp.csproj", "{676D6BFD-029D-4E43-BFC7-3892265CE251}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.IntegrationTests.Win32", "tests\Avalonia.IntegrationTests.Win32\Avalonia.IntegrationTests.Win32.csproj", "{F2CE566B-E7F6-447A-AB1A-3F574A6FE43A}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.IntegrationTests.Win32", "tests\Avalonia.IntegrationTests.Win32\Avalonia.IntegrationTests.Win32.csproj", "{F2CE566B-E7F6-447A-AB1A-3F574A6FE43A}"
EndProject EndProject
Global Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution GlobalSection(SharedMSBuildProjectFiles) = preSolution
@ -2235,6 +2235,7 @@ Global
{29132311-1848-4FD6-AE0C-4FF841151BD3} = {9B9E3891-2366-4253-A952-D08BCEB71098} {29132311-1848-4FD6-AE0C-4FF841151BD3} = {9B9E3891-2366-4253-A952-D08BCEB71098}
{7D2D3083-71DD-4CC9-8907-39A0D86FB322} = {3743B0F2-CC41-4F14-A8C8-267F579BF91E} {7D2D3083-71DD-4CC9-8907-39A0D86FB322} = {3743B0F2-CC41-4F14-A8C8-267F579BF91E}
{39D7B147-1A5B-47C2-9D01-21FB7C47C4B3} = {9B9E3891-2366-4253-A952-D08BCEB71098} {39D7B147-1A5B-47C2-9D01-21FB7C47C4B3} = {9B9E3891-2366-4253-A952-D08BCEB71098}
{86C53C40-57AA-45B8-AD42-FAE0EFDF0F2B} = {A689DEF5-D50F-4975-8B72-124C9EB54066}
{854568D5-13D1-4B4F-B50D-534DC7EFD3C9} = {86C53C40-57AA-45B8-AD42-FAE0EFDF0F2B} {854568D5-13D1-4B4F-B50D-534DC7EFD3C9} = {86C53C40-57AA-45B8-AD42-FAE0EFDF0F2B}
{638580B0-7910-40EF-B674-DCB34DA308CD} = {A0CC0258-D18C-4AB3-854F-7101680FC3F9} {638580B0-7910-40EF-B674-DCB34DA308CD} = {A0CC0258-D18C-4AB3-854F-7101680FC3F9}
{CBC4FF2F-92D4-420B-BE21-9FE0B930B04E} = {B39A8919-9F95-48FE-AD7B-76E08B509888} {CBC4FF2F-92D4-420B-BE21-9FE0B930B04E} = {B39A8919-9F95-48FE-AD7B-76E08B509888}

43
samples/IntegrationTestApp/MainWindow.axaml

@ -9,31 +9,40 @@
<TabItem Header="Button"> <TabItem Header="Button">
<StackPanel> <StackPanel>
<Button AutomationProperties.AutomationId="DisabledButton" IsEnabled="False"> <Button AutomationProperties.AutomationId="DisabledButton" IsEnabled="False">
Disabled Button Disabled Button
</Button> </Button>
<Button AutomationProperties.AutomationId="BasicButton"> <Button AutomationProperties.AutomationId="BasicButton">
Basic Button Basic Button
</Button> </Button>
<Button AutomationProperties.AutomationId="ButtonWithTextBlock"> <Button AutomationProperties.AutomationId="ButtonWithTextBlock">
<TextBlock>Button with TextBlock</TextBlock> <TextBlock>Button with TextBlock</TextBlock>
</Button> </Button>
</StackPanel> </StackPanel>
</TabItem> </TabItem>
<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>
</StackPanel>
</TabItem>
<TabItem Header="ComboBox"> <TabItem Header="ComboBox">
<StackPanel> <StackPanel>
<ComboBox AutomationProperties.AutomationId="UnselectedComboBox"> <ComboBox AutomationProperties.AutomationId="UnselectedComboBox">
<ComboBoxItem>Foo</ComboBoxItem> <ComboBoxItem>Foo</ComboBoxItem>
<ComboBoxItem>Bar</ComboBoxItem> <ComboBoxItem>Bar</ComboBoxItem>
</ComboBox> </ComboBox>
<ComboBox AutomationProperties.AutomationId="SelectedIndex0ComboBox" SelectedIndex="0"> <ComboBox AutomationProperties.AutomationId="SelectedIndex0ComboBox" SelectedIndex="0">
<ComboBoxItem>Foo</ComboBoxItem> <ComboBoxItem>Foo</ComboBoxItem>
<ComboBoxItem>Bar</ComboBoxItem> <ComboBoxItem>Bar</ComboBoxItem>
</ComboBox> </ComboBox>
<ComboBox AutomationProperties.AutomationId="SelectedIndex1ComboBox" SelectedIndex="1"> <ComboBox AutomationProperties.AutomationId="SelectedIndex1ComboBox" SelectedIndex="1">
<ComboBoxItem>Foo</ComboBoxItem> <ComboBoxItem>Foo</ComboBoxItem>
<ComboBoxItem>Bar</ComboBoxItem> <ComboBoxItem>Bar</ComboBoxItem>
</ComboBox> </ComboBox>
</StackPanel> </StackPanel>
</TabItem> </TabItem>
</TabControl> </TabControl>
</Window> </Window>

3
src/Avalonia.Controls/Automation/Peers/ToggleButtonAutomationPeer.cs

@ -35,5 +35,8 @@ namespace Avalonia.Automation.Peers
{ {
return AutomationControlType.Button; return AutomationControlType.Button;
} }
protected override bool IsContentElementCore() => true;
protected override bool IsControlElementCore() => true;
} }
} }

72
tests/Avalonia.IntegrationTests.Win32/CheckBoxTests.cs

@ -0,0 +1,72 @@
using OpenQA.Selenium.Appium.Windows;
using Xunit;
namespace Avalonia.IntegrationTests.Win32
{
[Collection("Default")]
public class CheckBoxTests
{
private WindowsDriver<WindowsElement> _session;
public CheckBoxTests(TestAppFixture fixture)
{
_session = fixture.Session;
var tabs = _session.FindElementByAccessibilityId("MainTabs");
var tab = tabs.FindElementByName("CheckBox");
tab.Click();
}
[Fact]
public void UncheckedCheckBox()
{
var checkBox = _session.FindElementByAccessibilityId("UncheckedCheckBox");
Assert.Equal("Unchecked", checkBox.Text);
Assert.False(checkBox.Selected);
Assert.Equal("0", checkBox.GetAttribute("Toggle.ToggleState"));
checkBox.Click();
Assert.True(checkBox.Selected);
Assert.Equal("1", checkBox.GetAttribute("Toggle.ToggleState"));
}
[Fact]
public void CheckedCheckBox()
{
var checkBox = _session.FindElementByAccessibilityId("CheckedCheckBox");
Assert.Equal("Checked", checkBox.Text);
Assert.True(checkBox.Selected);
Assert.Equal("1", checkBox.GetAttribute("Toggle.ToggleState"));
checkBox.Click();
Assert.False(checkBox.Selected);
Assert.Equal("0", checkBox.GetAttribute("Toggle.ToggleState"));
}
[Fact]
public void ThreeStateCheckBox()
{
var checkBox = _session.FindElementByAccessibilityId("ThreeStateCheckBox");
Assert.Equal("ThreeState", checkBox.Text);
Assert.Equal("2", checkBox.GetAttribute("Toggle.ToggleState"));
checkBox.Click();
Assert.False(checkBox.Selected);
Assert.Equal("0", checkBox.GetAttribute("Toggle.ToggleState"));
checkBox.Click();
Assert.True(checkBox.Selected);
Assert.Equal("1", checkBox.GetAttribute("Toggle.ToggleState"));
checkBox.Click();
Assert.Equal("2", checkBox.GetAttribute("Toggle.ToggleState"));
}
}
}

11
tests/Avalonia.IntegrationTests.Win32/TestAppFixture.cs

@ -1,5 +1,7 @@
using System; using System;
using System.Globalization;
using System.IO; using System.IO;
using System.Runtime.InteropServices;
using OpenQA.Selenium.Appium; using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows; using OpenQA.Selenium.Appium.Windows;
@ -19,10 +21,19 @@ namespace Avalonia.IntegrationTests.Win32
Session = new WindowsDriver<WindowsElement>( Session = new WindowsDriver<WindowsElement>(
new Uri(WindowsApplicationDriverUrl), new Uri(WindowsApplicationDriverUrl),
opts); opts);
// https://github.com/microsoft/WinAppDriver/issues/1025
SetForegroundWindow(new IntPtr(int.Parse(
Session.WindowHandles[0].Substring(2),
NumberStyles.AllowHexSpecifier)));
} }
public WindowsDriver<WindowsElement> Session { get; } public WindowsDriver<WindowsElement> Session { get; }
public void Dispose() => Session.Close(); public void Dispose() => Session.Close();
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetForegroundWindow(IntPtr hWnd);
} }
} }

Loading…
Cancel
Save