Implement recorder PoC (#6)
This commit is contained in:
12
tests/Recordingtest.Recorder.Tests/FakeElement.cs
Normal file
12
tests/Recordingtest.Recorder.Tests/FakeElement.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace Recordingtest.Recorder.Tests;
|
||||
|
||||
internal sealed class FakeElement : IElementSnapshot
|
||||
{
|
||||
public string ClassName { get; set; } = "Element";
|
||||
public string? AutomationId { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public bool IsPassword { get; set; }
|
||||
public (double Left, double Top, double Width, double Height) BoundingRectangle { get; set; }
|
||||
= (0, 0, 0, 0);
|
||||
public IElementSnapshot? Parent { get; set; }
|
||||
}
|
||||
141
tests/Recordingtest.Recorder.Tests/RecorderTests.cs
Normal file
141
tests/Recordingtest.Recorder.Tests/RecorderTests.cs
Normal file
@@ -0,0 +1,141 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Xunit;
|
||||
|
||||
namespace Recordingtest.Recorder.Tests;
|
||||
|
||||
public class RecorderTests
|
||||
{
|
||||
[Fact]
|
||||
public void ElementPathBuilder_WithNestedElements_ReturnsFullPath()
|
||||
{
|
||||
var window = new FakeElement
|
||||
{
|
||||
ClassName = "Window",
|
||||
Name = "Main",
|
||||
};
|
||||
var panel = new FakeElement
|
||||
{
|
||||
ClassName = "StackPanel",
|
||||
AutomationId = "ToolStrip",
|
||||
Parent = window,
|
||||
};
|
||||
var button = new FakeElement
|
||||
{
|
||||
ClassName = "Button",
|
||||
AutomationId = "BoxCommand",
|
||||
Parent = panel,
|
||||
};
|
||||
|
||||
var path = ElementPathBuilder.Build(button);
|
||||
|
||||
Assert.Equal(
|
||||
"Window[@Name='Main']/StackPanel[@AutomationId='ToolStrip']/Button[@AutomationId='BoxCommand']",
|
||||
path);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OffsetNormalizer_ClicksInsideElement_ReturnsZeroToOne()
|
||||
{
|
||||
var bounds = (Left: 100.0, Top: 200.0, Width: 400.0, Height: 200.0);
|
||||
|
||||
var (dx, dy) = OffsetNormalizer.Normalize(bounds, 300, 300);
|
||||
|
||||
Assert.Equal(0.5, dx, 6);
|
||||
Assert.Equal(0.5, dy, 6);
|
||||
|
||||
var (dx2, dy2) = OffsetNormalizer.Normalize(bounds, 100, 200);
|
||||
Assert.Equal(0.0, dx2, 6);
|
||||
Assert.Equal(0.0, dy2, 6);
|
||||
|
||||
// Out-of-bounds clamps into [0,1]
|
||||
var (dx3, dy3) = OffsetNormalizer.Normalize(bounds, 9999, -9999);
|
||||
Assert.InRange(dx3, 0.0, 1.0);
|
||||
Assert.InRange(dy3, 0.0, 1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FocusedElementIsPassword_ReturnsMasked()
|
||||
{
|
||||
var pwd = new FakeElement
|
||||
{
|
||||
ClassName = "PasswordBox",
|
||||
IsPassword = true,
|
||||
};
|
||||
|
||||
var value = MaskPolicy.Apply(pwd, "supersecret");
|
||||
|
||||
Assert.Equal("<MASKED>", value);
|
||||
Assert.True(MaskPolicy.IsMasked(pwd));
|
||||
|
||||
var plain = new FakeElement { ClassName = "TextBox" };
|
||||
Assert.Equal("hello", MaskPolicy.Apply(plain, "hello"));
|
||||
Assert.False(MaskPolicy.IsMasked(plain));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void YamlSerializer_RoundtripsScenario()
|
||||
{
|
||||
var s = new Scenario
|
||||
{
|
||||
Name = "smoke",
|
||||
Description = "round trip",
|
||||
Sut = new ScenarioSut
|
||||
{
|
||||
Exe = "EG-BIM Modeler/EG-BIM Modeler.exe",
|
||||
StartupTimeoutMs = 15000,
|
||||
},
|
||||
Steps =
|
||||
{
|
||||
new ScenarioStep
|
||||
{
|
||||
Kind = "click",
|
||||
Target = new ScenarioTarget
|
||||
{
|
||||
UiaPath = "Window[@Name='Main']/Button[@AutomationId='BoxCommand']",
|
||||
Offset = new[] { 0.5, 0.5 },
|
||||
},
|
||||
Value = null,
|
||||
WaitFor = null,
|
||||
},
|
||||
new ScenarioStep
|
||||
{
|
||||
Kind = "type",
|
||||
Target = new ScenarioTarget
|
||||
{
|
||||
UiaPath = "Window[@Name='Main']/Edit[@AutomationId='Pwd']",
|
||||
Offset = new[] { 0.5, 0.5 },
|
||||
},
|
||||
Value = "<MASKED>",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
var yaml = ScenarioWriter.Serialize(s);
|
||||
var parsed = ScenarioWriter.Deserialize(yaml);
|
||||
|
||||
Assert.Equal(s.Name, parsed.Name);
|
||||
Assert.Equal(s.Description, parsed.Description);
|
||||
Assert.Equal(s.Sut.Exe, parsed.Sut.Exe);
|
||||
Assert.Equal(s.Sut.StartupTimeoutMs, parsed.Sut.StartupTimeoutMs);
|
||||
Assert.Equal(s.Steps.Count, parsed.Steps.Count);
|
||||
Assert.Equal(s.Steps[0].Target!.UiaPath, parsed.Steps[0].Target!.UiaPath);
|
||||
Assert.Equal(s.Steps[1].Value, parsed.Steps[1].Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Cli_MissingAttach_ExitTwo()
|
||||
{
|
||||
var stderr = Console.Error;
|
||||
try
|
||||
{
|
||||
Console.SetError(new StringWriter());
|
||||
var rc = Program.Main(new[] { "--output", "scenarios/x.yaml" });
|
||||
Assert.Equal(2, rc);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Console.SetError(stderr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<UseWPF>false</UseWPF>
|
||||
<UseWindowsForms>false</UseWindowsForms>
|
||||
<IsPackable>false</IsPackable>
|
||||
<RootNamespace>Recordingtest.Recorder.Tests</RootNamespace>
|
||||
<AssemblyName>Recordingtest.Recorder.Tests</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Recordingtest.Recorder\Recordingtest.Recorder.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user