From 11763bf71168ac469f61fe9d91018dd099e02d6f Mon Sep 17 00:00:00 2001 From: Dor Blayzer <59066376+Dor-bl@users.noreply.github.com> Date: Sat, 13 Apr 2024 14:55:36 +0300 Subject: [PATCH] chore: Removal of obsolete CloseApp (#773) --- src/Appium.Net/Appium/AppiumCommand.cs | 6 ++-- src/Appium.Net/Appium/AppiumDriver.cs | 3 -- src/Appium.Net/Appium/AppiumDriverCommand.cs | 9 ------ .../Appium/Interfaces/IInteractsWithApps.cs | 5 ---- .../Appium/Windows/WindowsDriver.cs | 4 +-- .../Appium/Windows/WindowsDriverCommand.cs | 30 +++++++++++++++++++ test/integration/Android/SettingTest.cs | 7 +++-- test/integration/Android/WaitTests.cs | 13 ++++---- .../ServerTests/StartingAppLocallyTest.cs | 5 ++-- test/integration/Windows/ClickElementTest.cs | 17 ++++++----- .../Windows/ImagesComparisonTest.cs | 13 ++++---- 11 files changed, 66 insertions(+), 46 deletions(-) create mode 100644 src/Appium.Net/Appium/Windows/WindowsDriverCommand.cs diff --git a/src/Appium.Net/Appium/AppiumCommand.cs b/src/Appium.Net/Appium/AppiumCommand.cs index 758f1ac6..259c8cad 100644 --- a/src/Appium.Net/Appium/AppiumCommand.cs +++ b/src/Appium.Net/Appium/AppiumCommand.cs @@ -121,12 +121,12 @@ public class AppiumCommand new AppiumCommand(HttpCommandInfo.PostCommand, AppiumDriverCommand.GetPerformanceDataTypes, "/session/{sessionId}/appium/performanceData/types"), - #region (Deprecated) legacy app management + #region (WinAppDriver) legacy app management - new AppiumCommand(HttpCommandInfo.PostCommand, AppiumDriverCommand.CloseApp, + new AppiumCommand(HttpCommandInfo.PostCommand, WindowsDriverCommand.CloseApp, "/session/{sessionId}/appium/app/close"), - #endregion (Deprecated) legacy app management + #endregion (WinAppDriver) legacy app management new AppiumCommand(HttpCommandInfo.PostCommand, AppiumDriverCommand.BackgroundApp, "/session/{sessionId}/appium/app/background"), diff --git a/src/Appium.Net/Appium/AppiumDriver.cs b/src/Appium.Net/Appium/AppiumDriver.cs index 145b3f87..753ffc6c 100644 --- a/src/Appium.Net/Appium/AppiumDriver.cs +++ b/src/Appium.Net/Appium/AppiumDriver.cs @@ -182,9 +182,6 @@ public void PushFile(string pathOnDevice, byte[] base64Data) => public void PushFile(string pathOnDevice, FileInfo file) => AppiumCommandExecutionHelper.PushFile(this, pathOnDevice, file); - [Obsolete("The CloseApp API is deprecated and will be removed in future versions. Please use TerminateApp instead \r\n See https://github.com/appium/appium/issues/15807")] - public void CloseApp() => ((IExecuteMethod)this).Execute(AppiumDriverCommand.CloseApp); - public void FingerPrint(int fingerprintId) => AppiumCommandExecutionHelper.FingerPrint(this, fingerprintId); diff --git a/src/Appium.Net/Appium/AppiumDriverCommand.cs b/src/Appium.Net/Appium/AppiumDriverCommand.cs index 1390f4b0..87e0a77b 100644 --- a/src/Appium.Net/Appium/AppiumDriverCommand.cs +++ b/src/Appium.Net/Appium/AppiumDriverCommand.cs @@ -138,15 +138,6 @@ public class AppiumDriverCommand /// public const string ToggleLocationServices = "toggleLocationServices"; - #region (Deprecated) legacy app management - - /// - /// Close App Command. - /// - public const string CloseApp = "closeApp"; - - #endregion (Deprecated) legacy app management - /// /// Background App Command. /// diff --git a/src/Appium.Net/Appium/Interfaces/IInteractsWithApps.cs b/src/Appium.Net/Appium/Interfaces/IInteractsWithApps.cs index 6ed9e97a..6b2a527b 100644 --- a/src/Appium.Net/Appium/Interfaces/IInteractsWithApps.cs +++ b/src/Appium.Net/Appium/Interfaces/IInteractsWithApps.cs @@ -70,11 +70,6 @@ public interface IInteractsWithApps : IExecuteMethod /// a boolean indicating if the app was terminated in the given timeout. bool TerminateApp(string appId, TimeSpan timeout); - /// - /// Closes the current app. - /// - void CloseApp(); - /// /// Gets the State of the app. /// diff --git a/src/Appium.Net/Appium/Windows/WindowsDriver.cs b/src/Appium.Net/Appium/Windows/WindowsDriver.cs index a77fadef..b604c0ce 100644 --- a/src/Appium.Net/Appium/Windows/WindowsDriver.cs +++ b/src/Appium.Net/Appium/Windows/WindowsDriver.cs @@ -190,9 +190,9 @@ public void LongPressKeyCode(int keyCode, int metastate = -1) => #region App management - public new void CloseApp() + public void CloseApp() { - ((IExecuteMethod)this).Execute(AppiumDriverCommand.CloseApp); + ((IExecuteMethod)this).Execute(WindowsDriverCommand.CloseApp); } #endregion App management diff --git a/src/Appium.Net/Appium/Windows/WindowsDriverCommand.cs b/src/Appium.Net/Appium/Windows/WindowsDriverCommand.cs new file mode 100644 index 00000000..4bd4a448 --- /dev/null +++ b/src/Appium.Net/Appium/Windows/WindowsDriverCommand.cs @@ -0,0 +1,30 @@ +//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. + +namespace OpenQA.Selenium.Appium +{ + public class WindowsDriverCommand + { + + #region legacy app management + + /// + /// Close App Command. + /// + public const string CloseApp = "closeApp"; + + #endregion legacy app management + + } +} \ No newline at end of file diff --git a/test/integration/Android/SettingTest.cs b/test/integration/Android/SettingTest.cs index 018778b7..19555590 100644 --- a/test/integration/Android/SettingTest.cs +++ b/test/integration/Android/SettingTest.cs @@ -9,17 +9,18 @@ namespace Appium.Net.Integration.Tests.Android public class SettingTest { private AndroidDriver _driver; + private readonly string _appName = "androidApiDemos"; [OneTimeSetUp] public void BeforeAll() { var capabilities = Env.ServerIsRemote() - ? Caps.GetAndroidUIAutomatorCaps(Apps.Get("androidApiDemos")) - : Caps.GetAndroidUIAutomatorCaps(Apps.Get("androidApiDemos")); + ? Caps.GetAndroidUIAutomatorCaps(Apps.Get(_appName)) + : Caps.GetAndroidUIAutomatorCaps(Apps.Get(_appName)); var serverUri = Env.ServerIsRemote() ? AppiumServers.RemoteServerUri : AppiumServers.LocalServiceUri; _driver = new AndroidDriver(serverUri, capabilities, Env.InitTimeoutSec); _driver.Manage().Timeouts().ImplicitWait = Env.ImplicitTimeoutSec; - _driver.CloseApp(); + _driver.TerminateApp(Apps.GetId(_appName)); } [Test] diff --git a/test/integration/Android/WaitTests.cs b/test/integration/Android/WaitTests.cs index 6b8c8f61..9f492d21 100644 --- a/test/integration/Android/WaitTests.cs +++ b/test/integration/Android/WaitTests.cs @@ -13,14 +13,15 @@ public class WaitTests { private AndroidDriver _driver; private WebDriverWait _waitDriver; - private TimeSpan _driverTimeOut = TimeSpan.FromSeconds(5); + private readonly TimeSpan _driverTimeOut = TimeSpan.FromSeconds(5); + private readonly string _appKey = "androidApiDemos"; [OneTimeSetUp] public void BeforeAll() { var capabilities = Env.ServerIsRemote() - ? Caps.GetAndroidUIAutomatorCaps(Apps.Get("androidApiDemos")) - : Caps.GetAndroidUIAutomatorCaps(Apps.Get("androidApiDemos")); + ? Caps.GetAndroidUIAutomatorCaps(Apps.Get(_appKey)) + : Caps.GetAndroidUIAutomatorCaps(Apps.Get(_appKey)); var serverUri = Env.ServerIsRemote() ? AppiumServers.RemoteServerUri : AppiumServers.LocalServiceUri; _driver = new AndroidDriver(serverUri, capabilities, Env.InitTimeoutSec); } @@ -28,7 +29,7 @@ public void BeforeAll() [SetUp] public void SetUp() { - _driver.StartActivity("io.appium.android.apis", ".ApiDemos"); + _driver.StartActivity(Apps.GetId(_appKey), ".ApiDemos"); _waitDriver = new WebDriverWait(_driver, _driverTimeOut); _waitDriver.IgnoreExceptionTypes(typeof(NoSuchElementException)); } @@ -53,7 +54,7 @@ public void WebDriverWaitElementNotFoundTestCase() [Test] public void WebDriverWaitIsWaitingTestCase() { - Stopwatch stopWatch = new Stopwatch(); + Stopwatch stopWatch = new(); stopWatch.Start(); try @@ -76,7 +77,7 @@ public void AfterAll() { if (_driver != null) { - _driver.CloseApp(); + _ = _driver.TerminateApp(Apps.GetId(_appKey)); _driver?.Quit(); } if (!Env.ServerIsRemote()) diff --git a/test/integration/ServerTests/StartingAppLocallyTest.cs b/test/integration/ServerTests/StartingAppLocallyTest.cs index 9a94e667..762d46b4 100644 --- a/test/integration/ServerTests/StartingAppLocallyTest.cs +++ b/test/integration/ServerTests/StartingAppLocallyTest.cs @@ -57,7 +57,6 @@ public void StartingAndroidAppWithCapabilitiesAndServiceTest() } } - [Test] public void StartingAndroidAppWithCapabilitiesOnTheServerSideTest() { @@ -97,7 +96,7 @@ public void StartingIosAppWithCapabilitiesOnlyTest() try { driver = new IOSDriver(capabilities, Env.InitTimeoutSec); - driver.CloseApp(); + driver.TerminateApp(Apps.GetId("iosTestApp")); } finally { @@ -120,7 +119,7 @@ public void StartingIosAppWithCapabilitiesAndServiceTest() try { driver = new IOSDriver(builder, capabilities, Env.InitTimeoutSec); - driver.CloseApp(); + driver.TerminateApp(Apps.GetId("iosTestApp")); } finally { diff --git a/test/integration/Windows/ClickElementTest.cs b/test/integration/Windows/ClickElementTest.cs index 9f32894b..a4fc5234 100644 --- a/test/integration/Windows/ClickElementTest.cs +++ b/test/integration/Windows/ClickElementTest.cs @@ -24,15 +24,18 @@ public class ClickElementTest { private WindowsDriver _calculatorSession; protected static WebElement CalculatorResult; + private readonly string _appId = "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App"; [OneTimeSetUp] public void BeforeAll() { - var appCapabilities = new AppiumOptions(); - appCapabilities.AutomationName = "Windows"; - appCapabilities.App = "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App"; - appCapabilities.DeviceName = "WindowsPC"; - appCapabilities.PlatformName = "Windows"; + var appCapabilities = new AppiumOptions + { + AutomationName = "Windows", + App = _appId, + DeviceName = "WindowsPC", + PlatformName = "Windows" + }; var serverUri = Env.ServerIsRemote() ? AppiumServers.RemoteServerUri : AppiumServers.LocalServiceUri; _calculatorSession = new WindowsDriver(serverUri, appCapabilities, @@ -49,8 +52,8 @@ public void BeforeAll() public void OneTimeTearDown() { CalculatorResult = null; - _calculatorSession.CloseApp(); - _calculatorSession.Dispose(); + _calculatorSession?.CloseApp(); + _calculatorSession?.Dispose(); _calculatorSession = null; } diff --git a/test/integration/Windows/ImagesComparisonTest.cs b/test/integration/Windows/ImagesComparisonTest.cs index 21e98609..89e81134 100644 --- a/test/integration/Windows/ImagesComparisonTest.cs +++ b/test/integration/Windows/ImagesComparisonTest.cs @@ -11,15 +11,18 @@ public class ImagesComparisonTests { private WindowsDriver _calculatorSession; protected static WebElement CalculatorResult; + private readonly string _appId = "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App"; [OneTimeSetUp] public void BeforeAll() { - var appCapabilities = new AppiumOptions(); - appCapabilities.App = "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App"; - appCapabilities.DeviceName = "WindowsPC"; - appCapabilities.PlatformName = "Windows"; - appCapabilities.AutomationName = "Windows"; + var appCapabilities = new AppiumOptions + { + App = _appId, + DeviceName = "WindowsPC", + PlatformName = "Windows", + AutomationName = "Windows" + }; var serverUri = Env.ServerIsRemote() ? AppiumServers.RemoteServerUri : AppiumServers.LocalServiceUri; _calculatorSession = new WindowsDriver(serverUri, appCapabilities,