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

Feature/win #158

Merged
merged 12 commits into from
Sep 4, 2016
2 changes: 2 additions & 0 deletions appium-dotnet-driver/Appium/Enums/MobilePlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public sealed class MobilePlatform

public static readonly string IOS = "iOS";

public static readonly string Windows = "Windows";

//FireFoxOS and WinPhone will be added when there will be the supporting of appropriate mobile OS.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//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.Collections.ObjectModel;

namespace OpenQA.Selenium.Appium.Interfaces
{
public interface IFindByWindowsUIAutomation<W> where W : IWebElement
{
/// <summary>
/// Finds the first of elements that match the Windows UIAutomation selector supplied
/// </summary>
/// <param name="selector">a Windows UIAutomation selector</param>
/// <returns>IWebElement object so that you can interact that object</returns>
W FindElementByWindowsUIAutomation(string selector);

/// <summary>
/// Finds a list of elements that match the Windows UIAutomation selector supplied
/// </summary>
/// <param name="selector">a Windows UIAutomation selector</param>
/// <returns>ReadOnlyCollection of IWebElement objects so that you can interact with those objects</returns>
ReadOnlyCollection<W> FindElementsByWindowsUIAutomation(string selector);
}
}
37 changes: 37 additions & 0 deletions appium-dotnet-driver/Appium/Windows/Enums/WindowsKeyCodes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//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.Windows.Enums
{
public sealed class WindowsKeyCode
{
public static readonly int Power = 0;
public static readonly int Windows = 1;
public static readonly int VolumeUp = 2;
public static readonly int VolumeDown = 3;
public static readonly int RotationLock = 4;
public static readonly int CountMin = 5;
public static readonly int Back = 5;
public static readonly int Search = 6;
public static readonly int CameraFocus = 7;
public static readonly int CameraShutter = 8;
public static readonly int RingerToggle = 9;
public static readonly int Headset = 10;
public static readonly int HwkbDploy = 11;
public static readonly int CameraLens = 12;
public static readonly int OemCustom = 13;
public static readonly int OemCustom2 = 14;
public static readonly int OemCustom3 = 15;
public static readonly int Count = 16;
}
}
198 changes: 198 additions & 0 deletions appium-dotnet-driver/Appium/Windows/WindowsDriver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
//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 System.Collections.Generic;
using System.Collections.ObjectModel;
using OpenQA.Selenium.Appium.Enums;
using OpenQA.Selenium.Appium.Interfaces;
using OpenQA.Selenium.Appium.Service;
using OpenQA.Selenium.Remote;

