diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 4e578438..09f45dfb 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -4,6 +4,9 @@ - Update to Selenium.Webdriver v2.52.0 and Selenium.Support v2.52.0 - FIXED The issue of compatibility of AppiumServiceBuilder with Appium node server v >= 1.5.x. - Page object tools were updated. By.Name locator strategy is deprecated for Android and iOS. It is still valid for the Selendroid mode. +- The DeviceTime property was added and it works with Appium node 1.5 +- improvements of locking methods. The LockDevice(seconds) is obsolete and it is going to be removed in the next release. Since Appium node server v1.5.x it is recommended to use +AndroidDriver.Lock()()...AndroidDriver.Unlock() or IOSDriver.Lock(int seconds) instead. ##1.5.0.1 - Update to Selenium.Webdriver v2.48.2 and Selenium.Support v2.48.2 diff --git a/appium-dotnet-driver/Appium/Android/AndroidDriver.cs b/appium-dotnet-driver/Appium/Android/AndroidDriver.cs index 8d233771..edfad6f0 100644 --- a/appium-dotnet-driver/Appium/Android/AndroidDriver.cs +++ b/appium-dotnet-driver/Appium/Android/AndroidDriver.cs @@ -230,17 +230,6 @@ public void ToggleLocationServices() } - /// - /// Check if the device is locked - /// - /// true if device is locked, false otherwise - public bool IsLocked() - { - var commandResponse = this.Execute(AppiumDriverCommand.IsLocked, null); - return (bool)commandResponse.Value; - } - - /// /// Gets Current Device Activity. /// @@ -381,7 +370,36 @@ private static string UiScrollable(string uiSelector) { return "new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(" + uiSelector + ".instance(0));"; } + #endregion + + #region locking + /** + * This method locks a device. + */ + public void Lock() + { + Dictionary parameters = new Dictionary(); + parameters.Add("seconds", 0); + this.Execute(AppiumDriverCommand.LockDevice, parameters); + } + + /// + /// Check if the device is locked + /// + /// true if device is locked, false otherwise + public bool IsLocked() + { + var commandResponse = this.Execute(AppiumDriverCommand.IsLocked, null); + return (bool)commandResponse.Value; + } + /** + * This method unlocks a device. + */ + public void Unlock() + { + this.Execute(AppiumDriverCommand.UnlockDevice, null); + } #endregion } diff --git a/appium-dotnet-driver/Appium/AppiumCommand.cs b/appium-dotnet-driver/Appium/AppiumCommand.cs index 4c75c7b0..c13ef7da 100644 --- a/appium-dotnet-driver/Appium/AppiumCommand.cs +++ b/appium-dotnet-driver/Appium/AppiumCommand.cs @@ -33,6 +33,7 @@ internal class AppiumCommand new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.ShakeDevice, "/session/{sessionId}/appium/device/shake"), new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.LockDevice, "/session/{sessionId}/appium/device/lock"), new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.IsLocked, "/session/{sessionId}/appium/device/is_locked"), + new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.UnlockDevice, "/session/{sessionId}/appium/device/unlock"), new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.ToggleAirplaneMode, "/session/{sessionId}/appium/device/toggle_airplane_mode"), new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.KeyEvent, "/session/{sessionId}/appium/device/keyevent"), new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.Rotate, "/session/{sessionId}/appium/device/rotate"), @@ -83,6 +84,10 @@ internal class AppiumCommand new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.SetValue, "/session/{sessionId}/appium/element/{id}/value"), #endregion Input value + #region Device Time + new AppiumCommand(CommandInfo.GetCommand, AppiumDriverCommand.GetDeviceTime, "/session/{sessionId}/appium/device/system_time"), + #endregion Device Time + #endregion JSON Wire Protocol Commands }; diff --git a/appium-dotnet-driver/Appium/AppiumDriver.cs b/appium-dotnet-driver/Appium/AppiumDriver.cs index 153509a8..df00ca98 100644 --- a/appium-dotnet-driver/Appium/AppiumDriver.cs +++ b/appium-dotnet-driver/Appium/AppiumDriver.cs @@ -352,6 +352,9 @@ public ReadOnlyCollection FindElementsByAccessibilityId(string selector) /// Locks the device. /// /// The number of seconds during which the device need to be locked for. + [Obsolete("This method works incorrectly. It is deprecated and it is going to be removed further. " + + "Be careful. Since Appium node 1.5.x you are free to use. " + + "IOSDriver.Lock(int seconds) or AndroidDriver.Lock()...AndroidDriver.Unlock() instead")] public void LockDevice(int seconds) { Dictionary parameters = new Dictionary(); @@ -898,6 +901,22 @@ public void Zoom(IWebElement el) #endregion + #region Device Time + /// + /// Gets device date and time for both iOS(Supports only real device) and Android devices + /// + /// A string which consists of date and time + public String DeviceTime + { + get + { + var commandResponse = this.Execute(AppiumDriverCommand.GetDeviceTime, null); + return commandResponse.Value.ToString(); + } + } + + #endregion Device Time + #endregion Public Methods #region Internal Methods diff --git a/appium-dotnet-driver/Appium/AppiumDriverCommand.cs b/appium-dotnet-driver/Appium/AppiumDriverCommand.cs index 360aba35..5151e2f5 100644 --- a/appium-dotnet-driver/Appium/AppiumDriverCommand.cs +++ b/appium-dotnet-driver/Appium/AppiumDriverCommand.cs @@ -29,6 +29,11 @@ public class AppiumDriverCommand /// public const string LockDevice = "lockDevice"; + /// + /// Represents the Unlock Device Mapping command + /// + public const string UnlockDevice = "unlockDevice"; + /// /// Represents the Is Device Locked Mapping command /// @@ -252,6 +257,8 @@ public class AppiumDriverCommand public const string SetValue = "setValue"; + public const string GetDeviceTime = "getDeviceTime"; + #endregion JSON Wire Protocol } } diff --git a/appium-dotnet-driver/Appium/iOS/IOSDriver.cs b/appium-dotnet-driver/Appium/iOS/IOSDriver.cs index f0d7bc47..d45906fb 100644 --- a/appium-dotnet-driver/Appium/iOS/IOSDriver.cs +++ b/appium-dotnet-driver/Appium/iOS/IOSDriver.cs @@ -17,6 +17,7 @@ using OpenQA.Selenium.Appium.Service; using OpenQA.Selenium.Remote; using System; +using System.Collections.Generic; using System.Collections.ObjectModel; namespace OpenQA.Selenium.Appium.iOS @@ -177,5 +178,16 @@ public W GetNamedTextField(String name) } return element; } + + /// + /// Locks the device. + /// + /// The number of seconds during which the device need to be locked for. + public void Lock(int seconds) + { + Dictionary parameters = new Dictionary(); + parameters.Add("seconds", seconds); + this.Execute(AppiumDriverCommand.LockDevice, parameters); + } } } diff --git a/appium-dotnet-driver/appium-dotnet-driver.nuspec b/appium-dotnet-driver/appium-dotnet-driver.nuspec index f91ce14b..385db2ef 100644 --- a/appium-dotnet-driver/appium-dotnet-driver.nuspec +++ b/appium-dotnet-driver/appium-dotnet-driver.nuspec @@ -15,7 +15,9 @@ 1.5.1.1 Update to Selenium.Webdriver v2.52.0 and Selenium.Support v2.52.0 FIXED The issue of compatibility of AppiumServiceBuilder with Appium node server v >= 1.5.x. - Page object tools were updated. By.Name locator strategy is deprecated for Android and iOS. It is still valid for the Selendroid mode. + Page object tools were updated. By.Name locator strategy is deprecated for Android and iOS. It is still valid for the Selendroid mode. + The DeviceTime property was added and it works with Appium node 1.5 + improvements of locking methods. The LockDevice(seconds) is obsolete and it is going to be removed in the next release. Since Appium node server v1.5.x it is recommended to use AndroidDriver.Lock()()...AndroidDriver.Unlock() or IOSDriver.Lock(int seconds) instead. 1.5.0.1 Update to Selenium.Webdriver v2.48.2 and Selenium.Support v2.48.2 The ability to start appium server programmatically was provided. The ICommandServer implementation (AppiumLocalService). diff --git a/integration_tests/Android/AndroidEmulatorDeviceTime.cs b/integration_tests/Android/AndroidEmulatorDeviceTime.cs new file mode 100644 index 00000000..644c1491 --- /dev/null +++ b/integration_tests/Android/AndroidEmulatorDeviceTime.cs @@ -0,0 +1,54 @@ +using Appium.Integration.Tests.Helpers; +using NUnit.Framework; +using OpenQA.Selenium.Appium; +using OpenQA.Selenium.Appium.Android; +using OpenQA.Selenium.Remote; +using System; + +namespace Appium.Integration.Tests.Android +{ + class AndroidEmulatorDeviceTime + { + private AppiumDriver driver; + + [SetUp] + public void BeforeAll() + { + DesiredCapabilities capabilities = Env.isSauce() ? + Caps.getAndroid501Caps(Apps.get("androidApiDemos")) : + Caps.getAndroid19Caps(Apps.get("androidApiDemos")); + if (Env.isSauce()) + { + capabilities.SetCapability("username", Env.getEnvVar("SAUCE_USERNAME")); + capabilities.SetCapability("accessKey", Env.getEnvVar("SAUCE_ACCESS_KEY")); + capabilities.SetCapability("name", "android - complex"); + capabilities.SetCapability("tags", new string[] { "sample" }); + } + Uri serverUri = Env.isSauce() ? AppiumServers.sauceURI : AppiumServers.LocalServiceURIAndroid; + driver = new AndroidDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); + driver.Manage().Timeouts().ImplicitlyWait(Env.IMPLICIT_TIMEOUT_SEC); + } + + [TearDown] + public void AfterEach() + { + if (driver != null) + { + driver.Quit(); + } + if (!Env.isSauce()) + { + AppiumServers.StopLocalService(); + } + } + + [Test()] + public void DeviceTimeTest() + { + string time = driver.DeviceTime; + Console.WriteLine(time); + Assert.AreEqual(true, time.Length == 28); + } + + } +} diff --git a/integration_tests/Android/AndroidLockDeviceTest.cs b/integration_tests/Android/AndroidLockDeviceTest.cs new file mode 100644 index 00000000..2b43c587 --- /dev/null +++ b/integration_tests/Android/AndroidLockDeviceTest.cs @@ -0,0 +1,53 @@ +using Appium.Integration.Tests.Helpers; +using NUnit.Framework; +using OpenQA.Selenium.Appium.Android; +using OpenQA.Selenium.Remote; +using System; + +namespace Appium.Integration.Tests.Android +{ + class AndroidLockDeviceTest + { + private AndroidDriver driver; + + [SetUp] + public void BeforeAll() + { + DesiredCapabilities capabilities = Env.isSauce() ? + Caps.getAndroid501Caps(Apps.get("androidApiDemos")) : + Caps.getAndroid19Caps(Apps.get("androidApiDemos")); + if (Env.isSauce()) + { + capabilities.SetCapability("username", Env.getEnvVar("SAUCE_USERNAME")); + capabilities.SetCapability("accessKey", Env.getEnvVar("SAUCE_ACCESS_KEY")); + capabilities.SetCapability("name", "android - complex"); + capabilities.SetCapability("tags", new string[] { "sample" }); + } + Uri serverUri = Env.isSauce() ? AppiumServers.sauceURI : AppiumServers.LocalServiceURIAndroid; + driver = new AndroidDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); + driver.Manage().Timeouts().ImplicitlyWait(Env.IMPLICIT_TIMEOUT_SEC); + } + + [TearDown] + public void AfterEach() + { + if (driver != null) + { + driver.Quit(); + } + if (!Env.isSauce()) + { + AppiumServers.StopLocalService(); + } + } + + [Test()] + public void LockTest() + { + driver.Lock(); + Assert.AreEqual(true, driver.IsLocked()); + driver.Unlock(); + Assert.AreEqual(false, driver.IsLocked()); + } + } +} diff --git a/integration_tests/iOS/iOSLockDeviceTest.cs b/integration_tests/iOS/iOSLockDeviceTest.cs new file mode 100644 index 00000000..f0d87eea --- /dev/null +++ b/integration_tests/iOS/iOSLockDeviceTest.cs @@ -0,0 +1,51 @@ +using Appium.Integration.Tests.Helpers; +using NUnit.Framework; +using OpenQA.Selenium; +using OpenQA.Selenium.Appium.iOS; +using OpenQA.Selenium.Remote; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Appium.Integration.Tests.iOS +{ + class iOSLockDeviceTest + { + private IOSDriver driver; + + [TestFixtureSetUp] + public void BeforeAll() + { + DesiredCapabilities capabilities = Caps.getIos82Caps(Apps.get("iosWebviewApp")); + if (Env.isSauce()) + { + capabilities.SetCapability("username", Env.getEnvVar("SAUCE_USERNAME")); + capabilities.SetCapability("accessKey", Env.getEnvVar("SAUCE_ACCESS_KEY")); + capabilities.SetCapability("tags", new string[] { "sample" }); + } + Uri serverUri = Env.isSauce() ? AppiumServers.sauceURI : AppiumServers.LocalServiceURIForIOS; + driver = new IOSDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); + driver.Manage().Timeouts().ImplicitlyWait(Env.IMPLICIT_TIMEOUT_SEC); + } + + [TestFixtureTearDown] + public void AfterAll() + { + if (driver != null) + { + driver.Quit(); + } + if (!Env.isSauce()) + { + AppiumServers.StopLocalService(); + } + } + + [Test()] + public void LockTest() + { + driver.Lock(20); + } + } +} diff --git a/integration_tests/integration_tests.csproj b/integration_tests/integration_tests.csproj index f3c92570..2f4c0142 100644 --- a/integration_tests/integration_tests.csproj +++ b/integration_tests/integration_tests.csproj @@ -48,6 +48,8 @@ + + @@ -68,6 +70,7 @@ + diff --git a/test/specs/MJsonMethodTest.cs b/test/specs/MJsonMethodTest.cs index bcc2a822..9f61112d 100644 --- a/test/specs/MJsonMethodTest.cs +++ b/test/specs/MJsonMethodTest.cs @@ -49,7 +49,7 @@ public void LockDeviceTestCase() { IOSDriver driver = new IOSDriver(defaultUri, capabilities); server.respondTo("POST", "/appium/device/lock", null); - driver.LockDevice(3); + driver.Lock(3); }