Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ App management: Please read [issue #15807](https://github.com/appium/appium/issu
> The original [WinAppDriver](https://github.com/microsoft/WinAppDriver) server has not been maintained by Microsoft for years and does not support the W3C WebDriver protocol. Direct communication between modern Appium .NET Client versions and standalone WinAppDriver is not supported.
>
> To automate Windows applications:
> - Use [appium-windows-driver](https://github.com/appium/appium-windows-driver) (`appium driver install windows`), which acts as a W3C-compliant proxy to WinAppDriver.
> - Consider trying [NovaWindows Driver](https://github.com/AutomateThePlanet/appium-novawindows-driver) by [Automate The Planet](https://www.automatetheplanet.com/) as a modern drop-in replacement that operates directly via FlaUI / UI Automation without WinAppDriver.
> - Use `WincoreDriver` with [appium-wincore-driver](https://github.com/appium/appium-wincore-driver) (`appium driver install wincore`), which operates directly via UI Automation without WinAppDriver.
> - Legacy `WindowsDriver` with [appium-windows-driver](https://github.com/appium/appium-windows-driver) (`appium driver install windows`) is deprecated and not supported since Appium 4.
>
> Examples of running Windows applications with the .NET client can be found in the [Windows Integration Tests](test/integration/Windows).

Expand Down
18 changes: 9 additions & 9 deletions src/Appium.Net/Appium/AppiumDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public byte[] PullFile(string pathOnDevice) =>
Convert.FromBase64String(Execute(AppiumDriverCommand.PullFile,
AppiumCommandExecutionHelper.PrepareArgument("path", pathOnDevice)).Value.ToString());

public byte[] PullFolder(string remotePath) =>
public virtual byte[] PullFolder(string remotePath) =>
Convert.FromBase64String(Execute(AppiumDriverCommand.PullFolder,
AppiumCommandExecutionHelper.PrepareArgument("path", remotePath)).Value.ToString());

Expand Down Expand Up @@ -621,22 +621,22 @@ private string GetSessionCapability(string name)

#region Recording Screen

public string StartRecordingScreen() =>
((IExecuteMethod)this).Execute(AppiumDriverCommand.StartRecordingScreen).Value.ToString();
public virtual string StartRecordingScreen() =>
((IExecuteMethod)this).Execute(AppiumDriverCommand.StartRecordingScreen).Value?.ToString();

public string StartRecordingScreen(IScreenRecordingOptions options)
public virtual string StartRecordingScreen(IScreenRecordingOptions options)
{
var parameters = AppiumCommandExecutionHelper.PrepareArgument("options", options.GetParameters());
return Execute(AppiumDriverCommand.StartRecordingScreen, parameters).Value.ToString();
return Execute(AppiumDriverCommand.StartRecordingScreen, parameters).Value?.ToString();
}

public string StopRecordingScreen() =>
((IExecuteMethod)this).Execute(AppiumDriverCommand.StopRecordingScreen).Value.ToString();
public virtual string StopRecordingScreen() =>
((IExecuteMethod)this).Execute(AppiumDriverCommand.StopRecordingScreen).Value?.ToString();

public string StopRecordingScreen(IScreenRecordingOptions options)
public virtual string StopRecordingScreen(IScreenRecordingOptions options)
{
var parameters = AppiumCommandExecutionHelper.PrepareArgument("options", options.GetParameters());
return Execute(AppiumDriverCommand.StopRecordingScreen, parameters).Value.ToString();
return Execute(AppiumDriverCommand.StopRecordingScreen, parameters).Value?.ToString();
}

#endregion Recording Screen
Expand Down
1 change: 1 addition & 0 deletions src/Appium.Net/Appium/Enums/AutomationName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ public sealed class AutomationName
public static readonly string AndroidEspresso = "Espresso";
public static readonly string YouiEngine = "youiengine";
public static readonly string Mac2 = "mac2";
public static readonly string Wincore = "Wincore";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace OpenQA.Selenium.Appium.ScreenRecording
{
public class ScreenRecordingUploadOptions
{
protected Dictionary<string, object> Parameters;
protected Dictionary<string, object> Parameters = [];

/// <summary>
/// The path to the remote location, where the resulting video should be uploaded.
Expand Down
229 changes: 229 additions & 0 deletions src/Appium.Net/Appium/Windows/WincoreDriver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//See the NOTICE file distributed with this work for additional
//information regarding copyright ownership.
//You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.

using System;
using OpenQA.Selenium.Appium.Android.Interfaces;
using OpenQA.Selenium.Appium.Enums;
using OpenQA.Selenium.Appium.Interfaces;
using OpenQA.Selenium.Appium.Service;

namespace OpenQA.Selenium.Appium.Windows
{
/// <summary>
/// WincoreDriver is an Appium driver created to automate Windows apps.
/// Read https://github.com/appium/appium-wincore-driver for more details.
/// </summary>
public class WincoreDriver : AppiumDriver, IPushesFiles
{
private static readonly string Platform = MobilePlatform.Windows;

/// <summary>
/// Initializes a new instance of the WincoreDriver class
/// </summary>
/// <param name="commandExecutor">An <see cref="ICommandExecutor"/> object which executes commands for the driver.</param>
/// <param name="driverOptions">An <see cref="DriverOptions"/> object containing the Appium options.</param>
public WincoreDriver(ICommandExecutor commandExecutor, DriverOptions driverOptions)
: base(commandExecutor, SetPlatformAndAutomationToCapabilities(driverOptions))
{
}

/// <summary>
/// Initializes a new instance of the WincoreDriver class using Appium options
/// </summary>
/// <param name="driverOptions">An <see cref="DriverOptions"/> object containing the Appium options of the browser.</param>
public WincoreDriver(DriverOptions driverOptions)
: base(SetPlatformAndAutomationToCapabilities(driverOptions))
{
}

/// <summary>
/// Initializes a new instance of the WincoreDriver class using Appium options and command timeout
/// </summary>
/// <param name="driverOptions">An <see cref="DriverOptions"/> object containing the Appium options.</param>
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
public WincoreDriver(DriverOptions driverOptions, TimeSpan commandTimeout)
: base(SetPlatformAndAutomationToCapabilities(driverOptions), commandTimeout)
{
}

/// <summary>
/// Initializes a new instance of the WincoreDriver class using the AppiumServiceBuilder instance and Appium options
/// </summary>
/// <param name="builder">The object containing settings of the Appium local service which is going to be started.</param>
/// <param name="driverOptions">An <see cref="DriverOptions"/> object containing the Appium options.</param>
public WincoreDriver(AppiumServiceBuilder builder, DriverOptions driverOptions)
: base(builder, SetPlatformAndAutomationToCapabilities(driverOptions))
{
}

/// <summary>
/// Initializes a new instance of the WincoreDriver class using the AppiumServiceBuilder instance, Appium options and command timeout
/// </summary>
/// <param name="builder">The object containing settings of the Appium local service which is going to be started.</param>
/// <param name="driverOptions">An <see cref="DriverOptions"/> object containing the Appium options.</param>
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
public WincoreDriver(AppiumServiceBuilder builder, DriverOptions driverOptions, TimeSpan commandTimeout)
: base(builder, SetPlatformAndAutomationToCapabilities(driverOptions), commandTimeout)
{
}

/// <summary>
/// Initializes a new instance of the WincoreDriver class using the specified remote address and Appium options
/// </summary>
/// <param name="remoteAddress">URI containing the address of the WebDriver remote server (e.g. http://127.0.0.1:4723/).</param>
/// <param name="driverOptions">An <see cref="DriverOptions"/> object containing the Appium options.</param>
public WincoreDriver(Uri remoteAddress, DriverOptions driverOptions)
: base(remoteAddress, SetPlatformAndAutomationToCapabilities(driverOptions))
{
}

/// <summary>
/// Initializes a new instance of the WincoreDriver class using the specified Appium local service and Appium options
/// </summary>
/// <param name="service">The specified Appium local service.</param>
/// <param name="driverOptions">An <see cref="DriverOptions"/> object containing the Appium options of the browser.</param>
public WincoreDriver(AppiumLocalService service, DriverOptions driverOptions)
: base(service, SetPlatformAndAutomationToCapabilities(driverOptions))
{
}

/// <summary>
/// Initializes a new instance of the WincoreDriver class using the specified remote address, Appium options, and command timeout.
/// </summary>
/// <param name="remoteAddress">URI containing the address of the WebDriver remote server (e.g. http://127.0.0.1:4723/).</param>
/// <param name="driverOptions">An <see cref="DriverOptions"/> object containing the Appium options.</param>
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
public WincoreDriver(Uri remoteAddress, DriverOptions driverOptions, TimeSpan commandTimeout)
: base(remoteAddress, SetPlatformAndAutomationToCapabilities(driverOptions), commandTimeout)
{
}

/// <summary>
/// Initializes a new instance of the WincoreDriver class using the specified Appium local service, Appium options, and command timeout.
/// </summary>
/// <param name="service">The specified Appium local service.</param>
/// <param name="driverOptions">An <see cref="DriverOptions"/> object containing the Appium options.</param>
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
public WincoreDriver(AppiumLocalService service, DriverOptions driverOptions, TimeSpan commandTimeout)
: base(service, SetPlatformAndAutomationToCapabilities(driverOptions), commandTimeout)
{
}

/// <summary>
/// Initializes a new instance of the WincoreDriver class using the specified remote address, Appium options and AppiumClientConfig.
/// </summary>
/// <param name="remoteAddress">URI containing the address of the WebDriver remote server (e.g. http://127.0.0.1:4723/).</param>
/// <param name="driverOptions">An <see cref="DriverOptions"/> object containing the Appium options.</param>
/// <param name="clientConfig">An instance of <see cref="AppiumClientConfig"/></param>
public WincoreDriver(Uri remoteAddress, DriverOptions driverOptions, AppiumClientConfig clientConfig)
: base(remoteAddress, SetPlatformAndAutomationToCapabilities(driverOptions), clientConfig)
{
}

/// <summary>
/// Initializes a new instance of the WincoreDriver class using the specified Appium local service, Appium options and AppiumClientConfig.
/// </summary>
/// <param name="service">The specified Appium local service.</param>
/// <param name="driverOptions">An <see cref="DriverOptions"/> object containing the Appium options.</param>
/// <param name="clientConfig">An instance of <see cref="AppiumClientConfig"/></param>
public WincoreDriver(AppiumLocalService service, DriverOptions driverOptions, AppiumClientConfig clientConfig)
: base(service, SetPlatformAndAutomationToCapabilities(driverOptions), clientConfig)
{
}

/// <summary>
/// Initializes a new instance of the WincoreDriver class using the specified remote address, Appium options, command timeout and AppiumClientConfig.
/// </summary>
/// <param name="remoteAddress">URI containing the address of the WebDriver remote server (e.g. http://127.0.0.1:4723/).</param>
/// <param name="driverOptions">An <see cref="DriverOptions"/> object containing the Appium options.</param>
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
/// <param name="clientConfig">An instance of <see cref="AppiumClientConfig"/></param>
public WincoreDriver(Uri remoteAddress, DriverOptions driverOptions, TimeSpan commandTimeout, AppiumClientConfig clientConfig)
: base(remoteAddress, SetPlatformAndAutomationToCapabilities(driverOptions), commandTimeout, clientConfig)
{
}

/// <summary>
/// Initializes a new instance of the WincoreDriver class using the specified Appium local service, Appium options, command timeout and AppiumClientConfig.
/// </summary>
/// <param name="service">The specified Appium local service.</param>
/// <param name="driverOptions">An <see cref="DriverOptions"/> object containing the Appium options.</param>
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
/// <param name="clientConfig">An instance of <see cref="AppiumClientConfig"/></param>
public WincoreDriver(AppiumLocalService service, DriverOptions driverOptions, TimeSpan commandTimeout, AppiumClientConfig clientConfig)
: base(service, SetPlatformAndAutomationToCapabilities(driverOptions), commandTimeout, clientConfig)
{
}

public override string StartRecordingScreen() =>
StartRecordingScreen(new WincoreStartScreenRecordingOptions());

public override string StartRecordingScreen(IScreenRecordingOptions options) =>
ExecuteScript("windows: startRecordingScreen", options.GetParameters())?.ToString();

public override string StopRecordingScreen() =>
StopRecordingScreen(new WincoreStopScreenRecordingOptions());

public override string StopRecordingScreen(IScreenRecordingOptions options) =>
ExecuteScript("windows: stopRecordingScreen", options.GetParameters())?.ToString();

public override byte[] PullFolder(string remotePath) =>
throw new NotSupportedException("The Wincore driver cannot pull folders");

#region App management

/// <summary>
/// Closes the Windows application.
/// </summary>
public void CloseApp() => ExecuteScript("windows: closeApp");

/// <summary>
/// Launches the Windows application.
/// </summary>
public void LaunchApp() => ExecuteScript("windows: launchApp");

#endregion App management

private static ICapabilities SetPlatformAndAutomationToCapabilities(DriverOptions driverOptions)
{
if (string.IsNullOrEmpty(driverOptions.PlatformName))
{
driverOptions.PlatformName = Platform;
}

if (driverOptions is AppiumOptions appiumOptions)
{
if (string.IsNullOrEmpty(appiumOptions.AutomationName))
{
appiumOptions.AutomationName = OpenQA.Selenium.Appium.Enums.AutomationName.Wincore;
}

return appiumOptions.ToCapabilities();
}

var capabilities = driverOptions.ToCapabilities();
var existingAutomationName = capabilities.GetCapability(MobileCapabilityType.AutomationName)
?? capabilities.GetCapability("automationName");
if (string.IsNullOrEmpty(existingAutomationName?.ToString()))
{
driverOptions.AddAdditionalOption(
MobileCapabilityType.AutomationName,
OpenQA.Selenium.Appium.Enums.AutomationName.Wincore);
capabilities = driverOptions.ToCapabilities();
}

return capabilities;
}
}
}
Loading
Loading