From 6632172d1e676f73368f008d76913242e750bdce Mon Sep 17 00:00:00 2001 From: redth Date: Tue, 18 Jun 2024 11:27:17 -0400 Subject: [PATCH 1/2] Update to appium 5.0.0 Their driver has some removed methods (LaunchApp/CloseApp) which seem to be now implemented for windows. Also removed an extra explicit ref to system.drawing.common since it comes in transitively from appium.webdriver package (and the version was causing issues since the newer appium.webdriver uses a newer version). --- .../Controls.TestCases.Android.Tests.csproj | 2 +- .../Controls.TestCases.Mac.Tests.csproj | 2 +- .../Controls.TestCases.WinUI.Tests.csproj | 2 +- .../Controls.TestCases.iOS.Tests.csproj | 2 +- .../UITest.Appium/Actions/AppiumLifecycleActions.cs | 12 ------------ src/TestUtils/src/UITest.Appium/UITest.Appium.csproj | 3 +-- 6 files changed, 5 insertions(+), 18 deletions(-) diff --git a/src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj b/src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj index 4327a3a3cb23..050f80101590 100644 --- a/src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj +++ b/src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj @@ -10,7 +10,7 @@ - + diff --git a/src/Controls/tests/TestCases.Mac.Tests/Controls.TestCases.Mac.Tests.csproj b/src/Controls/tests/TestCases.Mac.Tests/Controls.TestCases.Mac.Tests.csproj index 19739d6177d6..408168b2f848 100644 --- a/src/Controls/tests/TestCases.Mac.Tests/Controls.TestCases.Mac.Tests.csproj +++ b/src/Controls/tests/TestCases.Mac.Tests/Controls.TestCases.Mac.Tests.csproj @@ -10,7 +10,7 @@ - + diff --git a/src/Controls/tests/TestCases.WinUI.Tests/Controls.TestCases.WinUI.Tests.csproj b/src/Controls/tests/TestCases.WinUI.Tests/Controls.TestCases.WinUI.Tests.csproj index 935c059d6d57..3279ab0fd0a9 100644 --- a/src/Controls/tests/TestCases.WinUI.Tests/Controls.TestCases.WinUI.Tests.csproj +++ b/src/Controls/tests/TestCases.WinUI.Tests/Controls.TestCases.WinUI.Tests.csproj @@ -10,7 +10,7 @@ - + diff --git a/src/Controls/tests/TestCases.iOS.Tests/Controls.TestCases.iOS.Tests.csproj b/src/Controls/tests/TestCases.iOS.Tests/Controls.TestCases.iOS.Tests.csproj index 8d90bbb080e1..d781e1e9465f 100644 --- a/src/Controls/tests/TestCases.iOS.Tests/Controls.TestCases.iOS.Tests.csproj +++ b/src/Controls/tests/TestCases.iOS.Tests/Controls.TestCases.iOS.Tests.csproj @@ -10,7 +10,7 @@ - + diff --git a/src/TestUtils/src/UITest.Appium/Actions/AppiumLifecycleActions.cs b/src/TestUtils/src/UITest.Appium/Actions/AppiumLifecycleActions.cs index 1132c1943ebe..abd33cd46a50 100644 --- a/src/TestUtils/src/UITest.Appium/Actions/AppiumLifecycleActions.cs +++ b/src/TestUtils/src/UITest.Appium/Actions/AppiumLifecycleActions.cs @@ -61,12 +61,6 @@ CommandResponse LaunchApp(IDictionary parameters) { "bundleId", _app.GetAppId() }, }); } - else if (_app.GetTestDevice() == TestDevice.Windows) - { -#pragma warning disable CS0618 // Type or member is obsolete - _app.Driver.LaunchApp(); -#pragma warning restore CS0618 // Type or member is obsolete - } else { _app.Driver.ActivateApp(_app.GetAppId()); @@ -143,12 +137,6 @@ CommandResponse CloseApp(IDictionary parameters) { "bundleId", _app.GetAppId() }, }); } - else if (_app.GetTestDevice() == TestDevice.Windows) - { - #pragma warning disable CS0618 // Type or member is obsolete - _app.Driver.CloseApp(); - #pragma warning restore CS0618 // Type or member is obsolete - } else { _app.Driver.TerminateApp(_app.GetAppId()); diff --git a/src/TestUtils/src/UITest.Appium/UITest.Appium.csproj b/src/TestUtils/src/UITest.Appium/UITest.Appium.csproj index 3d33c1a996c8..08b934d89b4c 100644 --- a/src/TestUtils/src/UITest.Appium/UITest.Appium.csproj +++ b/src/TestUtils/src/UITest.Appium/UITest.Appium.csproj @@ -7,8 +7,7 @@ - - + From bfe57d88f0401fa354f40934c0f4be45da20a3a4 Mon Sep 17 00:00:00 2001 From: redth Date: Tue, 18 Jun 2024 13:55:51 -0400 Subject: [PATCH 2/2] Fix windows launchapp/closeapp for newer appium In Appium's dotnet driver in v5.0.0 they removed `LaunchApp` from the driver: https://github.com/appium/dotnet-client/pull/766 The deprecation suggests using `ActivateApp` as an alternative, but that throws an error saying it's not implemented on the windows driver. Curiously, `CloseApp` which was also marked as deprecated was _moved_ from the base appium driver to the `WindowsDriver` here: https://github.com/appium/dotnet-client/pull/773 I think the same treatment should have been done to the `LaunchApp` method since there's no alternative in windows. For now the workaround is to invoke the command manually: `windowsDriver.ExecuteScript("windows: launchApp", [_app.GetAppId()]);` --- .../Actions/AppiumLifecycleActions.cs | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/TestUtils/src/UITest.Appium/Actions/AppiumLifecycleActions.cs b/src/TestUtils/src/UITest.Appium/Actions/AppiumLifecycleActions.cs index abd33cd46a50..fd1d13e24037 100644 --- a/src/TestUtils/src/UITest.Appium/Actions/AppiumLifecycleActions.cs +++ b/src/TestUtils/src/UITest.Appium/Actions/AppiumLifecycleActions.cs @@ -55,13 +55,21 @@ CommandResponse LaunchApp(IDictionary parameters) return CommandResponse.FailedEmptyResponse; if (_app.GetTestDevice() == TestDevice.Mac) - { + { _app.Driver.ExecuteScript("macos: activateApp", new Dictionary { { "bundleId", _app.GetAppId() }, }); } - else + else if (_app.Driver is WindowsDriver windowsDriver) + { + // Appium driver removed the LaunchApp method in 5.0.0, so we need to use the executeScript method instead + // Currently the appium-windows-driver reports the following commands as compatible: + // startRecordingScreen,stopRecordingScreen,launchApp,closeApp,deleteFile,deleteFolder, + // click,scroll,clickAndDrag,hover,keys,setClipboard,getClipboard + windowsDriver.ExecuteScript("windows: launchApp", [_app.GetAppId()]); + } + else { _app.Driver.ActivateApp(_app.GetAppId()); } @@ -121,7 +129,7 @@ CommandResponse CloseApp(IDictionary parameters) } catch (Exception) { - // TODO Pass in logger so we can log these exceptions + // TODO: Pass in logger so we can log these exceptions // Occasionally the app seems to get so locked up it can't // even report back the appstate. In that case, we'll just @@ -137,6 +145,13 @@ CommandResponse CloseApp(IDictionary parameters) { "bundleId", _app.GetAppId() }, }); } + else if (_app.Driver is WindowsDriver windowsDriver) + { + // This is still here for now, but it looks like it will get removed just like + // LaunchApp was in 5.0.0, in which case we may need to use: + // windowsDriver.ExecuteScript("windows: closeApp", [_app.GetAppId()]); + windowsDriver.CloseApp(); + } else { _app.Driver.TerminateApp(_app.GetAppId());