namespace OpenQA.Selenium.Appium.Windows
{
public class WindowsDriver<W> : AppiumDriver<W>, IFindByWindowsUIAutomation<W> where W : IWebElement
{
private static readonly string Platform = MobilePlatform.Windows;

/// <summary>
/// Initializes a new instance of the WindowsDriver class using desired capabilities
/// </summary>
/// <param name="desiredCapabilities">An <see cref="DesiredCapabilities"/> object containing the desired capabilities of the browser.</param>
public WindowsDriver(DesiredCapabilities desiredCapabilities)
: base(SetPlatformToCapabilities(desiredCapabilities, Platform))
{
}

/// <summary>
/// Initializes a new instance of the WindowsDriver class using desired capabilities and command timeout
/// </summary>
/// <param name="desiredCapabilities">An <see cref="ICapabilities"/> object containing the desired capabilities.</param>
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
public WindowsDriver(DesiredCapabilities desiredCapabilities, TimeSpan commandTimeout)
: base(SetPlatformToCapabilities(desiredCapabilities, Platform), commandTimeout)
{
}

/// <summary>
/// Initializes a new instance of the WindowsDriver class using the AppiumServiceBuilder instance and desired capabilities
/// </summary>
/// <param name="builder"> object containing settings of the Appium local service which is going to be started</param>
/// <param name="desiredCapabilities">An <see cref="ICapabilities"/> object containing the desired capabilities.</param>
public WindowsDriver(AppiumServiceBuilder builder, DesiredCapabilities desiredCapabilities)
: base(builder, SetPlatformToCapabilities(desiredCapabilities, Platform))
{
}

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

/// <summary>
/// Initializes a new instance of the WindowsDriver class using the specified remote address and desired capabilities
/// </summary>
/// <param name="remoteAddress">URI containing the address of the WebDriver remote server (e.g. http://127.0.0.1:4723/wd/hub).</param>
/// <param name="desiredCapabilities">An <see cref="DesiredCapabilities"/> object containing the desired capabilities.</param>
public WindowsDriver(Uri remoteAddress, DesiredCapabilities desiredCapabilities)
: base(remoteAddress, SetPlatformToCapabilities(desiredCapabilities, Platform))
{
}

/// <summary>
/// Initializes a new instance of the WindowsDriver class using the specified Appium local service and desired capabilities
/// </summary>
/// <param name="service">the specified Appium local service</param>
/// <param name="desiredCapabilities">An <see cref="ICapabilities"/> object containing the desired capabilities of the browser.</param>
public WindowsDriver(AppiumLocalService service, DesiredCapabilities desiredCapabilities)
: base(service, SetPlatformToCapabilities(desiredCapabilities, Platform))
{
}

/// <summary>
/// Initializes a new instance of the WindowsDriver class using the specified remote address, desired capabilities, and command timeout.
/// </summary>
/// <param name="remoteAddress">URI containing the address of the WebDriver remote server (e.g. http://127.0.0.1:4723/wd/hub).</param>
/// <param name="desiredCapabilities">An <see cref="DesiredCapabilities"/> object containing the desired capabilities.</param>
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
public WindowsDriver(Uri remoteAddress, DesiredCapabilities desiredCapabilities, TimeSpan commandTimeout)
: base(remoteAddress, SetPlatformToCapabilities(desiredCapabilities, Platform), commandTimeout)
{
}

/// <summary>
/// Initializes a new instance of the WindowsDriver class using the specified Appium local service, desired capabilities, and command timeout.
/// </summary>
/// <param name="service">the specified Appium local service</param>
/// <param name="desiredCapabilities">An <see cref="ICapabilities"/> object containing the desired capabilities.</param>
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
public WindowsDriver(AppiumLocalService service, DesiredCapabilities desiredCapabilities, TimeSpan commandTimeout)
: base(service, SetPlatformToCapabilities(desiredCapabilities, Platform), commandTimeout)
{
}

#region IFindByWindowsUIAutomation Members

/// <summary>
/// Finds the first of elements that match the Windows UIAutomation selector supplied
/// </summary>
/// <param name="selector">a Windows UIAutomation selector</param>
/// <returns>IWebElement object so that you can interact that object</returns>
public W FindElementByWindowsUIAutomation(string selector)
{
return (W)this.FindElement("-windows uiautomation", selector);
}

/// <summary>
/// Finds a list of elements that match the Windows UIAutomation selector supplied
/// </summary>
/// <param name="selector">a Windows UIAutomation selector</param>
/// <returns>ReadOnlyCollection of IWebElement objects so that you can interact with those objects</returns>
public ReadOnlyCollection<W> FindElementsByWindowsUIAutomation(string selector)
{
return CollectionConverterUnility.ConvertToExtendedWebElementCollection<W>(
this.FindElements("-windows uiautomation", selector));
}

#endregion IFindByWindowsUIAutomation Members

/// <summary>
/// Hides the keyboard
/// </summary>
/// <param name="key"></param>
/// <param name="strategy"></param>
public new void HideKeyboard(string key, string strategy = null)
{
base.HideKeyboard(strategy, key);
}

/// <summary>
/// Create a Windows Element
/// </summary>
/// <param name="elementId">element to create</param>
/// <returns>WindowsElement</returns>
protected override RemoteWebElement CreateElement(string elementId)
{
return new WindowsElement(this, elementId);
}

/// <summary>
/// Sends a device key event with metastate
/// </summary>
/// <param name="keyCode">Code for the long key pressed on the Windows device</param>
/// <param name="metastate">metastate for the long key press</param>
public void PressKeyCode(int keyCode, int metastate = -1)
{
var parameters = new Dictionary<string, object>();
parameters.Add("keycode", keyCode);
if (metastate > 0)
{
parameters.Add("metastate", metastate);
}
Execute(AppiumDriverCommand.PressKeyCode, parameters);
}

/// <summary>
/// Sends a device long key event with metastate
/// </summary>
/// <param name="keyCode">Code for the long key pressed on the Windows device</param>
/// <param name="metastate">metastate for the long key press</param>
public void LongPressKeyCode(int keyCode, int metastate = -1)
{
var parameters = new Dictionary<string, object>();
parameters.Add("keycode", keyCode);
if (metastate > 0)
{
parameters.Add("metastate", metastate);
}
Execute(AppiumDriverCommand.LongPressKeyCode, parameters);
}

/// <summary>
/// Convenience method for swiping across the screen
/// </summary>
/// <param name="startx">starting x coordinate</param>
/// <param name="starty">starting y coordinate</param>
/// <param name="endx">ending x coordinate</param>
/// <param name="endy">ending y coordinate</param>
/// <param name="duration">amount of time in milliseconds for the entire swipe action to take</param>
public override void Swipe(int startx, int starty, int endx, int endy, int duration) =>
DoSwipe(startx, starty, endx, endy, duration);
}
}
41 changes: 41 additions & 0 deletions appium-dotnet-driver/Appium/Windows/WindowsElement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//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.Collections.ObjectModel;
using OpenQA.Selenium.Appium.Interfaces;
using OpenQA.Selenium.Remote;

