-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
913db9b
commit 92ab789
Showing
45 changed files
with
1,059 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
sample/test/DeviceTestingKitApp.UITests.NUnitTests/PlaywrightServerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using DeviceRunners.UIAutomation.Appium; | ||
using DeviceRunners.UIAutomation.Playwright; | ||
|
||
using NUnit.Framework.Internal; | ||
using Microsoft.Playwright; | ||
|
||
namespace DeviceTestingKitApp.UITests.NUnitTests; | ||
|
||
public class PlaywrightServerTests | ||
{ | ||
public PlaywrightServerTests() | ||
{ | ||
} | ||
|
||
[Test] | ||
public async Task IsReady() | ||
{ | ||
using var playwright = await Playwright.CreateAsync(); | ||
|
||
await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions { Channel = "msedge" }); | ||
|
||
var page = await browser.NewPageAsync(); | ||
|
||
await page.GotoAsync("https://playwright.dev/dotnet"); | ||
|
||
await page.ScreenshotAsync(new() | ||
{ | ||
Path = "screenshot.png" | ||
}); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/DeviceRunners.UIAutomation.Playwright/AppiumAutomatedApp.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
namespace DeviceRunners.UIAutomation.Playwright; | ||
|
||
/// <summary> | ||
/// This type represents an automated app that is driven by Playwright. | ||
/// </summary> | ||
public class PlaywrightAutomatedApp : IAutomatedApp | ||
{ | ||
//private readonly PlaywrightAutomatedAppOptions _options; | ||
//private readonly IPlaywrightDiagnosticLogger? _logger; | ||
|
||
//public PlaywrightAutomatedApp(PlaywrightAutomationFramework playwright, PlaywrightAutomatedAppOptions options, IPlaywrightDiagnosticLogger? logger = null) | ||
//{ | ||
// Framework = playwright; | ||
// _options = options; | ||
// _logger = logger; | ||
// DriverManager = new PlaywrightDriverManager(Framework.ServiceManager, _options); | ||
// Commands = new AutomatedAppCommandManager(this, options.Commands); | ||
//} | ||
|
||
//public PlaywrightAutomationFramework Framework { get; } | ||
|
||
//public PlaywrightServiceManager ServiceManager => Framework.ServiceManager; | ||
|
||
//public PlaywrightDriverManager DriverManager { get; } | ||
|
||
//public PlaywrightDriver Driver => DriverManager.Driver; | ||
|
||
public IAutomatedAppCommandManager Commands { get; } | ||
|
||
IReadOnlyList<IAutomatedAppElement> IContainsElements.FindElements(Action<IBy> by) => null; | ||
IAutomatedAppElement IContainsElements.FindElement(Action<IBy> by) => null; | ||
|
||
//public PlaywrightAutomatedAppElement FindElement(Action<IBy> by) | ||
//{ | ||
// ArgumentNullException.ThrowIfNull(by); | ||
|
||
// var playwrightBy = _options.ByFactory.Create(this); | ||
// by(playwrightBy); | ||
|
||
// var element = Driver.FindElement(playwrightBy.ToBy()); | ||
|
||
// return new PlaywrightAutomatedAppElement(this, element); | ||
//} | ||
|
||
//IAutomatedAppElement IContainsElements.FindElement(Action<IBy> by) => | ||
// FindElement(by); | ||
|
||
//public IReadOnlyList<PlaywrightAutomatedAppElement> FindElements(Action<IBy> by) | ||
//{ | ||
// ArgumentNullException.ThrowIfNull(by); | ||
|
||
// var playwrightBy = _options.ByFactory.Create(this); | ||
// by(playwrightBy); | ||
|
||
// var elements = Driver.FindElements(playwrightBy.ToBy()); | ||
|
||
// return elements.Select(e => new PlaywrightAutomatedAppElement(this, e)).ToList(); | ||
//} | ||
|
||
//IReadOnlyList<IAutomatedAppElement> IContainsElements.FindElements(Action<IBy> by) => | ||
// FindElements(by); | ||
} |
18 changes: 18 additions & 0 deletions
18
src/DeviceRunners.UIAutomation.Playwright/AppiumAutomatedAppElement.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//using OpenQA.Selenium.Playwright; | ||
|
||
//namespace DeviceRunners.UIAutomation.Playwright; | ||
|
||
//public class PlaywrightAutomatedAppElement : IAutomatedAppElement | ||
//{ | ||
// public PlaywrightAutomatedAppElement(PlaywrightAutomatedApp app, PlaywrightElement element) | ||
// { | ||
// App = app; | ||
// PlaywrightElement = element; | ||
// } | ||
|
||
// public PlaywrightAutomatedApp App { get; } | ||
|
||
// public PlaywrightElement PlaywrightElement { get; } | ||
|
||
// IAutomatedApp IAutomatedAppElement.App => App; | ||
//} |
84 changes: 84 additions & 0 deletions
84
src/DeviceRunners.UIAutomation.Playwright/AppiumAutomationFramework.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
////namespace DeviceRunners.UIAutomation.Playwright; | ||
|
||
/////// <summary> | ||
/////// This type is responsible for creating and managing Playwright automated app instances. | ||
/////// </summary> | ||
////public class PlaywrightAutomationFramework : IAutomationFramework | ||
////{ | ||
//// private readonly PlaywrightServiceManagerOptions _options; | ||
//// private readonly IReadOnlyList<PlaywrightAutomatedAppOptions> _apps; | ||
//// private readonly IPlaywrightDiagnosticLogger? _logger; | ||
//// private PlaywrightServiceManager? _serviceManager; | ||
//// private bool _disposed; | ||
|
||
//// public PlaywrightAutomationFramework(PlaywrightServiceManagerOptions options, IEnumerable<PlaywrightAutomatedAppOptions> apps, IPlaywrightDiagnosticLogger? logger = null) | ||
//// { | ||
//// _options = options; | ||
//// _apps = apps.ToList(); | ||
//// _logger = logger; | ||
//// } | ||
|
||
//// public PlaywrightServiceManager ServiceManager | ||
//// { | ||
//// get | ||
//// { | ||
//// ObjectDisposedException.ThrowIf(_disposed, typeof(PlaywrightAutomationFramework)); | ||
//// return _serviceManager ??= new PlaywrightServiceManager(_options, _logger); | ||
//// } | ||
//// } | ||
|
||
//// public IReadOnlyList<PlaywrightAutomatedAppOptions> AvailableApps => _apps; | ||
|
||
//// public IAutomatedApp CreateApp(PlaywrightAutomatedAppOptions options) | ||
//// { | ||
//// return new PlaywrightAutomatedApp(this, options, _logger); | ||
//// } | ||
|
||
//// public void StartApp(PlaywrightAutomatedApp app) | ||
//// { | ||
//// app.DriverManager.StartDriver(); | ||
//// } | ||
|
||
//// public void StopApp(PlaywrightAutomatedApp app) | ||
//// { | ||
//// app.DriverManager.ShutdownDriver(); | ||
//// } | ||
|
||
//// public void RestartApp(PlaywrightAutomatedApp app) | ||
//// { | ||
//// app.DriverManager.RestartDriver(); | ||
//// } | ||
|
||
//// IReadOnlyList<IAutomatedAppOptions> IAutomationFramework.AvailableApps => _apps; | ||
|
||
//// IAutomatedApp IAutomationFramework.CreateApp(IAutomatedAppOptions options) | ||
//// { | ||
//// if (options is not PlaywrightAutomatedAppOptions playwrightOptions) | ||
//// throw new ArgumentException($"Expected {nameof(PlaywrightAutomatedAppOptions)} but got {options.GetType().Name}", nameof(options)); | ||
|
||
//// return CreateApp(playwrightOptions); | ||
//// } | ||
|
||
//// void IAutomationFramework.StartApp(IAutomatedApp app) => StartApp(AsPlaywrightApp(app)); | ||
|
||
//// void IAutomationFramework.StopApp(IAutomatedApp app) => StopApp(AsPlaywrightApp(app)); | ||
|
||
//// void IAutomationFramework.RestartApp(IAutomatedApp app) => RestartApp(AsPlaywrightApp(app)); | ||
|
||
//// public void Dispose() | ||
//// { | ||
//// if (_disposed) | ||
//// return; | ||
|
||
//// _disposed = true; | ||
|
||
//// _serviceManager?.Dispose(); | ||
//// } | ||
|
||
//// private static PlaywrightAutomatedApp AsPlaywrightApp(IAutomatedApp app) | ||
//// { | ||
//// if (app is not PlaywrightAutomatedApp playwrightApp) | ||
//// throw new ArgumentException($"Expected {nameof(PlaywrightAutomatedApp)} but got {app.GetType().Name}", nameof(app)); | ||
//// return playwrightApp; | ||
//// } | ||
////} |
43 changes: 43 additions & 0 deletions
43
src/DeviceRunners.UIAutomation.Playwright/AppiumAutomationOptionsBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//namespace DeviceRunners.UIAutomation.Playwright; | ||
|
||
///// <summary> | ||
///// This type is responsible for building the options for the Playwright automation framework. | ||
///// </summary> | ||
//public class PlaywrightAutomationOptionsBuilder | ||
//{ | ||
// private readonly List<IPlaywrightDiagnosticLogger> _loggers = []; | ||
// private readonly Dictionary<string, PlaywrightAutomatedAppOptions> _apps = []; | ||
|
||
// public PlaywrightAutomationOptionsBuilder UseServiceAddress( | ||
// string hostAddress = PlaywrightServiceManagerOptions.DefaultHostAddress, | ||
// int port = PlaywrightServiceManagerOptions.DefaultHostPort) | ||
// { | ||
// Options.HostAddress = hostAddress; | ||
// Options.HostPort = port; | ||
|
||
// return this; | ||
// } | ||
|
||
// public PlaywrightAutomationOptionsBuilder AddLogger(IPlaywrightDiagnosticLogger logger) | ||
// { | ||
// _loggers.Add(logger); | ||
|
||
// return this; | ||
// } | ||
|
||
// public PlaywrightAutomationOptionsBuilder AddApp(string key, PlaywrightAutomatedAppOptions options) | ||
// { | ||
// if (_apps.TryGetValue(key, out var existing)) | ||
// throw new InvalidOperationException($"App with key '{key}' was already added: {existing}"); | ||
|
||
// _apps[key] = options; | ||
|
||
// return this; | ||
// } | ||
|
||
// internal PlaywrightServiceManagerOptions Options { get; } = new(); | ||
|
||
// internal IReadOnlyCollection<PlaywrightAutomatedAppOptions> Apps => _apps.Values; | ||
|
||
// internal IReadOnlyCollection<IPlaywrightDiagnosticLogger> Loggers => _loggers; | ||
//} |
18 changes: 18 additions & 0 deletions
18
...IAutomation.Playwright/AutomatedBrowsers/Edge/AppiumAutomationOptionsBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//namespace DeviceRunners.UIAutomation.Playwright; | ||
|
||
//public static partial class PlaywrightAutomationOptionsBuilderExtensions | ||
//{ | ||
// public static PlaywrightAutomationOptionsBuilder AddAndroidApp(this PlaywrightAutomationOptionsBuilder builder, string key, Action<AndroidPlaywrightAutomatedAppOptionsBuilder> optionsAction) | ||
// { | ||
// var optionsBuilder = new AndroidPlaywrightAutomatedAppOptionsBuilder(key); | ||
|
||
// optionsBuilder.AddDefaultPlaywrightCommands(); | ||
// optionsBuilder.AddDefaultAndroidPlaywrightCommands(); | ||
|
||
// optionsAction(optionsBuilder); | ||
|
||
// builder.AddApp(key, optionsBuilder.Build()); | ||
|
||
// return builder; | ||
// } | ||
//} |
11 changes: 11 additions & 0 deletions
11
...nners.UIAutomation.Playwright/AutomatedBrowsers/Edge/EdgePlaywrightAutomatedAppOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Microsoft.Playwright; | ||
|
||
namespace DeviceRunners.UIAutomation.Playwright; | ||
|
||
public class EdgePlaywrightAutomatedAppOptions : PlaywrightAutomatedAppOptions | ||
{ | ||
public EdgePlaywrightAutomatedAppOptions(string key, IPlaywrightBrowserLaunchOptions launchOptions, IReadOnlyList<IAutomatedAppCommand> commands) | ||
: base(key, launchOptions, new PlaywrightDriverFactory(BrowserType.Chromium), new PlaywrightByFactory(), commands) | ||
{ | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...IAutomation.Playwright/AutomatedBrowsers/Edge/EdgePlaywrightAutomatedAppOptionsBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Microsoft.Playwright; | ||
|
||
namespace DeviceRunners.UIAutomation.Playwright; | ||
|
||
public class EdgePlaywrightAutomatedAppOptionsBuilder : PlaywrightAutomatedAppOptionsBuilder | ||
{ | ||
public EdgePlaywrightAutomatedAppOptionsBuilder(string key) | ||
: base(key, BrowserType.Chromium) | ||
{ | ||
LaunchOptions.GetOrAddBrowserTypeLaunchOptions().Channel = "msedge"; | ||
} | ||
|
||
public override PlaywrightAutomatedAppOptions Build() => | ||
new EdgePlaywrightAutomatedAppOptions(Key, LaunchOptions, Commands); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/DeviceRunners.UIAutomation.Playwright/AutomatedBrowsers/PlaywrightDriverFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Microsoft.Playwright; | ||
|
||
namespace DeviceRunners.UIAutomation.Playwright; | ||
|
||
public class PlaywrightDriverFactory : IPlaywrightDriverFactory | ||
{ | ||
public PlaywrightDriverFactory(string browserType) | ||
{ | ||
BrowserType = browserType; | ||
} | ||
|
||
public string BrowserType { get; } | ||
|
||
public IBrowser CreateDriver(PlaywrightServiceManager playwright, PlaywrightAutomatedAppOptions options) | ||
{ | ||
var type = playwright.Service[BrowserType]; | ||
var browserTask = type.LaunchAsync(options.LaunchOptions.GetBrowserTypeLaunchOptions()); | ||
var browser = browserTask.GetAwaiter().GetResult(); | ||
return browser; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/DeviceRunners.UIAutomation.Playwright/AutomationTestSuiteBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//namespace DeviceRunners.UIAutomation.Playwright; | ||
|
||
//public static class AutomationTestSuiteBuilderExtensions | ||
//{ | ||
// public static AutomationTestSuiteBuilder AddPlaywright(this AutomationTestSuiteBuilder builder, Action<PlaywrightAutomationOptionsBuilder> optionsAction) | ||
// { | ||
// var optionsBuilder = new PlaywrightAutomationOptionsBuilder(); | ||
|
||
// optionsAction(optionsBuilder); | ||
|
||
// var playwright = new PlaywrightAutomationFramework( | ||
// optionsBuilder.Options, | ||
// optionsBuilder.Apps, | ||
// new CompositeLogger(optionsBuilder.Loggers)); | ||
|
||
// builder.AddAutomationFramework(playwright); | ||
|
||
// return builder; | ||
// } | ||
|
||
// class CompositeLogger : IPlaywrightDiagnosticLogger | ||
// { | ||
// private readonly List<IPlaywrightDiagnosticLogger> _loggers; | ||
|
||
// public CompositeLogger(IEnumerable<IPlaywrightDiagnosticLogger> loggers) => | ||
// _loggers = loggers.ToList(); | ||
|
||
// public void Log(string message) | ||
// { | ||
// foreach (var logger in _loggers) | ||
// logger.Log(message); | ||
// } | ||
// } | ||
//} |
Oops, something went wrong.