Skip to content

Commit 2778ec0

Browse files
authored
Adding wait for UI test (#3083)
* Adding wait for UI test Updating to file-scoped namespaces * Update XAMLTest
1 parent e356f5d commit 2778ec0

File tree

14 files changed

+992
-1000
lines changed

14 files changed

+992
-1000
lines changed

Directory.packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<PackageVersion Include="ShowMeTheXAML.AvalonEdit" Version="2.0.0" />
2323
<PackageVersion Include="ShowMeTheXAML.MSBuild" Version="2.0.0" />
2424
<PackageVersion Include="VirtualizingWrapPanel" Version="1.5.7" />
25-
<PackageVersion Include="XAMLTest" Version="1.0.0-ci335" />
25+
<PackageVersion Include="XAMLTest" Version="1.0.0-ci390" />
2626
<PackageVersion Include="xunit" Version="2.4.2" />
2727
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.5" />
2828
<PackageVersion Include="Xunit.StaFact" Version="1.1.11" />

MaterialDesignThemes.UITests/MaterialDesignThemes.UITests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net6.0-windows</TargetFramework>
3+
<TargetFramework>net7.0-windows</TargetFramework>
44
<IsPackable>false</IsPackable>
55
<SignAssembly>false</SignAssembly>
66
<UseWPF>true</UseWPF>
Lines changed: 61 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,82 @@
11
using System.Windows.Media;
22

3-
namespace MaterialDesignThemes.UITests.WPF.Buttons
3+
namespace MaterialDesignThemes.UITests.WPF.Buttons;
4+
5+
public class OutlineButtonTests : TestBase
46
{
5-
public class OutlineButtonTests : TestBase
6-
{
7-
public OutlineButtonTests(ITestOutputHelper output)
8-
: base(output)
9-
{ }
7+
public OutlineButtonTests(ITestOutputHelper output)
8+
: base(output)
9+
{ }
1010

11-
[Fact]
12-
public async Task OutlinedButton_UsesThemeColorForBorder()
13-
{
14-
await using var recorder = new TestRecorder(App);
11+
[Fact]
12+
public async Task OutlinedButton_UsesThemeColorForBorder()
13+
{
14+
await using var recorder = new TestRecorder(App);
1515

16-
//Arrange
17-
IVisualElement<Button> button = await LoadXaml<Button>(
18-
@"<Button Content=""Button"" Style=""{StaticResource MaterialDesignOutlinedButton}""/>");
19-
Color midColor = await GetThemeColor("PrimaryHueMidBrush");
20-
IVisualElement<Border> internalBorder = await button.GetElement<Border>("border");
16+
//Arrange
17+
IVisualElement<Button> button = await LoadXaml<Button>(
18+
@"<Button Content=""Button"" Style=""{StaticResource MaterialDesignOutlinedButton}""/>");
19+
Color midColor = await GetThemeColor("PrimaryHueMidBrush");
20+
IVisualElement<Border> internalBorder = await button.GetElement<Border>("border");
2121

22-
//Act
23-
Color? borderColor = await button.GetBorderBrushColor();
24-
Color? internalBorderColor = await internalBorder.GetBorderBrushColor();
22+
//Act
23+
Color? borderColor = await button.GetBorderBrushColor();
24+
Color? internalBorderColor = await internalBorder.GetBorderBrushColor();
2525

26-
//Assert
27-
Assert.Equal(midColor, borderColor);
28-
Assert.Equal(midColor, internalBorderColor);
26+
//Assert
27+
Assert.Equal(midColor, borderColor);
28+
Assert.Equal(midColor, internalBorderColor);
2929

30-
recorder.Success();
31-
}
30+
recorder.Success();
31+
}
3232

33-
[Fact]
34-
public async Task OutlinedButton_BorderCanBeOverridden()
35-
{
36-
await using var recorder = new TestRecorder(App);
33+
[Fact]
34+
public async Task OutlinedButton_BorderCanBeOverridden()
35+
{
36+
await using var recorder = new TestRecorder(App);
3737

38-
//Arrange
39-
var button = await LoadXaml<Button>(
40-
@"<Button Content=""Button""
38+
//Arrange
39+
var button = await LoadXaml<Button>(
40+
@"<Button Content=""Button""
4141
Style=""{StaticResource MaterialDesignOutlinedButton}""
4242
BorderThickness=""5""
4343
BorderBrush=""Red""
4444
/>");
45-
Color midColor = await GetThemeColor("PrimaryHueMidBrush");
46-
IVisualElement<Border> internalBorder = await button.GetElement<Border>("border");
45+
Color midColor = await GetThemeColor("PrimaryHueMidBrush");
46+
IVisualElement<Border> internalBorder = await button.GetElement<Border>("border");
4747

48-
//Act
49-
Thickness borderThickness = await internalBorder.GetBorderThickness();
50-
Color? borderBrush = await internalBorder.GetBorderBrushColor();
48+
//Act
49+
Thickness borderThickness = await internalBorder.GetBorderThickness();
50+
Color? borderBrush = await internalBorder.GetBorderBrushColor();
5151

52-
//Assert
53-
Assert.Equal(new Thickness(5), borderThickness);
54-
Assert.Equal(Colors.Red, borderBrush);
52+
//Assert
53+
Assert.Equal(new Thickness(5), borderThickness);
54+
Assert.Equal(Colors.Red, borderBrush);
55+
56+
recorder.Success();
57+
}
58+
59+
[Fact]
60+
public async Task OutlinedButton_OnMouseOver_UsesThemeBrush()
61+
{
62+
await using var recorder = new TestRecorder(App);
5563

56-
recorder.Success();
57-
}
64+
//Arrange
65+
IVisualElement<Button> button = await LoadXaml<Button>(
66+
@"<Button Content=""Button"" Style=""{StaticResource MaterialDesignOutlinedButton}""/>");
67+
Color midColor = await GetThemeColor("PrimaryHueMidBrush");
68+
IVisualElement<Border> internalBorder = await button.GetElement<Border>("border");
5869

59-
[Fact]
60-
public async Task OutlinedButton_OnMouseOver_UsesThemeBrush()
70+
//Act
71+
await button.MoveCursorTo(Position.Center);
72+
await Wait.For(async () =>
6173
{
62-
await using var recorder = new TestRecorder(App);
63-
64-
//Arrange
65-
IVisualElement<Button> button = await LoadXaml<Button>(
66-
@"<Button Content=""Button"" Style=""{StaticResource MaterialDesignOutlinedButton}""/>");
67-
Color midColor = await GetThemeColor("PrimaryHueMidBrush");
68-
IVisualElement<Border> internalBorder = await button.GetElement<Border>("border");
69-
70-
//Act
71-
await button.MoveCursorTo(Position.Center);
72-
await Wait.For(async () =>
73-
{
74-
SolidColorBrush? internalBorderBackground = (await internalBorder.GetBackground()) as SolidColorBrush;
75-
76-
//Assert
77-
Assert.Equal(midColor, internalBorderBackground?.Color);
78-
});
79-
80-
recorder.Success();
81-
}
74+
SolidColorBrush? internalBorderBackground = (await internalBorder.GetBackground()) as SolidColorBrush;
75+
76+
//Assert
77+
Assert.Equal(midColor, internalBorderBackground?.Color);
78+
});
79+
80+
recorder.Success();
8281
}
8382
}
Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
using System.Windows.Media;
22

3-
namespace MaterialDesignThemes.UITests.WPF.Buttons
3+
namespace MaterialDesignThemes.UITests.WPF.Buttons;
4+
5+
public class RaisedButtonTests : TestBase
46
{
5-
public class RaisedButtonTests : TestBase
6-
{
7-
public RaisedButtonTests(ITestOutputHelper output)
8-
: base(output)
9-
{ }
7+
public RaisedButtonTests(ITestOutputHelper output)
8+
: base(output)
9+
{ }
1010

11-
[Fact]
12-
public async Task OnLoad_ThemeBrushesSet()
13-
{
14-
await using var recorder = new TestRecorder(App);
11+
[Fact]
12+
public async Task OnLoad_ThemeBrushesSet()
13+
{
14+
await using var recorder = new TestRecorder(App);
1515

16-
//Arrange
17-
IVisualElement<Button> button = await LoadXaml<Button>(@"<Button Content=""Button"" />");
18-
Color midColor = await GetThemeColor("PrimaryHueMidBrush");
16+
//Arrange
17+
IVisualElement<Button> button = await LoadXaml<Button>(@"<Button Content=""Button"" />");
18+
Color midColor = await GetThemeColor("PrimaryHueMidBrush");
1919

20-
//Act
21-
Color? color = await button.GetBackgroundColor();
20+
//Act
21+
Color? color = await button.GetBackgroundColor();
2222

23-
//Assert
24-
Assert.Equal(midColor, color);
23+
//Assert
24+
Assert.Equal(midColor, color);
2525

26-
recorder.Success();
27-
}
26+
recorder.Success();
2827
}
2928
}
Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,39 @@
11
using System.Windows.Media;
22

3-
namespace MaterialDesignThemes.UITests.WPF.ColorZones
3+
namespace MaterialDesignThemes.UITests.WPF.ColorZones;
4+
5+
public class ColorZoneTests : TestBase
46
{
5-
public class ColorZoneTests : TestBase
7+
public ColorZoneTests(ITestOutputHelper output)
8+
: base(output)
69
{
7-
public ColorZoneTests(ITestOutputHelper output)
8-
: base(output)
9-
{
1010

11-
}
11+
}
1212

13-
[Theory]
14-
[InlineData(ColorZoneMode.Standard, "MaterialDesignPaper", "MaterialDesignBody")]
15-
[InlineData(ColorZoneMode.Inverted, "MaterialDesignBody", "MaterialDesignPaper")]
16-
[InlineData(ColorZoneMode.PrimaryLight, "PrimaryHueLightBrush", "PrimaryHueLightForegroundBrush")]
17-
[InlineData(ColorZoneMode.PrimaryMid, "PrimaryHueMidBrush", "PrimaryHueMidForegroundBrush")]
18-
[InlineData(ColorZoneMode.PrimaryDark, "PrimaryHueDarkBrush", "PrimaryHueDarkForegroundBrush")]
19-
[InlineData(ColorZoneMode.SecondaryLight, "SecondaryHueLightBrush", "SecondaryHueLightForegroundBrush")]
20-
[InlineData(ColorZoneMode.SecondaryMid, "SecondaryHueMidBrush", "SecondaryHueMidForegroundBrush")]
21-
[InlineData(ColorZoneMode.SecondaryDark, "SecondaryHueDarkBrush", "SecondaryHueDarkForegroundBrush")]
22-
[InlineData(ColorZoneMode.Light, "MaterialDesignLightBackground", "MaterialDesignLightForeground")]
23-
[InlineData(ColorZoneMode.Dark, "MaterialDesignDarkBackground", "MaterialDesignDarkForeground")]
24-
public async Task Mode_SetsThemeColors(ColorZoneMode mode, string backgroundBrush, string foregroundBrush)
25-
{
26-
await using var recorder = new TestRecorder(App);
13+
[Theory]
14+
[InlineData(ColorZoneMode.Standard, "MaterialDesignPaper", "MaterialDesignBody")]
15+
[InlineData(ColorZoneMode.Inverted, "MaterialDesignBody", "MaterialDesignPaper")]
16+
[InlineData(ColorZoneMode.PrimaryLight, "PrimaryHueLightBrush", "PrimaryHueLightForegroundBrush")]
17+
[InlineData(ColorZoneMode.PrimaryMid, "PrimaryHueMidBrush", "PrimaryHueMidForegroundBrush")]
18+
[InlineData(ColorZoneMode.PrimaryDark, "PrimaryHueDarkBrush", "PrimaryHueDarkForegroundBrush")]
19+
[InlineData(ColorZoneMode.SecondaryLight, "SecondaryHueLightBrush", "SecondaryHueLightForegroundBrush")]
20+
[InlineData(ColorZoneMode.SecondaryMid, "SecondaryHueMidBrush", "SecondaryHueMidForegroundBrush")]
21+
[InlineData(ColorZoneMode.SecondaryDark, "SecondaryHueDarkBrush", "SecondaryHueDarkForegroundBrush")]
22+
[InlineData(ColorZoneMode.Light, "MaterialDesignLightBackground", "MaterialDesignLightForeground")]
23+
[InlineData(ColorZoneMode.Dark, "MaterialDesignDarkBackground", "MaterialDesignDarkForeground")]
24+
public async Task Mode_SetsThemeColors(ColorZoneMode mode, string backgroundBrush, string foregroundBrush)
25+
{
26+
await using var recorder = new TestRecorder(App);
2727

28-
IVisualElement<ColorZone> colorZone = await LoadXaml<ColorZone>(@$"
28+
IVisualElement<ColorZone> colorZone = await LoadXaml<ColorZone>(@$"
2929
<materialDesign:ColorZone Mode=""{mode}""/>
3030
");
31-
Color background = await GetThemeColor(backgroundBrush);
32-
Color foreground = await GetThemeColor(foregroundBrush);
31+
Color background = await GetThemeColor(backgroundBrush);
32+
Color foreground = await GetThemeColor(foregroundBrush);
3333

34-
Assert.Equal(background, await colorZone.GetBackgroundColor());
35-
Assert.Equal(foreground, await colorZone.GetForegroundColor());
34+
Assert.Equal(background, await colorZone.GetBackgroundColor());
35+
Assert.Equal(foreground, await colorZone.GetForegroundColor());
3636

37-
recorder.Success();
38-
}
37+
recorder.Success();
3938
}
4039
}

MaterialDesignThemes.UITests/WPF/ContentControls/ContentControlTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ public async Task ClearButton_InsideOfControlTemplate_CanStillClearContent()
3535

3636
//Assert
3737
Assert.Equal("Some Text", initial);
38-
Assert.True(string.IsNullOrEmpty(await textBox.GetText()));
38+
await Wait.For(async () =>
39+
{
40+
Assert.True(string.IsNullOrEmpty(await textBox.GetText()));
41+
});
3942

4043
recorder.Success();
4144
}

0 commit comments

Comments
 (0)