namespace OpenQA.Selenium.Appium.Windows
{
public class WindowsElement : AppiumWebElement, IFindByWindowsUIAutomation<AppiumWebElement>
{
public WindowsElement(RemoteWebDriver parent, string id)
: base(parent, id)
{
}

#region IFindByWindowsUIAutomation Members

public AppiumWebElement FindElementByWindowsUIAutomation(string selector)
{
return (AppiumWebElement)this.FindElement("-windows uiautomation", selector);
}

public ReadOnlyCollection<AppiumWebElement> FindElementsByWindowsUIAutomation(string selector)
{
return CollectionConverterUnility.ConvertToExtendedWebElementCollection<AppiumWebElement>(
this.FindElements("-windows uiautomation", selector));
}
#endregion IFindByWindowsUIAutomation Members
}
}
4 changes: 4 additions & 0 deletions appium-dotnet-driver/appium-dotnet-driver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<Compile Include="Appium\Enums\MobileBrowserType.cs" />
<Compile Include="Appium\Enums\MobileCapabilityType.cs" />
<Compile Include="Appium\Android\Enums\ConnectionType.cs" />
<Compile Include="Appium\Windows\Enums\WindowsKeyCodes.cs" />
<Compile Include="Appium\Interfaces\Generic\SearchContext\IGenericFindsByClassName.cs" />
<Compile Include="Appium\Interfaces\Generic\SearchContext\IGenericFindsByCssSelector.cs" />
<Compile Include="Appium\Interfaces\Generic\SearchContext\IGenericFindsById.cs" />
Expand All @@ -77,6 +78,7 @@
<Compile Include="Appium\Interfaces\Generic\SearchContext\IGenericFindsByXPath.cs" />
<Compile Include="Appium\Interfaces\Generic\SearchContext\IGenericSearchContext.cs" />
<Compile Include="Appium\Interfaces\IContextAware.cs" />
<Compile Include="Appium\Interfaces\IFindByWindowsUIAutomation.cs" />
<Compile Include="Appium\Interfaces\IHidesKeyboard.cs" />
<Compile Include="Appium\Interfaces\IInteractsWithApps.cs" />
<Compile Include="Appium\Interfaces\IInteractsWithFiles.cs" />
Expand Down Expand Up @@ -119,6 +121,8 @@
<Compile Include="Appium\Service\Options\IOSOptionList.cs" />
<Compile Include="Appium\Service\Options\GeneralOptionList.cs" />
<Compile Include="Appium\Service\Options\OptionCollector.cs" />
<Compile Include="Appium\Windows\WindowsDriver.cs" />
<Compile Include="Appium\Windows\WindowsElement.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Appium\AppiumDriver.cs" />
<Compile Include="Appium\AppiumDriverCommand.cs" />
Expand Down
Loading