Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#134 FIX #141

Merged
merged 4 commits into from
Feb 20, 2016
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
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 29 additions & 11 deletions appium-dotnet-driver/Appium/Android/AndroidDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,6 @@ public void ToggleLocationServices()
}


/// <summary>
/// Check if the device is locked
/// </summary>
/// <returns>true if device is locked, false otherwise</returns>
public bool IsLocked()
{
var commandResponse = this.Execute(AppiumDriverCommand.IsLocked, null);
return (bool)commandResponse.Value;
}


/// <summary>
/// Gets Current Device Activity.
/// </summary>
Expand Down Expand Up @@ -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<string, object> parameters = new Dictionary<string, object>();
parameters.Add("seconds", 0);
this.Execute(AppiumDriverCommand.LockDevice, parameters);
}

/// <summary>
/// Check if the device is locked
/// </summary>
/// <returns>true if device is locked, false otherwise</returns>
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

}
Expand Down
5 changes: 5 additions & 0 deletions appium-dotnet-driver/Appium/AppiumCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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

};
Expand Down
19 changes: 19 additions & 0 deletions appium-dotnet-driver/Appium/AppiumDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ public ReadOnlyCollection<W> FindElementsByAccessibilityId(string selector)
/// Locks the device.
/// </summary>
/// <param name="seconds">The number of seconds during which the device need to be locked for.</param>
[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<string, object> parameters = new Dictionary<string, object>();
Expand Down Expand Up @@ -898,6 +901,22 @@ public void Zoom(IWebElement el)

#endregion

#region Device Time
/// <summary>
/// Gets device date and time for both iOS(Supports only real device) and Android devices
/// </summary>
/// <returns>A string which consists of date and time</returns>
public String DeviceTime
{
get
{
var commandResponse = this.Execute(AppiumDriverCommand.GetDeviceTime, null);
return commandResponse.Value.ToString();
}
}

#endregion Device Time

#endregion Public Methods

#region Internal Methods
Expand Down
7 changes: 7 additions & 0 deletions appium-dotnet-driver/Appium/AppiumDriverCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public class AppiumDriverCommand
/// </summary>
public const string LockDevice = "lockDevice";

/// <summary>
/// Represents the Unlock Device Mapping command
/// </summary>
public const string UnlockDevice = "unlockDevice";

/// <summary>
/// Represents the Is Device Locked Mapping command
/// </summary>
Expand Down Expand Up @@ -252,6 +257,8 @@ public class AppiumDriverCommand

public const string SetValue = "setValue";

public const string GetDeviceTime = "getDeviceTime";

#endregion JSON Wire Protocol
}
}
12 changes: 12 additions & 0 deletions appium-dotnet-driver/Appium/iOS/IOSDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -177,5 +178,16 @@ public W GetNamedTextField(String name)
}
return element;
}

/// <summary>
/// Locks the device.
/// </summary>
/// <param name="seconds">The number of seconds during which the device need to be locked for.</param>
public void Lock(int seconds)
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("seconds", seconds);
this.Execute(AppiumDriverCommand.LockDevice, parameters);
}
}
}
4 changes: 3 additions & 1 deletion appium-dotnet-driver/appium-dotnet-driver.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
54 changes: 54 additions & 0 deletions integration_tests/Android/AndroidEmulatorDeviceTime.cs
Original file line number Diff line number Diff line change
@@ -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<AndroidElement> 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<AndroidElement>(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);
}

}
}
53 changes: 53 additions & 0 deletions integration_tests/Android/AndroidLockDeviceTest.cs
Original file line number Diff line number Diff line change
@@ -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<AndroidElement> 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<AndroidElement>(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());
}
}
}
51 changes: 51 additions & 0 deletions integration_tests/iOS/iOSLockDeviceTest.cs
Original file line number Diff line number Diff line change
@@ -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<IWebElement> 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<IWebElement>(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);
}
}
}
3 changes: 3 additions & 0 deletions integration_tests/integration_tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Android\AndroidEmulatorDeviceTime.cs" />
<Compile Include="Android\AndroidLockDeviceTest.cs" />
<Compile Include="Android\AndroidActivityTest.cs" />
<Compile Include="Android\AndroidConnectionTest.cs" />
<Compile Include="Android\AndroidElementTest.cs" />
Expand All @@ -68,6 +70,7 @@
<Compile Include="iOS\iOSElementTest.cs" />
<Compile Include="iOS\iOSGestureTest.cs" />
<Compile Include="iOS\iOSLocationTest.cs" />
<Compile Include="iOS\iOSLockDeviceTest.cs" />
<Compile Include="iOS\iOSOrientationTest.cs" />
<Compile Include="iOS\iOSScrollTest.cs" />
<Compile Include="iOS\iOSSearchingTest.cs" />
Expand Down
2 changes: 1 addition & 1 deletion test/specs/MJsonMethodTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void LockDeviceTestCase()
{
IOSDriver<IWebElement> driver = new IOSDriver<IWebElement>(defaultUri, capabilities);
server.respondTo("POST", "/appium/device/lock", null);
driver.LockDevice(3);
driver.Lock(3);
}


Expand Down