Maui.UITesting/tests/RemoteAutomationTests/UnitTest1.cs

69 строки
2.3 KiB
C#
Исходник Обычный вид История

2021-12-24 22:10:25 +03:00
using Microsoft.Maui.Automation;
using Microsoft.Maui.Automation.Remote;
using System.Net;
using System.Threading.Tasks;
using Xunit;
namespace RemoteAutomationTests
{
public class UnitTest1
{
[Fact]
2021-12-28 23:28:02 +03:00
public async Task ListWindowsTest()
2021-12-24 22:10:25 +03:00
{
// Start the 'test runner' as a server, listening for the 'app/device' to connect
var tcsHost = new TaskCompletionSource<TcpRemoteApplication>();
_ = Task.Run(() =>
tcsHost.TrySetResult(new TcpRemoteApplication(IPAddress.Any)));
// Build a mock app
var app = new MockApplication()
2021-12-28 01:48:24 +03:00
.WithWindow("window1", "Window", "Window Title")
.WithView("view1");
2021-12-24 22:10:25 +03:00
// Create our app host service implementation
var service = new RemoteAutomationService(app);
// Connect the 'app/device' as a client
var device = new TcpRemoteApplication(IPAddress.Loopback, listen: false, remoteAutomationService: service);
// Wait until the client connects to the host to proceed
var runner = await tcsHost.Task;
// Query the remote host
var windows = await runner.Windows();
Assert.NotEmpty(windows);
}
2021-12-28 23:28:02 +03:00
[Fact]
public async Task IdSelectorTest()
{
// Start the 'test runner' as a server, listening for the 'app/device' to connect
var tcsHost = new TaskCompletionSource<TcpRemoteApplication>();
_ = Task.Run(() =>
tcsHost.TrySetResult(new TcpRemoteApplication(IPAddress.Any)));
// Build a mock app
var app = new MockApplication()
.WithWindow("window1", "Window", "Window Title")
.WithView("view1");
var window = app.CurrentMockWindow;
// Create our app host service implementation
var service = new RemoteAutomationService(app);
// Connect the 'app/device' as a client
var device = new TcpRemoteApplication(IPAddress.Loopback, listen: false, remoteAutomationService: service);
// Wait until the client connects to the host to proceed
var runner = await tcsHost.Task;
var v = await runner.Descendant(window!, new IdSelector("view1"));
Assert.NotNull(v);
}
2021-12-24 22:10:25 +03:00
}
}