|
|
@ -3,32 +3,53 @@ using System.Globalization; |
|
|
using System.IO; |
|
|
using System.IO; |
|
|
using System.Runtime.InteropServices; |
|
|
using System.Runtime.InteropServices; |
|
|
using OpenQA.Selenium.Appium; |
|
|
using OpenQA.Selenium.Appium; |
|
|
|
|
|
using OpenQA.Selenium.Appium.Enums; |
|
|
|
|
|
using OpenQA.Selenium.Appium.Mac; |
|
|
using OpenQA.Selenium.Appium.Windows; |
|
|
using OpenQA.Selenium.Appium.Windows; |
|
|
|
|
|
|
|
|
namespace Avalonia.IntegrationTests.Win32 |
|
|
namespace Avalonia.IntegrationTests.Win32 |
|
|
{ |
|
|
{ |
|
|
public class TestAppFixture : IDisposable |
|
|
public class TestAppFixture : IDisposable |
|
|
{ |
|
|
{ |
|
|
private const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723"; |
|
|
private const string TestAppPath = @"..\..\..\..\..\samples\IntegrationTestApp\bin\Debug\net6.0\IntegrationTestApp"; |
|
|
private const string TestAppPath = @"..\..\..\..\..\samples\IntegrationTestApp\bin\Debug\net6.0\IntegrationTestApp.exe"; |
|
|
|
|
|
|
|
|
|
|
|
public TestAppFixture() |
|
|
public TestAppFixture() |
|
|
{ |
|
|
{ |
|
|
var opts = new AppiumOptions(); |
|
|
var opts = new AppiumOptions(); |
|
|
var path = Path.GetFullPath(TestAppPath); |
|
|
var path = Path.GetFullPath(TestAppPath); |
|
|
opts.AddAdditionalCapability("app", path); |
|
|
|
|
|
opts.AddAdditionalCapability("deviceName", "WindowsPC"); |
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
|
|
Session = new WindowsDriver<WindowsElement>( |
|
|
{ |
|
|
new Uri(WindowsApplicationDriverUrl), |
|
|
opts.AddAdditionalCapability(MobileCapabilityType.App, path + ".exe"); |
|
|
opts); |
|
|
opts.AddAdditionalCapability(MobileCapabilityType.PlatformName, MobilePlatform.Windows); |
|
|
|
|
|
opts.AddAdditionalCapability(MobileCapabilityType.DeviceName, "WindowsPC"); |
|
|
// https://github.com/microsoft/WinAppDriver/issues/1025
|
|
|
|
|
|
SetForegroundWindow(new IntPtr(int.Parse( |
|
|
Session = new WindowsDriver<AppiumWebElement>( |
|
|
Session.WindowHandles[0].Substring(2), |
|
|
new Uri("http://127.0.0.1:4723"), |
|
|
NumberStyles.AllowHexSpecifier))); |
|
|
opts); |
|
|
|
|
|
|
|
|
|
|
|
// https://github.com/microsoft/WinAppDriver/issues/1025
|
|
|
|
|
|
SetForegroundWindow(new IntPtr(int.Parse( |
|
|
|
|
|
Session.WindowHandles[0].Substring(2), |
|
|
|
|
|
NumberStyles.AllowHexSpecifier))); |
|
|
|
|
|
} |
|
|
|
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) |
|
|
|
|
|
{ |
|
|
|
|
|
opts.AddAdditionalCapability(MobileCapabilityType.App, path + ".exe"); |
|
|
|
|
|
opts.AddAdditionalCapability(MobileCapabilityType.PlatformName, MobilePlatform.MacOS); |
|
|
|
|
|
opts.AddAdditionalCapability(MobileCapabilityType.AutomationName, "mac2"); |
|
|
|
|
|
|
|
|
|
|
|
Session = new MacDriver<AppiumWebElement>( |
|
|
|
|
|
new Uri("http://127.0.0.1:4723/wd/hub"), |
|
|
|
|
|
opts); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
throw new NotSupportedException("Unsupported platform."); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public WindowsDriver<WindowsElement> Session { get; } |
|
|
public AppiumDriver<AppiumWebElement> Session { get; } |
|
|
|
|
|
|
|
|
public void Dispose() => Session.Close(); |
|
|
public void Dispose() => Session.Close(); |
|
|
|
|
|
|
|
|
|