diff --git a/appium-dotnet-driver/Appium/Android/AndroidDriver.cs b/appium-dotnet-driver/Appium/Android/AndroidDriver.cs index f5589b944..9003074e6 100644 --- a/appium-dotnet-driver/Appium/Android/AndroidDriver.cs +++ b/appium-dotnet-driver/Appium/Android/AndroidDriver.cs @@ -6,16 +6,17 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics.Contracts; -using System.Linq; -using System.Text; namespace OpenQA.Selenium.Appium.Android { - public class AndroidDriver : AppiumDriver, IFindByAndroidUIAutomator, IStartsActivity, IHasNetworkConnection, - IAndroidDeviceActionShortcuts, IPushesFiles + public class AndroidDriver : AppiumDriver, IFindByAndroidUIAutomator, IStartsActivity, + IHasNetworkConnection, + IAndroidDeviceActionShortcuts, + IPushesFiles where W : IWebElement { private static readonly string Platform = MobilePlatform.Android; + /// /// Initializes a new instance of the AndroidDriver class /// @@ -57,37 +58,18 @@ public AndroidDriver(Uri remoteAddress, DesiredCapabilities desiredCapabilities, } #region IFindByAndroidUIAutomator Members - /// - /// Finds the first element in the page that matches the Android UIAutomator selector supplied - /// - /// Selector for the element. - /// IWebElement object so that you can interact that object - /// - /// - /// IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox()); - /// IWebElement elem = driver.FindElementByAndroidUIAutomator('elements()')) - /// - /// - public IWebElement FindElementByAndroidUIAutomator(string selector) + + public W FindElementByAndroidUIAutomator(string selector) { - return this.FindElement("-android uiautomator", selector); + return (W) this.FindElement("-android uiautomator", selector); } - /// - /// Finds a list of elements that match the Android UIAutomator selector supplied - /// - /// Selector for the elements. - /// ReadOnlyCollection of IWebElement object so that you can interact with those objects - /// - /// - /// IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox()); - /// ReadOnlyCollection]]> elem = driver.FindElementsByAndroidUIAutomator(elements()) - /// - /// - public ReadOnlyCollection FindElementsByAndroidUIAutomator(string selector) + public ReadOnlyCollection FindElementsByAndroidUIAutomator(string selector) { - return this.FindElements("-android uiautomator", selector); + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection(this.FindElements("-android uiautomator", selector)); } + #endregion IFindByAndroidUIAutomator Members /// diff --git a/appium-dotnet-driver/Appium/Android/AndroidElement.cs b/appium-dotnet-driver/Appium/Android/AndroidElement.cs index 28ec9531d..8625e1321 100644 --- a/appium-dotnet-driver/Appium/Android/AndroidElement.cs +++ b/appium-dotnet-driver/Appium/Android/AndroidElement.cs @@ -1,4 +1,5 @@ using OpenQA.Selenium.Appium.Interfaces; +using OpenQA.Selenium.Remote; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -7,37 +8,29 @@ namespace OpenQA.Selenium.Appium.Android { - public class AndroidElement : AppiumWebElement, IFindByAndroidUIAutomator + public class AndroidElement : AppiumWebElement, IFindByAndroidUIAutomator { /// /// Initializes a new instance of the AndroidElement class. /// /// Driver in use. /// ID of the element. - public AndroidElement(AppiumDriver parent, string id) + public AndroidElement(RemoteWebDriver parent, string id) : base(parent, id) { } #region IFindByAndroidUIAutomator Members - /// - /// Finds the first of elements that match the Android UIAutomator selector supplied - /// - /// an Android UIAutomator selector - /// IWebElement object so that you can interact that object - public IWebElement FindElementByAndroidUIAutomator(string selector) + + public AppiumWebElement FindElementByAndroidUIAutomator(string selector) { - return this.FindElement("-android uiautomator", selector); + return (AppiumWebElement) this.FindElement("-android uiautomator", selector); } - /// - /// Finds a list of elements that match the Android UIAutomator selector supplied - /// - /// an Android UIAutomator selector - /// IWebElement object so that you can interact that object - public ReadOnlyCollection FindElementsByAndroidUIAutomator(string selector) + public ReadOnlyCollection FindElementsByAndroidUIAutomator(string selector) { - return this.FindElements("-android uiautomator", selector); + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection(this.FindElements("-android uiautomator", selector)); } #endregion IFindByAndroidUIAutomator Members } diff --git a/appium-dotnet-driver/Appium/AppiumDriver.cs b/appium-dotnet-driver/Appium/AppiumDriver.cs index 116390dd6..e52bc0195 100644 --- a/appium-dotnet-driver/Appium/AppiumDriver.cs +++ b/appium-dotnet-driver/Appium/AppiumDriver.cs @@ -28,6 +28,7 @@ using System.Reflection; using System.Diagnostics.Contracts; using Newtonsoft.Json; +using Appium.Interfaces.Generic.SearchContext; namespace OpenQA.Selenium.Appium { @@ -69,8 +70,10 @@ namespace OpenQA.Selenium.Appium /// } /// /// - public abstract class AppiumDriver : RemoteWebDriver, IFindByAccessibilityId, IDeviceActionShortcuts, IInteractsWithFiles, - IInteractsWithApps, IPerformsTouchActions, IRotatable, IContextAware + public abstract class AppiumDriver : RemoteWebDriver, IFindByAccessibilityId, IDeviceActionShortcuts, IInteractsWithFiles, + IInteractsWithApps, IPerformsTouchActions, IRotatable, IContextAware, IGenericSearchContext, IGenericFindsByClassName, + IGenericFindsById, IGenericFindsByCssSelector, IGenericFindsByLinkText, IGenericFindsByName, + IGenericFindsByPartialLinkText, IGenericFindsByTagName, IGenericFindsByXPath where W : IWebElement { #region Constructors /// @@ -117,45 +120,128 @@ public AppiumDriver(Uri remoteAddress, ICapabilities desiredCapabilities, TimeSp } #endregion Constructors - #region Public Methods + #region Generic FindMethods + public W FindElement(By by) + { + return (W)base.FindElement(by); + } + + public ReadOnlyCollection FindElements(By by) + { + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection(base.FindElements(by)); + } + + public W FindElementByClassName(string className) + { + return (W)base.FindElementByClassName(className); + } + + public ReadOnlyCollection FindElementsByClassName(string className) + { + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection(base.FindElementsByClassName(className)); + } + + public W FindElementById(string id) + { + return (W) base.FindElementById(id); + } + + + public ReadOnlyCollection FindElementsById(string id) + { + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection(base.FindElementsById(id)); + } + + public W FindElementByCssSelector(string cssSelector) + { + return (W)base.FindElementByCssSelector(cssSelector); + } + + + public ReadOnlyCollection FindElementsByCssSelector(string cssSelector) + { + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection(base.FindElementsByCssSelector(cssSelector)); + } + + public W FindElementByLinkText(string linkText) + { + return (W) base.FindElementByLinkText(linkText); + } + + public ReadOnlyCollection FindElementsByLinkText(string linkText) + { + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection(base.FindElementsByLinkText(linkText)); + } + + public W FindElementByName(string name) + { + return (W)base.FindElementByName(name); + } - #region FindMethods + public ReadOnlyCollection FindElementsByName(string name) + { + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection(base.FindElementsByName(name)); + } + + public W FindElementByPartialLinkText(string partialLinkText) + { + return (W) base.FindElementByPartialLinkText(partialLinkText); + } + + public ReadOnlyCollection FindElementsByPartialLinkText(string partialLinkText) + { + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection(base.FindElementsByPartialLinkText(partialLinkText)); + } + + public W FindElementByTagName(string tagName) + { + return (W) base.FindElementByTagName(tagName); + } + + public ReadOnlyCollection FindElementsByTagName(string tagName) + { + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection(base.FindElementsByTagName(tagName)); + } + + public W FindElementByXPath(string xpath) + { + return (W) base.FindElementByXPath(xpath); + } + + public ReadOnlyCollection FindElementsByXPath(string xpath) + { + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection(base.FindElementsByXPath(xpath)); + } #region IFindByAccessibilityId Members - /// - /// Finds the first element in the page that matches the Accessibility Id selector supplied - /// - /// Selector for the element. - /// IWebElement object so that you can interact that object - /// - /// - /// IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox()); - /// IWebElement elem = driver.FindElementByAccessibilityId('elements()')) - /// - /// - public IWebElement FindElementByAccessibilityId(string selector) + + public W FindElementByAccessibilityId(string selector) { - return this.FindElement("accessibility id", selector); + return (W) this.FindElement("accessibility id", selector); } - /// - /// Finds a list of elements that match the Accessibility Id selector supplied - /// - /// Selector for the elements. - /// ReadOnlyCollection of IWebElement object so that you can interact with those objects - /// - /// - /// IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox()); - /// ReadOnlyCollection]]> elem = driver.FindElementsByAccessibilityId(elements()) - /// - /// - public ReadOnlyCollection FindElementsByAccessibilityId(string selector) - { - return this.FindElements("accessibility id", selector); + public ReadOnlyCollection FindElementsByAccessibilityId(string selector) + { + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection(base.FindElements("accessibility id", selector)); } + #endregion IFindByAccessibilityId Members + #endregion + #region Public Methods + + #region MJsonMethod Members /// /// Locks the device. @@ -320,6 +406,7 @@ protected void HideKeyboard(string strategy = null, string key = null) /// /// Hides the device keyboard. /// + /// The button pressed by the mobile driver to attempt hiding the keyboard. public void HideKeyboard() { this.HideKeyboard(null, null); diff --git a/appium-dotnet-driver/Appium/AppiumWebElement.cs b/appium-dotnet-driver/Appium/AppiumWebElement.cs index 23278b9f7..c06a35412 100644 --- a/appium-dotnet-driver/Appium/AppiumWebElement.cs +++ b/appium-dotnet-driver/Appium/AppiumWebElement.cs @@ -19,8 +19,8 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using OpenQA.Selenium.Appium.Interfaces; -using OpenQA.Selenium.Appium.Interfaces; using OpenQA.Selenium.Remote; +using Appium.Interfaces.Generic.SearchContext; namespace OpenQA.Selenium.Appium { @@ -40,14 +40,18 @@ namespace OpenQA.Selenium.Appium /// } /// /// - public abstract class AppiumWebElement : RemoteWebElement, IFindByAccessibilityId + public abstract class AppiumWebElement : RemoteWebElement, IFindByAccessibilityId, IGenericSearchContext, + IGenericFindsByClassName, + IGenericFindsById, IGenericFindsByCssSelector, IGenericFindsByLinkText, + IGenericFindsByName, + IGenericFindsByPartialLinkText, IGenericFindsByTagName, IGenericFindsByXPath { /// /// Initializes a new instance of the AppiumWebElement class. /// /// Driver in use. /// ID of the element. - public AppiumWebElement(AppiumDriver parent, string id) + public AppiumWebElement(RemoteWebDriver parent, string id) : base(parent, id) { } @@ -89,27 +93,123 @@ public void SetImmediateValue(string value) #region FindMethods #region IFindByAccessibilityId Members - /// - /// Finds the first of elements that match the Accessibility Id selector supplied - /// - /// an Accessibility Id selector - /// IWebElement object so that you can interact that object - public IWebElement FindElementByAccessibilityId(string selector) + + public AppiumWebElement FindElementByAccessibilityId(string selector) { - return this.FindElement("accessibility id", selector); + return (AppiumWebElement) this.FindElement("accessibility id", selector); } - /// - /// Finds a list of elements that match the Accessibility Id selector supplied - /// - /// an Accessibility Id selector - /// IWebElement object so that you can interact that object - public ReadOnlyCollection FindElementsByAccessibilityId(string selector) + public ReadOnlyCollection FindElementsByAccessibilityId(string selector) { - return this.FindElements("accessibility id", selector); + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection(this.FindElements("accessibility id", selector)); } + #endregion IFindByAccessibilityId Members + public AppiumWebElement FindElement(By by) + { + return (AppiumWebElement) base.FindElement(by); + } + + public ReadOnlyCollection FindElements(By by) + { + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection(base.FindElements(by)); + } + + public AppiumWebElement FindElementByClassName(string className) + { + return (AppiumWebElement) base.FindElementByClassName(className); + } + + public ReadOnlyCollection FindElementsByClassName(string className) + { + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection(base.FindElementsByClassName(className)); + } + + public AppiumWebElement FindElementById(string id) + { + return (AppiumWebElement) base.FindElementById(id); + } + + + public ReadOnlyCollection FindElementsById(string id) + { + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection(base.FindElementsById(id)); + } + + public AppiumWebElement FindElementByCssSelector(string cssSelector) + { + return (AppiumWebElement) base.FindElementByCssSelector(cssSelector); + } + + + public ReadOnlyCollection FindElementsByCssSelector(string cssSelector) + { + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection(base.FindElementsByCssSelector(cssSelector)); + } + + public AppiumWebElement FindElementByLinkText(string linkText) + { + return (AppiumWebElement) base.FindElementByLinkText(linkText); + } + + public ReadOnlyCollection FindElementsByLinkText(string linkText) + { + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection(base.FindElementsByLinkText(linkText)); + } + + public AppiumWebElement FindElementByName(string name) + { + return (AppiumWebElement) base.FindElementByName(name); + } + + public ReadOnlyCollection FindElementsByName(string name) + { + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection(base.FindElementsByName(name)); + } + + public AppiumWebElement FindElementByPartialLinkText(string partialLinkText) + { + return (AppiumWebElement) base.FindElementByPartialLinkText(partialLinkText); + } + + public ReadOnlyCollection FindElementsByPartialLinkText(string partialLinkText) + { + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection(base.FindElementsByPartialLinkText(partialLinkText)); + } + + public AppiumWebElement FindElementByTagName(string tagName) + { + return (AppiumWebElement) base.FindElementByTagName(tagName); + } + + public ReadOnlyCollection FindElementsByTagName(string tagName) + { + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection(base.FindElementsByTagName(tagName)); + } + + public AppiumWebElement FindElementByXPath(string xpath) + { + return (AppiumWebElement)base.FindElementByXPath(xpath); + } + + public ReadOnlyCollection FindElementsByXPath(string xpath) + { + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection(base.FindElementsByXPath(xpath)); + } + + + #endregion } } diff --git a/appium-dotnet-driver/Appium/ByAccessibilityId.cs b/appium-dotnet-driver/Appium/ByAccessibilityId.cs index 3e1ac8e24..f0543a244 100644 --- a/appium-dotnet-driver/Appium/ByAccessibilityId.cs +++ b/appium-dotnet-driver/Appium/ByAccessibilityId.cs @@ -20,6 +20,8 @@ using System.Collections.ObjectModel; using System.Globalization; using OpenQA.Selenium.Appium.Interfaces; +using System.Reflection; +using System.Collections; namespace OpenQA.Selenium.Appium { @@ -29,6 +31,7 @@ namespace OpenQA.Selenium.Appium public class ByAccessibilityId : By { private string selector = string.Empty; + private readonly string InterfaceNameRegExp = "IFindByAccessibilityId`1"; /// /// Initializes a new instance of the class. @@ -51,12 +54,14 @@ public ByAccessibilityId(string selector) /// The element that matches public override IWebElement FindElement(ISearchContext context) { - var tmpContext = context as IFindByAccessibilityId; - if (null == tmpContext) + Type contextType = context.GetType(); + Type findByAccessibilityId = contextType.GetInterface(InterfaceNameRegExp, false); + if (null == findByAccessibilityId) { - throw new InvalidCastException("Unable to cast ISearchContext to IFindByAccessibilityId"); + throw new InvalidCastException("Unable to cast " + contextType.ToString() + " to IFindByAccessibilityId"); } - return tmpContext.FindElementByAccessibilityId(selector); + MethodInfo m = findByAccessibilityId.GetMethod("FindElementByAccessibilityId", new Type[] { typeof(string) }); + return (IWebElement) m.Invoke(context, new object[] { selector }); } /// @@ -66,12 +71,15 @@ public override IWebElement FindElement(ISearchContext context) /// A readonly collection of elements that match. public override ReadOnlyCollection FindElements(ISearchContext context) { - var tmpContext = context as IFindByAccessibilityId; - if (null == tmpContext) + Type contextType = context.GetType(); + Type findByAccessibilityId = contextType.GetInterface(InterfaceNameRegExp, false); + if (null == findByAccessibilityId) { - throw new InvalidCastException("Unable to cast ISearchContext to IFindByAccessibilityId"); + throw new InvalidCastException("Unable to cast " + contextType.ToString() + " to IFindByAccessibilityId"); } - return tmpContext.FindElementsByAccessibilityId(selector); + MethodInfo m = findByAccessibilityId.GetMethod("FindElementsByAccessibilityId", new Type[] { typeof(string) }); + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection((IList) m.Invoke(context, new object[] { selector })); } /// diff --git a/appium-dotnet-driver/Appium/ByAndroidUIAutomator.cs b/appium-dotnet-driver/Appium/ByAndroidUIAutomator.cs index 8017af4c4..c48f4ecad 100644 --- a/appium-dotnet-driver/Appium/ByAndroidUIAutomator.cs +++ b/appium-dotnet-driver/Appium/ByAndroidUIAutomator.cs @@ -20,6 +20,8 @@ using System.Collections.ObjectModel; using System.Globalization; using OpenQA.Selenium.Appium.Interfaces; +using System.Reflection; +using System.Collections; namespace OpenQA.Selenium.Appium { @@ -29,7 +31,7 @@ namespace OpenQA.Selenium.Appium public class ByAndroidUIAutomator : By { private string _Selector = string.Empty; - private const string _UnableToCastError = "Unable to cast ISearchContext to IFindByAndroidUIAutomator"; + private readonly string InterfaceNameRegExp = "IFindByAndroidUIAutomator`1"; /// /// Initializes a new instance of the class. @@ -52,12 +54,14 @@ public ByAndroidUIAutomator(string selector) /// The element that matches public override IWebElement FindElement(ISearchContext context) { - var tmpContext = context as IFindByAndroidUIAutomator; - if (null == tmpContext) + Type contextType = context.GetType(); + Type findByAccessibilityId = contextType.GetInterface(InterfaceNameRegExp, false); + if (null == findByAccessibilityId) { - throw new InvalidCastException(_UnableToCastError); + throw new InvalidCastException("Unable to cast " + contextType.ToString() + " to IFindByAndroidUIAutomator"); } - return tmpContext.FindElementByAndroidUIAutomator(_Selector); + MethodInfo m = findByAccessibilityId.GetMethod("FindElementByAndroidUIAutomator", new Type[] { typeof(string) }); + return (IWebElement) m.Invoke(context, new object[] { _Selector}); } /// @@ -67,12 +71,15 @@ public override IWebElement FindElement(ISearchContext context) /// A readonly collection of elements that match. public override ReadOnlyCollection FindElements(ISearchContext context) { - var tmpContext = context as IFindByAndroidUIAutomator; - if (null == tmpContext) + Type contextType = context.GetType(); + Type findByAccessibilityId = contextType.GetInterface(InterfaceNameRegExp, false); + if (null == findByAccessibilityId) { - throw new InvalidCastException(_UnableToCastError); + throw new InvalidCastException("Unable to cast " + contextType.ToString() + " to IFindByAndroidUIAutomator"); } - return tmpContext.FindElementsByAndroidUIAutomator(_Selector); + MethodInfo m = findByAccessibilityId.GetMethod("FindElementsByAndroidUIAutomator", new Type[] { typeof(string) }); + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection((IList) m.Invoke(context, new object[] { _Selector })); } /// diff --git a/appium-dotnet-driver/Appium/ByIosUIAutomation.cs b/appium-dotnet-driver/Appium/ByIosUIAutomation.cs index d30de91ae..a391bcb68 100644 --- a/appium-dotnet-driver/Appium/ByIosUIAutomation.cs +++ b/appium-dotnet-driver/Appium/ByIosUIAutomation.cs @@ -20,6 +20,8 @@ using System.Collections.ObjectModel; using System.Globalization; using OpenQA.Selenium.Appium.Interfaces; +using System.Reflection; +using System.Collections; namespace OpenQA.Selenium.Appium { @@ -29,7 +31,7 @@ namespace OpenQA.Selenium.Appium public class ByIosUIAutomation : By { private string _Selector = string.Empty; - private const string _UnableToCast = "Unable to cast ISearchContext to IFindByIosUIAutomation"; + private readonly string InterfaceNameRegExp = "IFindByIosUIAutomation`1"; /// /// Initializes a new instance of the class. @@ -52,12 +54,14 @@ public ByIosUIAutomation(string selector) /// The element that matches public override IWebElement FindElement(ISearchContext context) { - var tmpContext = context as IFindByIosUIAutomation; - if (null == tmpContext) + Type contextType = context.GetType(); + Type findByAccessibilityId = contextType.GetInterface(InterfaceNameRegExp, false); + if (null == findByAccessibilityId) { - throw new InvalidCastException(_UnableToCast); + throw new InvalidCastException("Unable to cast " + contextType.ToString() + " to IFindByIosUIAutomation"); } - return tmpContext.FindElementByIosUIAutomation(_Selector); + MethodInfo m = findByAccessibilityId.GetMethod("FindElementByIosUIAutomation", new Type[] { typeof(string) }); + return (IWebElement)m.Invoke(context, new object[] { _Selector }); } /// @@ -67,12 +71,15 @@ public override IWebElement FindElement(ISearchContext context) /// A readonly collection of elements that match. public override ReadOnlyCollection FindElements(ISearchContext context) { - var tmpContext = context as IFindByIosUIAutomation; - if (null == tmpContext) + Type contextType = context.GetType(); + Type findByAccessibilityId = contextType.GetInterface(InterfaceNameRegExp, false); + if (null == findByAccessibilityId) { - throw new InvalidCastException(_UnableToCast); + throw new InvalidCastException("Unable to cast " + contextType.ToString() + " to IFindByIosUIAutomation"); } - return tmpContext.FindElementsByIosUIAutomation(_Selector); + MethodInfo m = findByAccessibilityId.GetMethod("FindElementsByIosUIAutomation", new Type[] { typeof(string) }); + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection((IList) m.Invoke(context, new object[] { _Selector })); } /// diff --git a/appium-dotnet-driver/Appium/CollectionConverterUnility.cs b/appium-dotnet-driver/Appium/CollectionConverterUnility.cs new file mode 100644 index 000000000..d85085e21 --- /dev/null +++ b/appium-dotnet-driver/Appium/CollectionConverterUnility.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; + +namespace OpenQA.Selenium.Appium +{ + internal class CollectionConverterUnility + { + public static ReadOnlyCollection ConvertToExtendedWebElementCollection(IList list) where T : IWebElement + { + List result = new List(); + foreach (var element in list) + { + result.Add((T) element); + } + return result.AsReadOnly(); + } + } +} diff --git a/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericFindsByClassName.cs b/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericFindsByClassName.cs new file mode 100644 index 000000000..4006dbf6a --- /dev/null +++ b/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericFindsByClassName.cs @@ -0,0 +1,45 @@ +// +// Copyright 2015 Software Freedom Conservancy +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// 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 OpenQA.Selenium; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; + +namespace Appium.Interfaces.Generic.SearchContext +{ + /// + /// Defines the interface through which the user finds elements by their CSS class. + /// + public interface IGenericFindsByClassName where W : IWebElement + { + /// + /// Finds the first element matching the specified CSS class. + /// + /// The CSS class to match. + /// The first matching the criteria. + W FindElementByClassName(string className); + + /// + /// Finds all elements matching the specified CSS class. + /// + /// The CSS class to match. + /// A containing all + /// IWebElements matching the criteria. + ReadOnlyCollection FindElementsByClassName(string className); + } +} diff --git a/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericFindsByCssSelector.cs b/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericFindsByCssSelector.cs new file mode 100644 index 000000000..2b12220c0 --- /dev/null +++ b/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericFindsByCssSelector.cs @@ -0,0 +1,45 @@ +// +// Copyright 2015 Software Freedom Conservancy +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// 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 System.Text; +using OpenQA.Selenium; + +namespace Appium.Interfaces.Generic.SearchContext +{ + /// + /// Defines the interface through which the user finds elements by their cascading style sheet (CSS) selector. + /// + public interface IGenericFindsByCssSelector where W : IWebElement + { + /// + /// Finds the first element matching the specified CSS selector. + /// + /// The id to match. + /// The first matching the criteria. + W FindElementByCssSelector(string cssSelector); + + /// + /// Finds all elements matching the specified CSS selector. + /// + /// The CSS selector to match. + /// A containing all + /// IWebElements matching the criteria. + ReadOnlyCollection FindElementsByCssSelector(string cssSelector); + } +} diff --git a/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericFindsById.cs b/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericFindsById.cs new file mode 100644 index 000000000..431b62eac --- /dev/null +++ b/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericFindsById.cs @@ -0,0 +1,45 @@ +// +// Copyright 2015 Software Freedom Conservancy +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// 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 OpenQA.Selenium; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; + +namespace Appium.Interfaces.Generic.SearchContext +{ + /// + /// Defines the interface through which the user finds elements by their ID. + /// + public interface IGenericFindsById where W : IWebElement + { + /// + /// Finds the first element matching the specified id. + /// + /// The id to match. + /// The first matching the criteria. + W FindElementById(string id); + + /// + /// Finds all elements matching the specified id. + /// + /// The id to match. + /// A containing all + /// IWebElements matching the criteria. + ReadOnlyCollection FindElementsById(string id); + } +} diff --git a/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericFindsByLinkText.cs b/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericFindsByLinkText.cs new file mode 100644 index 000000000..649b3403b --- /dev/null +++ b/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericFindsByLinkText.cs @@ -0,0 +1,45 @@ +// +// Copyright 2015 Software Freedom Conservancy +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// 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 OpenQA.Selenium; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; + +namespace Appium.Interfaces.Generic.SearchContext +{ + /// + /// Defines the interface through which the user finds elements by their link text. + /// + public interface IGenericFindsByLinkText where W : IWebElement + { + /// + /// Finds the first element matching the specified link text. + /// + /// The link text to match. + /// The first matching the criteria. + W FindElementByLinkText(string linkText); + + /// + /// Finds all elements matching the specified link text. + /// + /// The link text to match. + /// A containing all + /// IWebElements matching the criteria. + ReadOnlyCollection FindElementsByLinkText(string linkText); + } +} diff --git a/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericFindsByName.cs b/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericFindsByName.cs new file mode 100644 index 000000000..f246ae16b --- /dev/null +++ b/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericFindsByName.cs @@ -0,0 +1,45 @@ +// +// Copyright 2015 Software Freedom Conservancy +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// 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 OpenQA.Selenium; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; + +namespace Appium.Interfaces.Generic.SearchContext +{ + /// + /// Defines the interface through which the user finds elements by their name. + /// + public interface IGenericFindsByName where W : IWebElement + { + /// + /// Finds the first element matching the specified name. + /// + /// The name to match. + /// The first matching the criteria. + W FindElementByName(string name); + + /// + /// Finds all elements matching the specified name. + /// + /// The name to match. + /// A containing all + /// IWebElements matching the criteria. + ReadOnlyCollection FindElementsByName(string name); + } +} diff --git a/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericFindsByPartialLinkText.cs b/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericFindsByPartialLinkText.cs new file mode 100644 index 000000000..2c4fd5097 --- /dev/null +++ b/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericFindsByPartialLinkText.cs @@ -0,0 +1,45 @@ +// +// Copyright 2015 Software Freedom Conservancy +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// 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 OpenQA.Selenium; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; + +namespace Appium.Interfaces.Generic.SearchContext +{ + /// + /// Defines the interface through which the user finds elements by a partial match on their link text. + /// + public interface IGenericFindsByPartialLinkText where W : IWebElement + { + /// + /// Finds the first element matching the specified partial link text. + /// + /// The partial link text to match. + /// The first matching the criteria. + W FindElementByPartialLinkText(string partialLinkText); + + /// + /// Finds all elements matching the specified partial link text. + /// + /// The partial link text to match. + /// A containing all + /// IWebElements matching the criteria. + ReadOnlyCollection FindElementsByPartialLinkText(string partialLinkText); + } +} diff --git a/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericFindsByTagName.cs b/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericFindsByTagName.cs new file mode 100644 index 000000000..c5e607a56 --- /dev/null +++ b/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericFindsByTagName.cs @@ -0,0 +1,45 @@ +// +// Copyright 2015 Software Freedom Conservancy +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// 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 OpenQA.Selenium; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; + +namespace Appium.Interfaces.Generic.SearchContext +{ + /// + /// Defines the interface through which the user finds elements by their tag name. + /// + public interface IGenericFindsByTagName where W : IWebElement + { + /// + /// Finds the first element matching the specified tag name. + /// + /// The tag name to match. + /// The first matching the criteria. + W FindElementByTagName(string tagName); + + /// + /// Finds all elements matching the specified tag name. + /// + /// The tag name to match. + /// A containing all + /// IWebElements matching the criteria. + ReadOnlyCollection FindElementsByTagName(string tagName); + } +} diff --git a/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericFindsByXPath.cs b/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericFindsByXPath.cs new file mode 100644 index 000000000..5fd725b0a --- /dev/null +++ b/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericFindsByXPath.cs @@ -0,0 +1,45 @@ +// +// Copyright 2015 Software Freedom Conservancy +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// 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 OpenQA.Selenium; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; + +namespace Appium.Interfaces.Generic.SearchContext +{ + /// + /// Defines the interface through which the user finds elements by XPath. + /// + public interface IGenericFindsByXPath where W : IWebElement + { + /// + /// Finds the first element matching the specified XPath query. + /// + /// The XPath query to match. + /// The first matching the criteria. + W FindElementByXPath(string xpath); + + /// + /// Finds all elements matching the specified XPath query. + /// + /// The XPath query to match. + /// A containing all + /// IWebElements matching the criteria. + ReadOnlyCollection FindElementsByXPath(string xpath); + } +} diff --git a/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericSearchContext.cs b/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericSearchContext.cs new file mode 100644 index 000000000..afe03e40d --- /dev/null +++ b/appium-dotnet-driver/Appium/Interfaces/Generic/SearchContext/IGenericSearchContext.cs @@ -0,0 +1,47 @@ +// +// Copyright 2015 Software Freedom Conservancy +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// 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 OpenQA.Selenium; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; + +namespace Appium.Interfaces.Generic.SearchContext +{ + /// + /// Defines the interface used to search for elements. + /// + public interface IGenericSearchContext where W : IWebElement + { + /// + /// Finds the first using the given method. + /// + /// The locating mechanism to use. + /// The first matching on the current context. + /// If no element matches the criteria. + W FindElement(By by); + + /// + /// Finds all IWebElements within the current context + /// using the given mechanism. + /// + /// The locating mechanism to use. + /// A of all WebElements + /// matching the current criteria, or an empty list if nothing matches. + ReadOnlyCollection FindElements(By by); + } +} diff --git a/appium-dotnet-driver/Appium/Interfaces/IContextAware.cs b/appium-dotnet-driver/Appium/Interfaces/IContextAware.cs index 90263ead2..dc2e08b57 100644 --- a/appium-dotnet-driver/Appium/Interfaces/IContextAware.cs +++ b/appium-dotnet-driver/Appium/Interfaces/IContextAware.cs @@ -4,11 +4,7 @@ using System.Linq; using System.Text; -/// -/// This interface is temporary. Let it be here till -///https://github.com/SeleniumHQ/selenium/pull/301 -///is merged and new Webdriver for .Net is published. -/// + namespace OpenQA.Selenium.Appium.Interfaces { /// diff --git a/appium-dotnet-driver/Appium/Interfaces/IFindByAccessibilityId.cs b/appium-dotnet-driver/Appium/Interfaces/IFindByAccessibilityId.cs index 1a9ebfe42..dfa78bd7c 100644 --- a/appium-dotnet-driver/Appium/Interfaces/IFindByAccessibilityId.cs +++ b/appium-dotnet-driver/Appium/Interfaces/IFindByAccessibilityId.cs @@ -2,20 +2,20 @@ namespace OpenQA.Selenium.Appium.Interfaces { - public interface IFindByAccessibilityId + public interface IFindByAccessibilityId where W : IWebElement { /// /// Finds the first of elements that match the Accessibility Id selector supplied /// /// an Accessibility Id selector /// IWebElement object so that you can interact that object - IWebElement FindElementByAccessibilityId(string selector); + W FindElementByAccessibilityId(string selector); /// /// Finds a list of elements that match the Accessibility Id selector supplied /// /// an Accessibility Id selector /// IWebElement object so that you can interact that object - ReadOnlyCollection FindElementsByAccessibilityId(string selector); + ReadOnlyCollection FindElementsByAccessibilityId(string selector); } } diff --git a/appium-dotnet-driver/Appium/Interfaces/IFindByAndroidUIAutomator.cs b/appium-dotnet-driver/Appium/Interfaces/IFindByAndroidUIAutomator.cs index e556ab3ff..e47dcab97 100644 --- a/appium-dotnet-driver/Appium/Interfaces/IFindByAndroidUIAutomator.cs +++ b/appium-dotnet-driver/Appium/Interfaces/IFindByAndroidUIAutomator.cs @@ -2,7 +2,7 @@ namespace OpenQA.Selenium.Appium.Interfaces { - public interface IFindByAndroidUIAutomator + public interface IFindByAndroidUIAutomator where W : IWebElement { /// /// Finds the first element in the page that matches the Android UIAutomator selector supplied @@ -15,7 +15,7 @@ public interface IFindByAndroidUIAutomator /// IWebElement elem = driver.FindElementByAndroidUIAutomator('elements()')) /// /// - IWebElement FindElementByAndroidUIAutomator(string selector); + W FindElementByAndroidUIAutomator(string selector); /// /// Finds a list of elements that match the Android UIAutomator selector supplied @@ -28,6 +28,6 @@ public interface IFindByAndroidUIAutomator /// ReadOnlyCollection]]> elem = driver.FindElementsByAndroidUIAutomator(elements()) /// /// - ReadOnlyCollection FindElementsByAndroidUIAutomator(string selector); + ReadOnlyCollection FindElementsByAndroidUIAutomator(string selector); } } diff --git a/appium-dotnet-driver/Appium/Interfaces/IFindByIosUIAutomation.cs b/appium-dotnet-driver/Appium/Interfaces/IFindByIosUIAutomation.cs index bce071437..2075d69a3 100644 --- a/appium-dotnet-driver/Appium/Interfaces/IFindByIosUIAutomation.cs +++ b/appium-dotnet-driver/Appium/Interfaces/IFindByIosUIAutomation.cs @@ -2,20 +2,20 @@ namespace OpenQA.Selenium.Appium.Interfaces { - public interface IFindByIosUIAutomation + public interface IFindByIosUIAutomation where W : IWebElement { /// /// Finds the first of elements that match the Ios UIAutomation selector supplied /// /// an Ios UIAutomation selector /// IWebElement object so that you can interact that object - IWebElement FindElementByIosUIAutomation(string selector); + W FindElementByIosUIAutomation(string selector); /// /// Finds a list of elements that match the Ios UIAutomation selector supplied /// /// an Ios UIAutomation selector /// IWebElement object so that you can interact that object - ReadOnlyCollection FindElementsByIosUIAutomation(string selector); + ReadOnlyCollection FindElementsByIosUIAutomation(string selector); } } diff --git a/appium-dotnet-driver/Appium/MultiAction/MultiAction.cs b/appium-dotnet-driver/Appium/MultiAction/MultiAction.cs index 6e996ca70..b9cb21523 100644 --- a/appium-dotnet-driver/Appium/MultiAction/MultiAction.cs +++ b/appium-dotnet-driver/Appium/MultiAction/MultiAction.cs @@ -3,6 +3,7 @@ using System.Linq; using OpenQA.Selenium.Appium.Interfaces; using System.Reflection; +using OpenQA.Selenium.Remote; namespace OpenQA.Selenium.Appium.MultiTouch { @@ -10,7 +11,7 @@ public class MultiAction : IMultiAction { private IList actions = new List(); - private AppiumDriver driver; + private IPerformsTouchActions TouchActionPerformer; private IWebElement element; private string getIdForElement(IWebElement el) { @@ -22,9 +23,9 @@ private string getIdForElement(IWebElement el) { /// /// The the driver to be used. /// The the element on which the actions built will be performed. - public MultiAction(AppiumDriver driver, IWebElement element) + public MultiAction(IPerformsTouchActions touchActionPerformer, IWebElement element) + :this(touchActionPerformer) { - this.driver = driver; this.element = element; } @@ -32,9 +33,9 @@ public MultiAction(AppiumDriver driver, IWebElement element) /// Initializes a new instance of the class. /// /// The the driver to be used. - public MultiAction(AppiumDriver driver) + public MultiAction(IPerformsTouchActions touchActionPerformer) { - this.driver = driver; + this.TouchActionPerformer = touchActionPerformer; } /// @@ -53,13 +54,6 @@ public MultiAction() { } - /// - /// Sets the driver. - /// - /// The the driver to be used. - public void setDriver (AppiumDriver driver) { - this.driver = driver; - } /// /// Sets the element. @@ -107,8 +101,6 @@ public Dictionary GetParameters() /// public void Cancel() { - this.driver = null; - this.element = null; actions.Clear (); } @@ -117,7 +109,7 @@ public void Cancel() /// public void Perform() { - this.driver.PerformMultiAction (this); + TouchActionPerformer.PerformMultiAction (this); } } } diff --git a/appium-dotnet-driver/Appium/MultiAction/TouchAction.cs b/appium-dotnet-driver/Appium/MultiAction/TouchAction.cs index 311f8be53..8b1009618 100644 --- a/appium-dotnet-driver/Appium/MultiAction/TouchAction.cs +++ b/appium-dotnet-driver/Appium/MultiAction/TouchAction.cs @@ -2,6 +2,7 @@ using OpenQA.Selenium.Appium.Interfaces; using System.Collections.Generic; using System.Reflection; +using OpenQA.Selenium.Remote; namespace OpenQA.Selenium.Appium.MultiTouch { @@ -47,16 +48,16 @@ public Dictionary GetParameters() { } } - private AppiumDriver driver; + private IPerformsTouchActions TouchActionPerformer; private List steps = new List(); public TouchAction () { } - public TouchAction (AppiumDriver driver) + public TouchAction(IPerformsTouchActions touchActionPerformer) { - this.driver = driver; + this.TouchActionPerformer = touchActionPerformer; } /// @@ -238,7 +239,7 @@ public List> GetParameters() { /// public void Cancel() { - this.driver = null; + this.TouchActionPerformer = null; steps.Clear (); } @@ -247,7 +248,7 @@ public void Cancel() /// public void Perform() { - this.driver.PerformTouchAction (this); + this.TouchActionPerformer.PerformTouchAction(this); } } diff --git a/appium-dotnet-driver/Appium/iOS/IOSDriver.cs b/appium-dotnet-driver/Appium/iOS/IOSDriver.cs index 8ec259b05..ddbb5ba5a 100644 --- a/appium-dotnet-driver/Appium/iOS/IOSDriver.cs +++ b/appium-dotnet-driver/Appium/iOS/IOSDriver.cs @@ -10,7 +10,7 @@ namespace OpenQA.Selenium.Appium.iOS { - public class IOSDriver : AppiumDriver, IFindByIosUIAutomation, IIOSDeviceActionShortcuts + public class IOSDriver : AppiumDriver, IFindByIosUIAutomation, IIOSDeviceActionShortcuts where W : IWebElement { private static readonly string Platform = MobilePlatform.IOS; /// @@ -54,36 +54,15 @@ public IOSDriver(Uri remoteAddress, DesiredCapabilities desiredCapabilities, Tim } #region IFindByIosUIAutomation Members - /// - /// Finds the first element in the page that matches the Ios UIAutomation selector supplied - /// - /// Selector for the element. - /// IWebElement object so that you can interact that object - /// - /// - /// IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox()); - /// IWebElement elem = driver.FindElementByIosUIAutomation('elements()')) - /// - /// - public IWebElement FindElementByIosUIAutomation(string selector) + public W FindElementByIosUIAutomation(string selector) { - return this.FindElement("-ios uiautomation", selector); + return (W) this.FindElement("-ios uiautomation", selector); } - /// - /// Finds a list of elements that match the Ios UIAutomation selector supplied - /// - /// Selector for the elements. - /// ReadOnlyCollection of IWebElement object so that you can interact with those objects - /// - /// - /// IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox()); - /// ReadOnlyCollection]]> elem = driver.FindElementsByIosUIAutomation(elements()) - /// - /// - public ReadOnlyCollection FindElementsByIosUIAutomation(string selector) + public ReadOnlyCollection FindElementsByIosUIAutomation(string selector) { - return this.FindElements("-ios uiautomation", selector); + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection(this.FindElements("-ios uiautomation", selector)); } #endregion IFindByIosUIAutomation Members diff --git a/appium-dotnet-driver/Appium/iOS/IOSElement.cs b/appium-dotnet-driver/Appium/iOS/IOSElement.cs index 82ce23f5d..e4266158b 100644 --- a/appium-dotnet-driver/Appium/iOS/IOSElement.cs +++ b/appium-dotnet-driver/Appium/iOS/IOSElement.cs @@ -1,4 +1,5 @@ using OpenQA.Selenium.Appium.Interfaces; +using OpenQA.Selenium.Remote; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -7,38 +8,30 @@ namespace OpenQA.Selenium.Appium.iOS { - public class IOSElement : AppiumWebElement, IFindByIosUIAutomation + public class IOSElement : AppiumWebElement, IFindByIosUIAutomation { /// /// Initializes a new instance of the IOSElement class. /// /// Driver in use. /// ID of the element. - public IOSElement(AppiumDriver parent, string id) + public IOSElement(RemoteWebDriver parent, string id) : base(parent, id) { } #region IFindByIosUIAutomation Members - /// - /// Finds the first of elements that match the Ios UIAutomation selector supplied - /// - /// an Ios UIAutomation selector - /// IWebElement object so that you can interact that object - public IWebElement FindElementByIosUIAutomation(string selector) + + public AppiumWebElement FindElementByIosUIAutomation(string selector) { - return this.FindElement("-ios uiautomation", selector); + return (AppiumWebElement) this.FindElement("-ios uiautomation", selector); } - /// - /// Finds a list of elements that match the Ios UIAutomation selector supplied - /// - /// an Ios UIAutomation selector - /// IWebElement object so that you can interact that object - public ReadOnlyCollection FindElementsByIosUIAutomation(string selector) + public ReadOnlyCollection FindElementsByIosUIAutomation(string selector) { - return this.FindElements("-ios uiautomation", selector); + return CollectionConverterUnility. + ConvertToExtendedWebElementCollection(this.FindElements("-ios uiautomation", selector)); } #endregion IFindByIosUIAutomation Members } diff --git a/appium-dotnet-driver/appium-dotnet-driver.csproj b/appium-dotnet-driver/appium-dotnet-driver.csproj index ac037bc8f..45438454b 100644 --- a/appium-dotnet-driver/appium-dotnet-driver.csproj +++ b/appium-dotnet-driver/appium-dotnet-driver.csproj @@ -55,6 +55,15 @@ + + + + + + + + + @@ -65,6 +74,7 @@ + diff --git a/samples/AndroidComplexTest.cs b/samples/AndroidComplexTest.cs index cb1f1e4ba..9e1670f24 100644 --- a/samples/AndroidComplexTest.cs +++ b/samples/AndroidComplexTest.cs @@ -19,7 +19,7 @@ namespace Appium.Samples [TestFixture ()] public class AndroidComplexTest { - private AppiumDriver driver; + private AndroidDriver driver; private bool allPassed = true; [SetUp] @@ -34,7 +34,7 @@ public void BeforeAll(){ capabilities.SetCapability("tags", new string[]{"sample"}); } Uri serverUri = Env.isSauce () ? AppiumServers.sauceURI : AppiumServers.localURI; - driver = new AndroidDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); + driver = new AndroidDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); driver.Manage().Timeouts().ImplicitlyWait(Env.IMPLICIT_TIMEOUT_SEC); } @@ -52,31 +52,31 @@ public void FindElementTestCase () driver.FindElementByXPath ("//android.widget.TextView[@text='Animation']"); Assert.AreEqual( driver.FindElementByXPath ("//android.widget.TextView").Text, "API Demos"); - IList els = driver.FindElementsByXPath ("//android.widget.TextView[contains(@text, 'Animat')]"); - els = Filters.FilterDisplayed (els); + IList els = driver.FindElementsByXPath ("//android.widget.TextView[contains(@text, 'Animat')]"); + var elsres = Filters.FilterDisplayed(els); if (!Env.isSauce ()) { - Assert.AreEqual (els [0].Text, "Animation"); + Assert.AreEqual (elsres [0].Text, "Animation"); } driver.FindElementByName ("App").Click(); Thread.Sleep (3000); - els = ((AndroidDriver) driver).FindElementsByAndroidUIAutomator ("new UiSelector().clickable(true)"); + els = driver.FindElementsByAndroidUIAutomator("new UiSelector().clickable(true)"); Assert.GreaterOrEqual (els.Count, 10); Assert.IsNotNull ( driver.FindElementByXPath("//android.widget.TextView[@text='Action Bar']")); els = driver.FindElementsByXPath ("//android.widget.TextView"); - els = Filters.FilterDisplayed (els); - Assert.AreEqual (els[0].Text, "API Demos"); + elsres = Filters.FilterDisplayed(els); + Assert.AreEqual(elsres[0].Text, "API Demos"); driver.Navigate ().Back (); } [Test] public void StartActivityInThisAppTestCase() { - ((AndroidDriver) driver).StartActivity("io.appium.android.apis", ".ApiDemos"); + driver.StartActivity("io.appium.android.apis", ".ApiDemos"); _AssertActivityNameContains("Demos"); - ((AndroidDriver) driver).StartActivity("io.appium.android.apis", ".accessibility.AccessibilityNodeProviderActivity"); + driver.StartActivity("io.appium.android.apis", ".accessibility.AccessibilityNodeProviderActivity"); _AssertActivityNameContains("Node"); } @@ -84,11 +84,11 @@ public void StartActivityInThisAppTestCase() [Test] public void StartActivityInNewAppTestCase() { - ((AndroidDriver) driver).StartActivity("io.appium.android.apis", ".ApiDemos"); + driver.StartActivity("io.appium.android.apis", ".ApiDemos"); _AssertActivityNameContains("Demos"); - ((AndroidDriver) driver).StartActivity("com.android.contacts", ".ContactsListActivity"); + driver.StartActivity("com.android.contacts", ".ContactsListActivity"); _AssertActivityNameContains("Contact"); } @@ -97,7 +97,7 @@ private void _AssertActivityNameContains(string activityName) { Contract.Requires(!String.IsNullOrWhiteSpace(activityName)); - String activity = ((AndroidDriver) driver).CurrentActivity; + String activity = driver.CurrentActivity; Debug.WriteLine (activity); Assert.IsNotNullOrEmpty(activity); @@ -108,7 +108,7 @@ private void _AssertActivityNameContains(string activityName) public void ScrollTestCase () { driver.FindElementByXPath (".//android.widget.TextView[@text='Animation']"); - IList els = driver.FindElementsByXPath (".//android.widget.TextView"); + IList els = driver.FindElementsByXPath (".//android.widget.TextView"); var loc1 = els [7].Location; var loc2 = els [3].Location; var swipe = Actions.Swipe (driver, loc1.X, loc1.Y, loc2.X, loc2.Y, 800); @@ -216,7 +216,7 @@ public void DrawSmileyTestCase () [Test()] public void HideKeyBoardTestCase() { - ((AndroidDriver)driver).StartActivity("io.appium.android.apis", ".app.CustomTitle"); + driver.StartActivity("io.appium.android.apis", ".app.CustomTitle"); driver.FindElement(By.Id("io.appium.android.apis:id/left_text_edit")).Clear(); driver.HideKeyboard(); } diff --git a/samples/AndroidConnectionTest.cs b/samples/AndroidConnectionTest.cs index 6377b6ee4..7f28e36db 100644 --- a/samples/AndroidConnectionTest.cs +++ b/samples/AndroidConnectionTest.cs @@ -14,7 +14,7 @@ namespace Appium.Samples [TestFixture()] class AndroidConnectionTest { - private AppiumDriver driver; + private AppiumDriver driver; private bool allPassed = true; [TestFixtureSetUp] @@ -31,7 +31,7 @@ public void BeforeAll() capabilities.SetCapability("tags", new string[] { "sample" }); } Uri serverUri = Env.isSauce() ? AppiumServers.sauceURI : AppiumServers.localURI; - driver = new AndroidDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); + driver = new AndroidDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); driver.Manage().Timeouts().ImplicitlyWait(Env.IMPLICIT_TIMEOUT_SEC); } @@ -58,11 +58,11 @@ public void AfterEach() [Test] public void ConnectionTest() { - ((AndroidDriver)driver).ConnectionType = ConnectionType.AirplaneMode; - Assert.AreEqual(ConnectionType.AirplaneMode, ((AndroidDriver)driver).ConnectionType); + ((AndroidDriver)driver).ConnectionType = ConnectionType.AirplaneMode; + Assert.AreEqual(ConnectionType.AirplaneMode, ((AndroidDriver)driver).ConnectionType); - ((AndroidDriver)driver).ConnectionType = ConnectionType.WifiOnly; - Assert.AreEqual(ConnectionType.WifiOnly, ((AndroidDriver)driver).ConnectionType); + ((AndroidDriver)driver).ConnectionType = ConnectionType.WifiOnly; + Assert.AreEqual(ConnectionType.WifiOnly, ((AndroidDriver)driver).ConnectionType); } } } diff --git a/samples/AndroidLocalServerTest.cs b/samples/AndroidLocalServerTest.cs index 2df66229d..b51d4ef6f 100644 --- a/samples/AndroidLocalServerTest.cs +++ b/samples/AndroidLocalServerTest.cs @@ -14,7 +14,7 @@ namespace Appium.Samples [TestFixture ()] public class AndroidLocalServerTest { - private AppiumDriver driver; + private AppiumDriver driver; private bool allPassed = true; LocalServer server = new LocalServer (3001); @@ -31,7 +31,7 @@ public void BeforeAll(){ capabilities.SetCapability("tags", new string[]{"sample"}); } Uri serverUri = Env.isSauce () ? AppiumServers.sauceURI : AppiumServers.localURI; - driver = new AndroidDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); + driver = new AndroidDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); driver.Manage().Timeouts().ImplicitlyWait(Env.IMPLICIT_TIMEOUT_SEC); } diff --git a/samples/AndroidOrientationTest.cs b/samples/AndroidOrientationTest.cs index 7de90b86b..efa3a341c 100644 --- a/samples/AndroidOrientationTest.cs +++ b/samples/AndroidOrientationTest.cs @@ -30,7 +30,7 @@ public void BeforeAll() capabilities.SetCapability("tags", new string[] { "sample" }); } Uri serverUri = Env.isSauce() ? AppiumServers.sauceURI : AppiumServers.localURI; - driver = new AndroidDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); + driver = new AndroidDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); driver.Manage().Timeouts().ImplicitlyWait(Env.IMPLICIT_TIMEOUT_SEC); } diff --git a/samples/AndroidSimpleTest.cs b/samples/AndroidSimpleTest.cs index c80a2a274..1d15ea6f9 100644 --- a/samples/AndroidSimpleTest.cs +++ b/samples/AndroidSimpleTest.cs @@ -14,7 +14,7 @@ namespace Appium.Samples [TestFixture ()] public class AndroidSimpleTest { - private AppiumDriver driver; + private AndroidDriver driver; private bool allPassed = true; [TestFixtureSetUp] @@ -29,7 +29,7 @@ public void BeforeAll(){ capabilities.SetCapability("tags", new string[]{"sample"}); } Uri serverUri = Env.isSauce () ? AppiumServers.sauceURI : AppiumServers.localURI; - driver = new AndroidDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); + driver = new AndroidDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); driver.Manage().Timeouts().ImplicitlyWait(Env.IMPLICIT_TIMEOUT_SEC); } @@ -54,13 +54,24 @@ public void AfterEach(){ [Test ()] public void FindElementTestCase () { - driver.FindElementByAccessibilityId ("Graphics").Click (); + By byAccessibilityId = new ByAccessibilityId("Graphics"); + Assert.AreNotEqual(driver.FindElement(byAccessibilityId).Text, null); + Assert.GreaterOrEqual(driver.FindElements(byAccessibilityId).Count, 1); + + driver.FindElementByAccessibilityId ("Graphics").Click (); Assert.IsNotNull (driver.FindElementByAccessibilityId ("Arcs")); driver.Navigate ().Back (); - Assert.IsNotNull (driver.FindElementByName ("App")); - var els = ((AndroidDriver) driver).FindElementsByAndroidUIAutomator ("new UiSelector().clickable(true)"); - Assert.GreaterOrEqual(els.Count, 12); - els = ((AndroidDriver)driver).FindElementsByAndroidUIAutomator("new UiSelector().enabled(true)"); + + Assert.IsNotNull(driver.FindElementByName("App")); + + Assert.IsNotNull(driver.FindElement(new ByAndroidUIAutomator("new UiSelector().clickable(true)")).Text); + var els = driver.FindElementsByAndroidUIAutomator ("new UiSelector().clickable(true)"); + Assert.GreaterOrEqual(els.Count, 12); + + var els2 = driver.FindElements(new ByAndroidUIAutomator("new UiSelector().enabled(true)")); + Assert.GreaterOrEqual(els2.Count, 20); + + els = driver.FindElementsByAndroidUIAutomator("new UiSelector().enabled(true)"); Assert.GreaterOrEqual (els.Count, 20); Assert.IsNotNull (driver.FindElementByXPath ("//android.widget.TextView[@text='API Demos']")); } diff --git a/samples/AndroidWebviewTest.cs b/samples/AndroidWebviewTest.cs index 9c596aad5..58089de2c 100644 --- a/samples/AndroidWebviewTest.cs +++ b/samples/AndroidWebviewTest.cs @@ -8,13 +8,14 @@ using System.Threading; using System.Drawing; using OpenQA.Selenium.Appium.Android; +using OpenQA.Selenium.Appium.Interfaces; namespace Appium.Samples { [TestFixture ()] public class AndroidWebviewTest { - private AppiumDriver driver; + private IWebDriver driver; private bool allPassed = true; [TestFixtureSetUp] @@ -29,7 +30,7 @@ public void BeforeAll(){ capabilities.SetCapability("tags", new string[]{"sample"}); } Uri serverUri = Env.isSauce () ? AppiumServers.sauceURI : AppiumServers.localURI; - driver = new AndroidDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); + driver = new AndroidDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); driver.Manage().Timeouts().ImplicitlyWait(Env.IMPLICIT_TIMEOUT_SEC); } @@ -54,11 +55,11 @@ public void AfterEach(){ [Test ()] public void FindElementTestCase () { - driver.FindElementByName ("buttonStartWebviewCD").Click (); + driver.FindElement(By.Name("buttonStartWebviewCD")).Click (); Thread.Sleep (5000); if (!Env.isSauce ()) { // Contexts don't work in android 4.3.3 - var contexts = driver.Contexts; + var contexts = ((IContextAware) driver).Contexts; string webviewContext = null; for (int i = 0; i < contexts.Count; i++) { Console.WriteLine (contexts [i]); @@ -67,8 +68,8 @@ public void FindElementTestCase () } } Assert.IsNotNull (webviewContext); - driver.Context = webviewContext; - var el = driver.FindElementById ("name_input"); + ((IContextAware) driver).Context = webviewContext; + var el = driver.FindElement(By.Id ("name_input")); el.Click(); el.Clear (); el.SendKeys ("Appium User"); diff --git a/samples/IosActionsTest.cs b/samples/IosActionsTest.cs index a7075515d..7792c4190 100644 --- a/samples/IosActionsTest.cs +++ b/samples/IosActionsTest.cs @@ -16,7 +16,7 @@ namespace Appium.Samples [TestFixture ()] public class IosActionsTest { - private AppiumDriver driver; + private AppiumDriver driver; private bool allPassed = true; [SetUp] @@ -29,7 +29,7 @@ public void BeforeAll(){ capabilities.SetCapability("tags", new string[]{"sample"}); } Uri serverUri = Env.isSauce () ? AppiumServers.sauceURI : AppiumServers.localURI; - driver = new IOSDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); + driver = new IOSDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); driver.Manage().Timeouts().ImplicitlyWait(Env.IMPLICIT_TIMEOUT_SEC); } diff --git a/samples/IosComplexTest.cs b/samples/IosComplexTest.cs index 05978826d..8ff0f567d 100644 --- a/samples/IosComplexTest.cs +++ b/samples/IosComplexTest.cs @@ -18,7 +18,7 @@ namespace Appium.Samples [TestFixture ()] public class IosComplexTest { - private AppiumDriver driver; + private AppiumDriver driver; private bool allPassed = true; [SetUp] @@ -31,7 +31,7 @@ public void beforeAll(){ capabilities.SetCapability("tags", new string[]{"sample"}); } Uri serverUri = Env.isSauce () ? AppiumServers.sauceURI : AppiumServers.localURI; - driver = new IOSDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); + driver = new IOSDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); driver.Manage().Timeouts().ImplicitlyWait(Env.IMPLICIT_TIMEOUT_SEC); } @@ -198,9 +198,9 @@ public void HideKeyBoardTestCase() e.Click(); driver.HideKeyboard(); e.Click(); - ((IOSDriver) driver).HideKeyboard("Done"); + ((IOSDriver) driver).HideKeyboard("Done"); e.Click(); - ((IOSDriver)driver).HideKeyboard("Done", HideKeyboardStrategy.Tap_outside); + ((IOSDriver) driver).HideKeyboard("Done", HideKeyboardStrategy.Tap_outside); } } diff --git a/samples/IosLocalServerTest.cs b/samples/IosLocalServerTest.cs index a852b27c9..62d75c6cc 100644 --- a/samples/IosLocalServerTest.cs +++ b/samples/IosLocalServerTest.cs @@ -16,7 +16,7 @@ namespace Appium.Samples [TestFixture ()] public class IosLocalServerTest { - private AppiumDriver driver; + private AppiumDriver driver; private bool allPassed = true; LocalServer server = new LocalServer (3000); @@ -31,7 +31,7 @@ public void BeforeAll(){ capabilities.SetCapability("tags", new string[]{"sample"}); } Uri serverUri = Env.isSauce () ? AppiumServers.sauceURI : AppiumServers.localURI; - driver = new IOSDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); + driver = new IOSDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); driver.Manage().Timeouts().ImplicitlyWait(Env.IMPLICIT_TIMEOUT_SEC); } diff --git a/samples/IosOrientationTest.cs b/samples/IosOrientationTest.cs index f8b0c1ebd..2e433e158 100644 --- a/samples/IosOrientationTest.cs +++ b/samples/IosOrientationTest.cs @@ -26,7 +26,7 @@ public void beforeAll(){ capabilities.SetCapability("tags", new string[]{"sample"}); } Uri serverUri = Env.isSauce () ? AppiumServers.sauceURI : AppiumServers.localURI; - driver = new IOSDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); + driver = new IOSDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); driver.Manage().Timeouts().ImplicitlyWait(Env.IMPLICIT_TIMEOUT_SEC); } diff --git a/samples/IosSimpleTest.cs b/samples/IosSimpleTest.cs index 728d5efd8..9e564563e 100644 --- a/samples/IosSimpleTest.cs +++ b/samples/IosSimpleTest.cs @@ -14,7 +14,7 @@ namespace Appium.Samples [TestFixture ()] public class IosSimpleTest { - private AppiumDriver driver; + private IOSDriver driver; private bool allPassed = true; private Random rnd = new Random(); @@ -29,7 +29,7 @@ public void BeforeAll(){ capabilities.SetCapability("tags", new string[]{"sample"}); } Uri serverUri = Env.isSauce () ? AppiumServers.sauceURI : AppiumServers.localURI; - driver = new IOSDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); + driver = new IOSDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); driver.Manage().Timeouts().ImplicitlyWait(Env.IMPLICIT_TIMEOUT_SEC); } @@ -74,7 +74,8 @@ public void ComputeSumTestCase () // compute and check the sum driver.FindElementByAccessibilityId ("ComputeSumButton").Click (); Thread.Sleep (1000); - IWebElement sumEl = ((IOSDriver) driver).FindElementByIosUIAutomation (".elements().withName(\"Answer\")"); + + IWebElement sumEl = driver.FindElementByIosUIAutomation (".elements().withName(\"Answer\")"); int sumOut = Convert.ToInt32 (sumEl.Text); Assert.AreEqual (sumIn, sumOut); } diff --git a/samples/IosWebviewTest.cs b/samples/IosWebviewTest.cs index 03aac565d..7629a3193 100644 --- a/samples/IosWebviewTest.cs +++ b/samples/IosWebviewTest.cs @@ -16,7 +16,7 @@ namespace Appium.Samples [TestFixture ()] public class IosWebviewTest { - private AppiumDriver driver; + private AppiumDriver driver; private bool allPassed = true; [TestFixtureSetUp] @@ -29,7 +29,7 @@ public void BeforeAll(){ capabilities.SetCapability("tags", new string[]{"sample"}); } Uri serverUri = Env.isSauce () ? AppiumServers.sauceURI : AppiumServers.localURI; - driver = new IOSDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); + driver = new IOSDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC); driver.Manage().Timeouts().ImplicitlyWait(Env.IMPLICIT_TIMEOUT_SEC); } diff --git a/samples/helpers/Actions.cs b/samples/helpers/Actions.cs index 505da024a..58c1a3ef1 100644 --- a/samples/helpers/Actions.cs +++ b/samples/helpers/Actions.cs @@ -3,12 +3,14 @@ using OpenQA.Selenium.Appium; using OpenQA.Selenium.Appium.MultiTouch; using OpenQA.Selenium.Appium.Interfaces; +using OpenQA.Selenium; +using OpenQA.Selenium.Remote; namespace Appium.Samples.Helpers { public class Actions { - public static ITouchAction Swipe(AppiumDriver driver, int startX, int startY, int endX, int endY, + public static ITouchAction Swipe(IPerformsTouchActions driver, int startX, int startY, int endX, int endY, int duration) { ITouchAction touchAction = new TouchAction(driver) .Press (startX, startY) diff --git a/samples/helpers/Filters.cs b/samples/helpers/Filters.cs index 16903b181..b81197a6f 100644 --- a/samples/helpers/Filters.cs +++ b/samples/helpers/Filters.cs @@ -5,43 +5,47 @@ namespace Appium.Samples.Helpers { - public class Filters - { - public static IWebElement FirstWithName(IList els, string name) - { - for (int i = 0; i < els.Count; i++) - { - if (els [i].GetAttribute ("name") == name) { - return els[i]; - } - } - return null; - } + public class Filters + { + public static IWebElement FirstWithName(IList els, string name) where W : IWebElement + { + for (int i = 0; i < els.Count; i++) + { + if (els[i].GetAttribute("name") == name) + { + return (W)els[i]; + } + } + return null; + } - public static IList FilterWithName(IList els, string name) - { - var res = new List (); - for (int i = 0; i < els.Count; i++) - { - if (els [i].GetAttribute ("name") == name) { - res.Add(els [i]); - } - } - return res; - } + public static IList FilterWithName(IList els, string name) where W : IWebElement + { + var res = new List(); + for (int i = 0; i < els.Count; i++) + { + if (els[i].GetAttribute("name") == name) + { + res.Add(els[i]); + } + } + return res; - public static IList FilterDisplayed(IList els) - { - var res = new List (); - for (int i = 0; i < els.Count; i++) - { - IWebElement el = els [i]; - if (els [i].Displayed ) { - res.Add(els [i]); - } - } - return res; - } + } - } + public static IList FilterDisplayed(IList els) where W : IWebElement + { + var res = new List(); + for (int i = 0; i < els.Count; i++) + { + IWebElement el = els[i]; + if (els[i].Displayed) + { + res.Add(els[i]); + } + } + return res; + } + + } } diff --git a/test/specs/MJsonMethodTest.cs b/test/specs/MJsonMethodTest.cs index b36de4b8a..895cd16da 100644 --- a/test/specs/MJsonMethodTest.cs +++ b/test/specs/MJsonMethodTest.cs @@ -8,273 +8,269 @@ namespace OpenQA.Selenium.Appium.Test.Specs { - [TestFixture ()] - public class MJsonMethodTest - { - public FakeAppium server; + [TestFixture()] + public class MJsonMethodTest + { + public FakeAppium server; public readonly Uri defaultUri = new Uri("http://127.0.0.1:4733/wd/hub"); public readonly DesiredCapabilities capabilities = new DesiredCapabilities(); - [TestFixtureSetUp] - public void RunBeforeAll(){ - server = new FakeAppium (4733); - server.Start (); - server.respondToInit (); - server.clear (); - } + [TestFixtureSetUp] + public void RunBeforeAll() + { + server = new FakeAppium(4733); + server.Start(); + server.respondToInit(); + server.clear(); + } - [TestFixtureTearDown] - public void RunAfterAll(){ - server.Stop (); - } - - [TearDown] - public void RunAfterEach() - { - server.clear (); - } + [TestFixtureTearDown] + public void RunAfterAll() + { + server.Stop(); + } - [Test] - public void ShakeDeviceTestCase () - { - IOSDriver driver = new IOSDriver(defaultUri, capabilities); - server.respondTo ("POST", "/appium/device/shake", null); - driver.ShakeDevice (); - } + [TearDown] + public void RunAfterEach() + { + server.clear(); + } - [Test] - public void LockDeviceTestCase () - { - IOSDriver driver = new IOSDriver(defaultUri, capabilities); - server.respondTo ("POST", "/appium/device/lock", null); - driver.LockDevice (3); - } + [Test] + public void ShakeDeviceTestCase() + { + IOSDriver driver = new IOSDriver(defaultUri, capabilities); + server.respondTo("POST", "/appium/device/shake", null); + driver.ShakeDevice(); + } + [Test] + public void LockDeviceTestCase() + { + IOSDriver driver = new IOSDriver(defaultUri, capabilities); + server.respondTo("POST", "/appium/device/lock", null); + driver.LockDevice(3); + } - [Test] - public void SetContextTestCase () - { - IOSDriver driver = new IOSDriver(defaultUri, capabilities); - server.respondTo ("POST", "/context", null); - driver.Context = "1234"; - } - [Test] - public void GetContextTestCase () - { - IOSDriver driver = new IOSDriver(defaultUri, capabilities); - server.respondTo ("GET", "/context", "1234"); - Assert.AreEqual( driver.Context, "1234"); - } + [Test] + public void SetContextTestCase() + { + IOSDriver driver = new IOSDriver(defaultUri, capabilities); + server.respondTo("POST", "/context", null); + driver.Context = "1234"; + } - [Test] - public void GetContextsTestCase () - { - IOSDriver driver = new IOSDriver(defaultUri, capabilities); - server.respondTo ("GET", "/contexts", new string[] {"ab", "cde", "123"}); - Assert.AreEqual( driver.Contexts, new string[] {"ab", "cde", "123"}); - } + [Test] + public void GetContextTestCase() + { + IOSDriver driver = new IOSDriver(defaultUri, capabilities); + server.respondTo("GET", "/context", "1234"); + Assert.AreEqual(driver.Context, "1234"); + } - [Test] - public void KeyEventTestCase () - { - IOSDriver driver = new IOSDriver(defaultUri, capabilities); - server.respondTo ("POST", "/appium/device/keyevent", null); - driver.KeyEvent(5); - } + [Test] + public void GetContextsTestCase() + { + IOSDriver driver = new IOSDriver(defaultUri, capabilities); + server.respondTo("GET", "/contexts", new string[] { "ab", "cde", "123" }); + Assert.AreEqual(driver.Contexts, new string[] { "ab", "cde", "123" }); + } - [Test] - public void RotateTestCase () - { - IOSDriver driver = new IOSDriver(defaultUri, capabilities); - server.respondTo ("POST", "/appium/device/rotate", null); - Dictionary parameters = new Dictionary {{"x", 114}, - {"y", 198}, {"duration", 5}, {"radius", 3}, {"rotation", 220}, {"touchCount", 2}}; - driver.Rotate (parameters); - } + [Test] + public void KeyEventTestCase() + { + IOSDriver driver = new IOSDriver(defaultUri, capabilities); + server.respondTo("POST", "/appium/device/keyevent", null); + driver.KeyEvent(5); + } - [Test] - public void ElementRotateTestCase () - { - IOSDriver driver = new IOSDriver(defaultUri, capabilities); - server.respondTo ("POST", "/element", new Dictionary { - {"ELEMENT", '5'} - }); - AppiumWebElement element = (AppiumWebElement) driver.FindElementByIosUIAutomation (".elements()"); - server.clear (); - server.respondTo ("POST", "/appium/device/rotate", null); - Dictionary parameters = new Dictionary {{"x", 114}, - {"y", 198}, {"duration", 5}, {"radius", 3}, {"rotation", 220}, {"touchCount", 2}}; - element.Rotate (parameters); - } + [Test] + public void RotateTestCase() + { + IOSDriver driver = new IOSDriver(defaultUri, capabilities); + server.respondTo("POST", "/appium/device/rotate", null); + Dictionary parameters = new Dictionary {{"x", 114}, 
 {"y", 198}, {"duration", 5}, {"radius", 3}, {"rotation", 220}, {"touchCount", 2}}; + driver.Rotate(parameters); + } - [Test] - public void GetCurrentActivityTestCase () - { - AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); - server.respondTo ("GET", "/appium/device/current_activity", ".activities.PeopleActivity"); - string activity = driver.CurrentActivity; - Assert.AreEqual (activity, ".activities.PeopleActivity"); - } + [Test] + public void ElementRotateTestCase() + { + IOSDriver driver = new IOSDriver(defaultUri, capabilities); + server.respondTo("POST", "/element", new Dictionary {
 {"ELEMENT", '5'}
 }); + AppiumWebElement element = (AppiumWebElement)driver.FindElementByIosUIAutomation(".elements()"); + server.clear(); + server.respondTo("POST", "/appium/device/rotate", null); + Dictionary parameters = new Dictionary {{"x", 114}, 
 {"y", 198}, {"duration", 5}, {"radius", 3}, {"rotation", 220}, {"touchCount", 2}}; + element.Rotate(parameters); + } - [Test] - public void InstallAppTestCase () - { - AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); - server.respondTo ("POST", "/appium/device/install_app", null); - driver.InstallApp ("/home/me/apps/superApp"); - } + [Test] + public void GetCurrentActivityTestCase() + { + AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); + server.respondTo("GET", "/appium/device/current_activity", ".activities.PeopleActivity"); + string activity = driver.CurrentActivity; + Assert.AreEqual(activity, ".activities.PeopleActivity"); + } - [Test] - public void RemoveAppTestCase () - { - AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); - server.respondTo ("POST", "/appium/device/remove_app", null); - driver.RemoveApp ("rubbish"); - } + [Test] + public void InstallAppTestCase() + { + AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); + server.respondTo("POST", "/appium/device/install_app", null); + driver.InstallApp("/home/me/apps/superApp"); + } - [Test] - public void IsAppInstalledTestCase () - { - AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); - server.respondTo ("POST", "/appium/device/app_installed", true); - driver.IsAppInstalled ("github"); - } + [Test] + public void RemoveAppTestCase() + { + AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); + server.respondTo("POST", "/appium/device/remove_app", null); + driver.RemoveApp("rubbish"); + } - [Test] - public void PushFileTestCase () - { - AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); - server.respondTo ("POST", "/appium/device/push_file", null); - driver.PushFile ("/pictures/me.jpg", "abde433qsawe3242"); - } + [Test] + public void IsAppInstalledTestCase() + { + AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); + server.respondTo("POST", "/appium/device/app_installed", true); + driver.IsAppInstalled("github"); + } - [Test] - public void PullFileTestCase () - { - AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); - var data = "wqewdsf232wewqqw443"; - server.respondTo ("POST", "/appium/device/pull_file", data); - byte[] result = driver.PullFile ("/pictures/me.jpg"); - Assert.AreEqual (result, Convert.FromBase64String(data)); - } + [Test] + public void PushFileTestCase() + { + AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); + server.respondTo("POST", "/appium/device/push_file", null); + driver.PushFile("/pictures/me.jpg", "abde433qsawe3242"); + } - [Test] - public void ToggleLocationServicesTestCase () - { - AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); - server.respondTo ("POST", "/appium/device/toggle_location_services", null); - driver.ToggleLocationServices (); - } + [Test] + public void PullFileTestCase() + { + AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); + var data = "wqewdsf232wewqqw443"; + server.respondTo("POST", "/appium/device/pull_file", data); + byte[] result = driver.PullFile("/pictures/me.jpg"); + Assert.AreEqual(result, Convert.FromBase64String(data)); + } - [Test] - public void LaunchAppTestCase () - { - AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); - server.respondTo ("POST", "/appium/app/launch", null); - driver.LaunchApp (); - } + [Test] + public void ToggleLocationServicesTestCase() + { + AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); + server.respondTo("POST", "/appium/device/toggle_location_services", null); + driver.ToggleLocationServices(); + } - [Test] - public void CloseAppTestCase () - { - AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); - server.respondTo ("POST", "/appium/app/close", null); - driver.CloseApp (); - } + [Test] + public void LaunchAppTestCase() + { + AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); + server.respondTo("POST", "/appium/app/launch", null); + driver.LaunchApp(); + } - [Test] - public void ResetAppTestCase () - { - AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); - server.respondTo ("POST", "/appium/app/reset", null); - driver.ResetApp (); - } + [Test] + public void CloseAppTestCase() + { + AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); + server.respondTo("POST", "/appium/app/close", null); + driver.CloseApp(); + } - [Test] - public void BackgroundAppTestCase () - { - AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); - server.respondTo ("POST", "/appium/app/background", null); - driver.BackgroundApp (5); - } + [Test] + public void ResetAppTestCase() + { + AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); + server.respondTo("POST", "/appium/app/reset", null); + driver.ResetApp(); + } - [Test] - public void EndTestCoverageTestCase () - { - AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); - var data = "21343n2312j3jw"; - server.respondTo ("POST", "/appium/app/end_test_coverage", data); - var result = driver.EndTestCoverage ("android.intent.action.BOOT_COMPLETED", "/random/path"); - Assert.AreEqual (result, data); - } + [Test] + public void BackgroundAppTestCase() + { + AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); + server.respondTo("POST", "/appium/app/background", null); + driver.BackgroundApp(5); + } - [Test] - public void GetAppStringsTestCase () - { - AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); - var data = "21343n2312j3jw"; - server.respondTo ("POST", "/appium/app/strings", data); - var result = driver.GetAppStrings (); - Assert.AreEqual (result, data); - } + [Test] + public void EndTestCoverageTestCase() + { + AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); + var data = "21343n2312j3jw"; + server.respondTo("POST", "/appium/app/end_test_coverage", data); + var result = driver.EndTestCoverage("android.intent.action.BOOT_COMPLETED", "/random/path"); + Assert.AreEqual(result, data); + } - [Test] - public void SetImmediateValueTestCase () - { - IOSDriver driver = new IOSDriver(defaultUri, capabilities); - server.respondTo ("POST", "/element", new Dictionary { - {"ELEMENT", '5'} - }); - AppiumWebElement element = (AppiumWebElement) driver.FindElementByIosUIAutomation (".elements()"); - server.clear (); - server.respondTo ("POST", "/appium/element/5/value", null); - element.SetImmediateValue ("123"); - } + [Test] + public void GetAppStringsTestCase() + { + AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); + var data = "21343n2312j3jw"; + server.respondTo("POST", "/appium/app/strings", data); + var result = driver.GetAppStrings(); + Assert.AreEqual(result, data); + } - [Test] - public void HideKeyboardTestCase () - { - IOSDriver driver = new IOSDriver(defaultUri, capabilities); - { - server.clear (); - RequestProcessor re = server.respondTo ("POST", "/appium/device/hide_keyboard", null); - driver.HideKeyboard (key: "Done"); - Assert.AreEqual (re.inputData, "{\"keyName\":\"Done\"}"); - } - { - server.clear (); - RequestProcessor re = server.respondTo ("POST", "/appium/device/hide_keyboard", null); - driver.HideKeyboard ("pressKey", "Done"); - Assert.AreEqual (re.inputData, "{\"strategy\":\"pressKey\",\"keyName\":\"Done\"}"); - } - { - server.clear (); - RequestProcessor re = server.respondTo ("POST", "/appium/device/hide_keyboard", null); - driver.HideKeyboard ("tapOutside"); - Assert.AreEqual (re.inputData, "{\"strategy\":\"tapOutside\"}"); - } - } + [Test] + public void SetImmediateValueTestCase() + { + IOSDriver driver = new IOSDriver(defaultUri, capabilities); + server.respondTo("POST", "/element", new Dictionary {
 {"ELEMENT", '5'}
 }); + AppiumWebElement element = (AppiumWebElement)driver.FindElementByIosUIAutomation(".elements()"); + server.clear(); + server.respondTo("POST", "/appium/element/5/value", null); + element.SetImmediateValue("123"); + } - [Test] - public void SettingsTestCase () - { - AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); - { - var data = "{\"setting\": true}"; - Dictionary simpleDict = new Dictionary (); - simpleDict.Add ("setting", true); - server.respondTo ("GET", "/appium/settings", data); - var result = driver.GetSettings (); - Assert.AreEqual (result, simpleDict); - } - { - RequestProcessor re = server.respondTo ("POST", "/appium/settings", null); - driver.IgnoreUnimportantViews (true); - Assert.AreEqual (re.inputData, "{\"settings\":{\"ignoreUnimportantViews\":true}}"); - } - } + [Test] + public void HideKeyboardTestCase() + { + IOSDriver driver = new IOSDriver(defaultUri, capabilities); + { + server.clear(); + RequestProcessor re = server.respondTo("POST", "/appium/device/hide_keyboard", null); + driver.HideKeyboard(key: "Done"); + Assert.AreEqual(re.inputData, "{\"keyName\":\"Done\"}"); + } + { + server.clear(); + RequestProcessor re = server.respondTo("POST", "/appium/device/hide_keyboard", null); + driver.HideKeyboard("pressKey", "Done"); + Assert.AreEqual(re.inputData, "{\"strategy\":\"pressKey\",\"keyName\":\"Done\"}"); + } + { + server.clear(); + RequestProcessor re = server.respondTo("POST", "/appium/device/hide_keyboard", null); + driver.HideKeyboard("tapOutside"); + Assert.AreEqual(re.inputData, "{\"strategy\":\"tapOutside\"}"); + } + } - } + [Test] + public void SettingsTestCase() + { + AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); + { + var data = "{\"setting\": true}"; + Dictionary simpleDict = new Dictionary(); + simpleDict.Add("setting", true); + server.respondTo("GET", "/appium/settings", data); + var result = driver.GetSettings(); + Assert.AreEqual(result, simpleDict); + } + { + RequestProcessor re = server.respondTo("POST", "/appium/settings", null); + driver.IgnoreUnimportantViews(true); + Assert.AreEqual(re.inputData, "{\"settings\":{\"ignoreUnimportantViews\":true}}"); + } + } + + } } diff --git a/test/specs/SelectorTest.cs b/test/specs/SelectorTest.cs index f1826c7b9..b5376b92b 100644 --- a/test/specs/SelectorTest.cs +++ b/test/specs/SelectorTest.cs @@ -8,278 +8,260 @@ namespace OpenQA.Selenium.Appium.Test.Specs { - [TestFixture ()] - public class ByIosUIAutomationTest - { - public FakeAppium server; + [TestFixture()] + public class ByIosUIAutomationTest + { + public FakeAppium server; public readonly Uri defaultUri = new Uri("http://127.0.0.1:4743/wd/hub"); public readonly DesiredCapabilities capabilities = new DesiredCapabilities(); - [TestFixtureSetUp] - public void RunBeforeAll(){ - server = new FakeAppium (4743); - server.Start (); - server.respondToInit (); - server.clear (); - } + [TestFixtureSetUp] + public void RunBeforeAll() + { + server = new FakeAppium(4743); + server.Start(); + server.respondToInit(); + server.clear(); + } + + [TestFixtureTearDown] + public void RunAfterAll() + { + server.Stop(); + } + + [TearDown] + public void RunAfterEach() + { + server.clear(); + } - [TestFixtureTearDown] - public void RunAfterAll(){ - server.Stop (); - } - - [TearDown] - public void RunAfterEach() - { - server.clear (); - } + [Test] + public void FindElementByIosUIAutomationTestCase() + { + IOSDriver driver = new IOSDriver(defaultUri, capabilities); + server.respondTo("POST", "/element", new Dictionary {
 {"ELEMENT", '5'}
 }); + IWebElement element = driver.FindElementByIosUIAutomation(".elements()"); + server.clear(); + server.respondTo("GET", "/element/5/attribute/id", "1234"); + element.GetAttribute("id"); + } - [Test] - public void FindElementByIosUIAutomationTestCase () - { - IOSDriver driver = new IOSDriver(defaultUri, capabilities); - server.respondTo ("POST", "/element", new Dictionary { - {"ELEMENT", '5'} - }); - IWebElement element = driver.FindElementByIosUIAutomation (".elements()"); - server.clear (); - server.respondTo ("GET", "/element/5/attribute/id", "1234"); - element.GetAttribute ("id"); - } - - [Test] - public void FindElementsByIosUIAutomationTestCase () - { - IOSDriver driver = new IOSDriver(defaultUri, capabilities); - List results = new List(); - results.Add (new Dictionary {{"ELEMENT", "4"}}); - results.Add (new Dictionary {{"ELEMENT", "6"}}); - results.Add (new Dictionary {{"ELEMENT", "8"}}); - server.respondTo ("POST", "/elements", results); - ICollection elements = driver.FindElementsByIosUIAutomation (".elements()"); - Assert.AreEqual (elements.Count, 3); - } + [Test] + public void FindElementsByIosUIAutomationTestCase() + { + IOSDriver driver = new IOSDriver(defaultUri, capabilities); + List results = new List(); + results.Add(new Dictionary { { "ELEMENT", "4" } }); + results.Add(new Dictionary { { "ELEMENT", "6" } }); + results.Add(new Dictionary { { "ELEMENT", "8" } }); + server.respondTo("POST", "/elements", results); + ICollection elements = driver.FindElementsByIosUIAutomation(".elements()"); + Assert.AreEqual(elements.Count, 3); + } - [Test] - public void ByIosUIAutomationTestCase () - { - IOSDriver driver = new IOSDriver(defaultUri, capabilities); - server.respondTo ("POST", "/element", new Dictionary { - {"ELEMENT", '5'} - }); - driver.FindElement(new ByIosUIAutomation(".elements()")); - (new ByIosUIAutomation(".elements()")).FindElement(driver); - server.clear (); - List results = new List(); - results.Add (new Dictionary {{"ELEMENT", "4"}}); - server.respondTo ("POST", "/elements", results); - driver.FindElements(new ByIosUIAutomation(".elements()")); - (new ByIosUIAutomation(".elements()")).FindElements(driver); - } + [Test] + public void ByIosUIAutomationTestCase() + { + IOSDriver driver = new IOSDriver(defaultUri, capabilities); + server.respondTo("POST", "/element", new Dictionary {
 {"ELEMENT", '5'}
 }); + driver.FindElement(new ByIosUIAutomation(".elements()")); + (new ByIosUIAutomation(".elements()")).FindElement(driver); + server.clear(); + List results = new List(); + results.Add(new Dictionary { { "ELEMENT", "4" } }); + server.respondTo("POST", "/elements", results); + driver.FindElements(new ByIosUIAutomation(".elements()")); + (new ByIosUIAutomation(".elements()")).FindElements(driver); + } - [Test] - public void FromElementTestCase () - { - IOSDriver driver = new IOSDriver(defaultUri, capabilities); - server.respondTo ("POST", "/element", new Dictionary { - {"ELEMENT", '5'} - }); - IOSElement element = (IOSElement) driver.FindElementByIosUIAutomation (".elements()"); - server.clear (); - server.respondTo ("POST", "/element/5/element", new Dictionary { - {"ELEMENT", '6'} - }); - element.FindElementByIosUIAutomation (".elements()"); - server.clear (); - List results = new List(); - results.Add (new Dictionary {{"ELEMENT", "4"}}); - server.respondTo ("POST", "/element/5/elements", results); - element.FindElementsByIosUIAutomation (".elements()"); - } + [Test] + public void FromElementTestCase() + { + IOSDriver driver = new IOSDriver(defaultUri, capabilities); + server.respondTo("POST", "/element", new Dictionary {
 {"ELEMENT", '5'}
 }); + IOSElement element = (IOSElement)driver.FindElementByIosUIAutomation(".elements()"); + server.clear(); + server.respondTo("POST", "/element/5/element", new Dictionary {
 {"ELEMENT", '6'}
 }); + element.FindElementByIosUIAutomation(".elements()"); + server.clear(); + List results = new List(); + results.Add(new Dictionary { { "ELEMENT", "4" } }); + server.respondTo("POST", "/element/5/elements", results); + element.FindElementsByIosUIAutomation(".elements()"); + } - } + } - [TestFixture ()] - public class ByAndroidUIAutomatorTest - { - public FakeAppium server; + [TestFixture()] + public class ByAndroidUIAutomatorTest + { + public FakeAppium server; public readonly Uri defaultUri = new Uri("http://127.0.0.1:4744/wd/hub"); public readonly DesiredCapabilities capabilities = new DesiredCapabilities(); - [TestFixtureSetUp] - public void RunBeforeAll(){ - server = new FakeAppium (4744); - server.Start (); + [TestFixtureSetUp] + public void RunBeforeAll() + { + server = new FakeAppium(4744); + server.Start(); server.respondToInit(); - server.clear (); - } + server.clear(); + } - [TestFixtureTearDown] - public void RunAfterAll(){ - server.Stop (); - } + [TestFixtureTearDown] + public void RunAfterAll() + { + server.Stop(); + } - [TearDown] - public void RunAfterEach() - { - server.clear (); - } + [TearDown] + public void RunAfterEach() + { + server.clear(); + } - [Test] - public void FindElementByAndroidUIAutomatorTestCase () - { - AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); - server.respondTo ("POST", "/element", new Dictionary { - {"ELEMENT", '5'} - }); - IWebElement element = driver.FindElementByAndroidUIAutomator (".elements()"); - server.clear (); - server.respondTo ("GET", "/element/5/attribute/id", "1234"); - element.GetAttribute ("id"); - } + [Test] + public void FindElementByAndroidUIAutomatorTestCase() + { + AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); + server.respondTo("POST", "/element", new Dictionary {
 {"ELEMENT", '5'}
 }); + IWebElement element = driver.FindElementByAndroidUIAutomator(".elements()"); + server.clear(); + server.respondTo("GET", "/element/5/attribute/id", "1234"); + element.GetAttribute("id"); + } - [Test] - public void FindElementsByAndroidUIAutomatorTestCase () - { - AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); - List results = new List(); - results.Add (new Dictionary {{"ELEMENT", "4"}}); - results.Add (new Dictionary {{"ELEMENT", "6"}}); - results.Add (new Dictionary {{"ELEMENT", "8"}}); - server.respondTo ("POST", "/elements", results); - ICollection elements = driver.FindElementsByAndroidUIAutomator (".elements()"); - Assert.AreEqual (elements.Count, 3); - } + [Test] + public void FindElementsByAndroidUIAutomatorTestCase() + { + AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); + List results = new List(); + results.Add(new Dictionary { { "ELEMENT", "4" } }); + results.Add(new Dictionary { { "ELEMENT", "6" } }); + results.Add(new Dictionary { { "ELEMENT", "8" } }); + server.respondTo("POST", "/elements", results); + ICollection elements = driver.FindElementsByAndroidUIAutomator(".elements()"); + Assert.AreEqual(elements.Count, 3); + } - [Test] - public void ByAndroidUIAutomatorTestCase () - { - AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); - server.respondTo ("POST", "/element", new Dictionary { - {"ELEMENT", '5'} - }); - driver.FindElement(new ByAndroidUIAutomator(".elements()")); - (new ByAndroidUIAutomator(".elements()")).FindElement(driver); - server.clear (); - List results = new List(); - results.Add (new Dictionary {{"ELEMENT", "4"}}); - server.respondTo ("POST", "/elements", results); - driver.FindElements(new ByAndroidUIAutomator(".elements()")); - (new ByAndroidUIAutomator(".elements()")).FindElements(driver); - } + [Test] + public void ByAndroidUIAutomatorTestCase() + { + AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); + server.respondTo("POST", "/element", new Dictionary {
 {"ELEMENT", '5'}
 }); + driver.FindElement(new ByAndroidUIAutomator(".elements()")); + (new ByAndroidUIAutomator(".elements()")).FindElement(driver); + server.clear(); + List results = new List(); + results.Add(new Dictionary { { "ELEMENT", "4" } }); + server.respondTo("POST", "/elements", results); + driver.FindElements(new ByAndroidUIAutomator(".elements()")); + (new ByAndroidUIAutomator(".elements()")).FindElements(driver); + } - [Test] - public void FromElementTestCase () - { - AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); - server.respondTo ("POST", "/element", new Dictionary { - {"ELEMENT", '5'} - }); - AndroidElement element = (AndroidElement) driver.FindElementByAndroidUIAutomator (".elements()"); - server.clear (); - server.respondTo ("POST", "/element/5/element", new Dictionary { - {"ELEMENT", '6'} - }); - element.FindElementByAndroidUIAutomator (".elements()"); - server.clear (); - List results = new List(); - results.Add (new Dictionary {{"ELEMENT", "4"}}); - server.respondTo ("POST", "/element/5/elements", results); - element.FindElementsByAndroidUIAutomator (".elements()"); - } + [Test] + public void FromElementTestCase() + { + AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); + server.respondTo("POST", "/element", new Dictionary {
 {"ELEMENT", '5'}
 }); + AndroidElement element = (AndroidElement)driver.FindElementByAndroidUIAutomator(".elements()"); + server.clear(); + server.respondTo("POST", "/element/5/element", new Dictionary {
 {"ELEMENT", '6'}
 }); + element.FindElementByAndroidUIAutomator(".elements()"); + server.clear(); + List results = new List(); + results.Add(new Dictionary { { "ELEMENT", "4" } }); + server.respondTo("POST", "/element/5/elements", results); + element.FindElementsByAndroidUIAutomator(".elements()"); + } - } - - [TestFixture ()] - public class ByAccessibilityIdTest - { - public FakeAppium server; + } + + [TestFixture()] + public class ByAccessibilityIdTest + { + public FakeAppium server; public readonly Uri defaultUri = new Uri("http://127.0.0.1:4745/wd/hub"); public readonly DesiredCapabilities capabilities = new DesiredCapabilities(); - [TestFixtureSetUp] - public void RunBeforeAll(){ - server = new FakeAppium (4745); - server.Start (); - server.respondToInit (); - server.clear (); - } + [TestFixtureSetUp] + public void RunBeforeAll() + { + server = new FakeAppium(4745); + server.Start(); + server.respondToInit(); + server.clear(); + } - [TestFixtureTearDown] - public void RunAfterAll(){ - server.Stop (); - } + [TestFixtureTearDown] + public void RunAfterAll() + { + server.Stop(); + } - [TearDown] - public void RunAfterEach() - { - server.clear (); - } + [TearDown] + public void RunAfterEach() + { + server.clear(); + } - [Test] - public void FindElementByAccessibilityIdTestCase () - { - IOSDriver driver = new IOSDriver(defaultUri, capabilities); - server.respondTo ("POST", "/element", new Dictionary { - {"ELEMENT", '5'} - }); - IWebElement element = driver.FindElementByAccessibilityId (".elements()"); - server.clear (); - server.respondTo ("GET", "/element/5/attribute/id", "1234"); - element.GetAttribute ("id"); - } + [Test] + public void FindElementByAccessibilityIdTestCase() + { + IOSDriver driver = new IOSDriver(defaultUri, capabilities); + server.respondTo("POST", "/element", new Dictionary {
 {"ELEMENT", '5'}
 }); + IWebElement element = driver.FindElementByAccessibilityId(".elements()"); + server.clear(); + server.respondTo("GET", "/element/5/attribute/id", "1234"); + element.GetAttribute("id"); + } - [Test] - public void FindElementsByAccessibilityIdTestCase () - { - IOSDriver driver = new IOSDriver(defaultUri, capabilities); - List results = new List(); - results.Add (new Dictionary {{"ELEMENT", "4"}}); - results.Add (new Dictionary {{"ELEMENT", "6"}}); - results.Add (new Dictionary {{"ELEMENT", "8"}}); - server.respondTo ("POST", "/elements", results); - ICollection elements = driver.FindElementsByAccessibilityId (".elements()"); - Assert.AreEqual (elements.Count, 3); - } + [Test] + public void FindElementsByAccessibilityIdTestCase() + { + IOSDriver driver = new IOSDriver(defaultUri, capabilities); + List results = new List(); + results.Add(new Dictionary { { "ELEMENT", "4" } }); + results.Add(new Dictionary { { "ELEMENT", "6" } }); + results.Add(new Dictionary { { "ELEMENT", "8" } }); + server.respondTo("POST", "/elements", results); + ICollection elements = driver.FindElementsByAccessibilityId(".elements()"); + Assert.AreEqual(elements.Count, 3); + } - [Test] - public void ByAccessibilityIdTestCase () - { - IOSDriver driver = new IOSDriver(defaultUri, capabilities); - server.respondTo ("POST", "/element", new Dictionary { - {"ELEMENT", '5'} - }); - driver.FindElement(new ByAccessibilityId(".elements()")); - (new ByAccessibilityId(".elements()")).FindElement(driver); - server.clear (); - List results = new List(); - results.Add (new Dictionary {{"ELEMENT", "4"}}); - server.respondTo ("POST", "/elements", results); - driver.FindElements(new ByAccessibilityId(".elements()")); - (new ByAccessibilityId(".elements()")).FindElements(driver); - } + [Test] + public void ByAccessibilityIdTestCase() + { + IOSDriver driver = new IOSDriver(defaultUri, capabilities); + server.respondTo("POST", "/element", new Dictionary {
 {"ELEMENT", '5'}
 }); + driver.FindElement(new ByAccessibilityId(".elements()")); + (new ByAccessibilityId(".elements()")).FindElement(driver); + server.clear(); + List results = new List(); + results.Add(new Dictionary { { "ELEMENT", "4" } }); + server.respondTo("POST", "/elements", results); + driver.FindElements(new ByAccessibilityId(".elements()")); + (new ByAccessibilityId(".elements()")).FindElements(driver); + } - [Test] - public void FromElementTestCase () - { - IOSDriver driver = new IOSDriver(defaultUri, capabilities); - server.respondTo ("POST", "/element", new Dictionary { - {"ELEMENT", '5'} - }); - AppiumWebElement element = (AppiumWebElement) driver.FindElementByAccessibilityId (".elements()"); - server.clear (); - server.respondTo ("POST", "/element/5/element", new Dictionary { - {"ELEMENT", '6'} - }); - element.FindElementByAccessibilityId (".elements()"); - server.clear (); - List results = new List(); - results.Add (new Dictionary {{"ELEMENT", "4"}}); - server.respondTo ("POST", "/element/5/elements", results); - element.FindElementsByAccessibilityId (".elements()"); - } + [Test] + public void FromElementTestCase() + { + IOSDriver driver = new IOSDriver(defaultUri, capabilities); + server.respondTo("POST", "/element", new Dictionary {
 {"ELEMENT", '5'}
 }); + AppiumWebElement element = (AppiumWebElement)driver.FindElementByAccessibilityId(".elements()"); + server.clear(); + server.respondTo("POST", "/element/5/element", new Dictionary {
 {"ELEMENT", '6'}
 }); + element.FindElementByAccessibilityId(".elements()"); + server.clear(); + List results = new List(); + results.Add(new Dictionary { { "ELEMENT", "4" } }); + server.respondTo("POST", "/element/5/elements", results); + element.FindElementsByAccessibilityId(".elements()"); + } - } + } } diff --git a/test/specs/SessionTest.cs b/test/specs/SessionTest.cs index 4cf1da84e..d8e2dda72 100644 --- a/test/specs/SessionTest.cs +++ b/test/specs/SessionTest.cs @@ -6,89 +6,93 @@ namespace OpenQA.Selenium.Appium.Test.Specs { - [TestFixture] - public class InitSessionTest - { - public FakeAppium server; + [TestFixture] + public class InitSessionTest + { + public FakeAppium server; public readonly Uri defaultUri = new Uri("http://127.0.0.1:4733/wd/hub"); public readonly DesiredCapabilities capabilities = new DesiredCapabilities(); - [TestFixtureSetUp] - public void RunBeforeAll(){ - server = new FakeAppium (4723); - server.Start (); - } + [TestFixtureSetUp] + public void RunBeforeAll() + { + server = new FakeAppium(4723); + server.Start(); + } - [TestFixtureTearDown] - public void RunAfterAll(){ - server.Stop (); - } + [TestFixtureTearDown] + public void RunAfterAll() + { + server.Stop(); + } - [TearDown] - public void RunAfterEach() - { - server.clear (); - } + [TearDown] + public void RunAfterEach() + { + server.clear(); + } - [Test] - public void InitSessionTestCase () - { - server.respondToInit (); - DesiredCapabilities capabilities = new DesiredCapabilities(); - new AndroidDriver (capabilities); - } - } + [Test] + public void InitSessionTestCase() + { + server.respondToInit(); + DesiredCapabilities capabilities = new DesiredCapabilities(); + new AndroidDriver(capabilities); + } + } - [TestFixture] - public class EndSessionTest - { - public FakeAppium server; + [TestFixture] + public class EndSessionTest + { + public FakeAppium server; public readonly Uri defaultUri = new Uri("http://127.0.0.1:4724/wd/hub"); public readonly DesiredCapabilities capabilities = new DesiredCapabilities(); - [TestFixtureSetUp] - public void RunBeforeAll(){ - server = new FakeAppium (4724); - server.Start (); - } + [TestFixtureSetUp] + public void RunBeforeAll() + { + server = new FakeAppium(4724); + server.Start(); + } - [TestFixtureTearDown] - public void RunAfterAll(){ - server.Stop (); - } - - [SetUp] - public void RunBeforeEach() - { - server.respondToInit (); - DesiredCapabilities capabilities = new DesiredCapabilities(); - AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); - server.clear (); - } + [TestFixtureTearDown] + public void RunAfterAll() + { + server.Stop(); + } + [SetUp] + public void RunBeforeEach() + { + server.respondToInit(); + DesiredCapabilities capabilities = new DesiredCapabilities(); + AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); + server.clear(); + } - [TearDown] - public void RunAfterEach() - { - server.clear (); - } - [Test] - public void CloseTestCase () - { - AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); - server.respondTo ("DELETE", "/window", null); - driver.Close (); - } - - [Test] - public void QuitTestCase () - { - AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); - server.respondTo ("DELETE", "/", null); - driver.Quit (); - } + [TearDown] + public void RunAfterEach() + { + server.clear(); + } - } + [Test] + public void CloseTestCase() + { + AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); + server.respondTo("DELETE", "/window", null); + driver.Close(); + } + + [Test] + public void QuitTestCase() + { + AndroidDriver driver = new AndroidDriver(defaultUri, capabilities); + server.respondTo("DELETE", "/", null); + driver.Quit(); + } + + } } diff --git a/test/specs/TouchTest.cs b/test/specs/TouchTest.cs index a0de679d6..abd68ed27 100644 --- a/test/specs/TouchTest.cs +++ b/test/specs/TouchTest.cs @@ -9,241 +9,241 @@ namespace OpenQA.Selenium.Appium.Test.Specs { - [TestFixture ()] - public class TouchTest - { - public FakeAppium server; + [TestFixture()] + public class TouchTest + { + public FakeAppium server; public readonly Uri defaultUri = new Uri("http://127.0.0.1:4753/wd/hub"); public readonly DesiredCapabilities capabilities = new DesiredCapabilities(); - [TestFixtureSetUp] - public void RunBeforeAll(){ - server = new FakeAppium (4753); - server.Start (); - server.respondToInit (); - server.clear (); - } - - [TestFixtureTearDown] - public void RunAfterAll(){ - server.Stop (); - } - - [TearDown] - public void RunAfterEach() - { - server.clear (); - } - - private RequestProcessor setupTouchAction() { - server.respondTo ("POST", "/element", new Dictionary { - {"ELEMENT", '5'} - }); - return server.respondTo ("POST", "/touch/perform", null); - } - - [Test] - public void LongPressTestCase () - { - IOSDriver driver = new IOSDriver(defaultUri, capabilities); - RequestProcessor re = setupTouchAction (); - IWebElement element = driver.FindElementByIosUIAutomation (".elements()"); - - ITouchAction a; - - a = new TouchAction (driver) - .LongPress (element, 50, 75); - a.Perform (); - Assert.AreEqual (re.inputData, "{\"actions\":[{\"action\":\"longpress\",\"options\":{\"element\":\"5\",\"x\":50,\"y\":75}}]}"); - - a = new TouchAction (driver) - .LongPress (element, 0.5, 75); - a.Perform (); - Assert.AreEqual (re.inputData, "{\"actions\":[{\"action\":\"longpress\",\"options\":{\"element\":\"5\",\"x\":0.5,\"y\":75}}]}"); - - a = new TouchAction (driver) - .LongPress (0.5, 75); - a.Perform (); - Assert.AreEqual (re.inputData, "{\"actions\":[{\"action\":\"longpress\",\"options\":{\"x\":0.5,\"y\":75}}]}"); - - a = new TouchAction (driver) - .LongPress (element); - a.Perform (); - Assert.AreEqual (re.inputData, "{\"actions\":[{\"action\":\"longpress\",\"options\":{\"element\":\"5\"}}]}"); - } - - [Test] - public void MoveToTestCase () - { - IOSDriver driver = new IOSDriver(defaultUri, capabilities); - RequestProcessor re = setupTouchAction (); - IWebElement element = driver.FindElementByIosUIAutomation (".elements()"); - - ITouchAction a; - - a = new TouchAction (driver) - .MoveTo (element, 50, 75); - a.Perform (); - Assert.AreEqual (re.inputData, "{\"actions\":[{\"action\":\"moveTo\",\"options\":{\"element\":\"5\",\"x\":50,\"y\":75}}]}"); - - a = new TouchAction (driver) - .MoveTo (element, 0.5, 75); - a.Perform (); - Assert.AreEqual (re.inputData, "{\"actions\":[{\"action\":\"moveTo\",\"options\":{\"element\":\"5\",\"x\":0.5,\"y\":75}}]}"); - - a = new TouchAction (driver) - .MoveTo (0.5, 75); - a.Perform (); - Assert.AreEqual (re.inputData, "{\"actions\":[{\"action\":\"moveTo\",\"options\":{\"x\":0.5,\"y\":75}}]}"); - - a = new TouchAction (driver) - .MoveTo (element); - a.Perform (); - Assert.AreEqual (re.inputData, "{\"actions\":[{\"action\":\"moveTo\",\"options\":{\"element\":\"5\"}}]}"); - } - - [Test] - public void PressTestCase () - { - IOSDriver driver = new IOSDriver(defaultUri, capabilities); - RequestProcessor re = setupTouchAction (); - IWebElement element = driver.FindElementByIosUIAutomation (".elements()"); - - ITouchAction a; - - a = new TouchAction (driver) - .Press (element, 50, 75); - a.Perform (); - Assert.AreEqual (re.inputData, "{\"actions\":[{\"action\":\"press\",\"options\":{\"element\":\"5\",\"x\":50,\"y\":75}}]}"); - - a = new TouchAction (driver) - .Press (element, 0.5, 75); - a.Perform (); - Assert.AreEqual (re.inputData, "{\"actions\":[{\"action\":\"press\",\"options\":{\"element\":\"5\",\"x\":0.5,\"y\":75}}]}"); - - a = new TouchAction (driver) - .Press (0.5, 75); - a.Perform (); - Assert.AreEqual (re.inputData, "{\"actions\":[{\"action\":\"press\",\"options\":{\"x\":0.5,\"y\":75}}]}"); - - a = new TouchAction (driver) - .Press (element); - a.Perform (); - Assert.AreEqual (re.inputData, "{\"actions\":[{\"action\":\"press\",\"options\":{\"element\":\"5\"}}]}"); - } - - [Test] - public void ReleaseTestCase () - { - IOSDriver driver = new IOSDriver(defaultUri, capabilities); - RequestProcessor re = setupTouchAction (); - ITouchAction a; - - a = new TouchAction (driver) - .Release (); - a.Perform (); - Assert.AreEqual (re.inputData, "{\"actions\":[{\"action\":\"release\"}]}"); - } - - [Test] - public void TapTestCase () - { - IOSDriver driver = new IOSDriver(defaultUri, capabilities); - RequestProcessor re = setupTouchAction (); - IWebElement element = driver.FindElementByIosUIAutomation (".elements()"); - - ITouchAction a; - - a = new TouchAction (driver) - .Tap (element, 50, 75); - a.Perform (); - Assert.AreEqual (re.inputData, "{\"actions\":[{\"action\":\"tap\",\"options\":{\"element\":\"5\",\"x\":50,\"y\":75}}]}"); - - a = new TouchAction (driver) - .Tap (element, 50, 75, 10); - a.Perform (); - Assert.AreEqual (re.inputData, "{\"actions\":[{\"action\":\"tap\",\"options\":{\"element\":\"5\",\"x\":50,\"y\":75,\"count\":10}}]}"); - - a = new TouchAction (driver) - .Tap (element, 0.5, 75); - a.Perform (); - Assert.AreEqual (re.inputData, "{\"actions\":[{\"action\":\"tap\",\"options\":{\"element\":\"5\",\"x\":0.5,\"y\":75}}]}"); - - a = new TouchAction (driver) - .Tap (0.5, 75); - a.Perform (); - Assert.AreEqual (re.inputData, "{\"actions\":[{\"action\":\"tap\",\"options\":{\"x\":0.5,\"y\":75}}]}"); - - a = new TouchAction (driver) - .Tap (0.5, 75, 10); - a.Perform (); - Assert.AreEqual (re.inputData, "{\"actions\":[{\"action\":\"tap\",\"options\":{\"x\":0.5,\"y\":75,\"count\":10}}]}"); - - a = new TouchAction (driver) - .Tap (element); - a.Perform (); - Assert.AreEqual (re.inputData, "{\"actions\":[{\"action\":\"tap\",\"options\":{\"element\":\"5\"}}]}"); - - a = new TouchAction (driver) - .Tap (element, count: 10); - a.Perform (); - Assert.AreEqual (re.inputData, "{\"actions\":[{\"action\":\"tap\",\"options\":{\"element\":\"5\",\"count\":10}}]}"); - - } - - [Test] - public void WaitTestCase () - { - IOSDriver driver = new IOSDriver(defaultUri, capabilities); - RequestProcessor re = setupTouchAction (); - ITouchAction a; - - a = new TouchAction (driver) - .Wait (1000); - a.Perform (); - Assert.AreEqual (re.inputData, "{\"actions\":[{\"action\":\"wait\",\"options\":{\"ms\":1000}}]}"); - - a = new TouchAction (driver) - .Wait (); - a.Perform (); - Assert.AreEqual (re.inputData, "{\"actions\":[{\"action\":\"wait\"}]}"); - } - - private RequestProcessor setupMultiAction() { - server.respondTo ("POST", "/element", new Dictionary { - {"ELEMENT", '5'} - }); - return server.respondTo ("POST", "/touch/multi/perform", null); - } - - [Test] - public void MultiActionTestCase () - { - IOSDriver driver = new IOSDriver(defaultUri, capabilities); - RequestProcessor re = setupMultiAction (); - IWebElement element = driver.FindElementByIosUIAutomation (".elements()"); - - MultiAction m = new MultiAction(driver); - m.Perform (); - Assert.AreEqual (re.inputData, ""); - - TouchAction a1 = new TouchAction (); - a1 - .Press (element, 100, 100) - .Wait (1000) - .Release (); - m.Add (a1); - m.Perform (); - Assert.AreEqual (re.inputData, "{\"actions\":[[{\"action\":\"press\",\"options\":{\"element\":\"5\",\"x\":100,\"y\":100}},{\"action\":\"wait\",\"options\":{\"ms\":1000}},{\"action\":\"release\"}]]}"); - - TouchAction a2 = new TouchAction (); - a2 - .Tap (100, 100) - .MoveTo (element); - m.Add (a2); - m.Perform (); - Assert.AreEqual (re.inputData, "{\"actions\":[[{\"action\":\"press\",\"options\":{\"element\":\"5\",\"x\":100,\"y\":100}},{\"action\":\"wait\",\"options\":{\"ms\":1000}},{\"action\":\"release\"}],[{\"action\":\"tap\",\"options\":{\"x\":100,\"y\":100}},{\"action\":\"moveTo\",\"options\":{\"element\":\"5\"}}]]}"); - } - } + [TestFixtureSetUp] + public void RunBeforeAll() + { + server = new FakeAppium(4753); + server.Start(); + server.respondToInit(); + server.clear(); + } + + [TestFixtureTearDown] + public void RunAfterAll() + { + server.Stop(); + } + + [TearDown] + public void RunAfterEach() + { + server.clear(); + } + + private RequestProcessor setupTouchAction() + { + server.respondTo("POST", "/element", new Dictionary {
 {"ELEMENT", '5'}
 }); + return server.respondTo("POST", "/touch/perform", null); + } + + [Test] + public void LongPressTestCase() + { + IOSDriver driver = new IOSDriver(defaultUri, capabilities); + RequestProcessor re = setupTouchAction(); + IWebElement element = driver.FindElementByIosUIAutomation(".elements()"); + + ITouchAction a; + + a = new TouchAction(driver) + .LongPress(element, 50, 75); + a.Perform(); + Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"longpress\",\"options\":{\"element\":\"5\",\"x\":50,\"y\":75}}]}"); + + a = new TouchAction(driver) + .LongPress(element, 0.5, 75); + a.Perform(); + Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"longpress\",\"options\":{\"element\":\"5\",\"x\":0.5,\"y\":75}}]}"); + + a = new TouchAction(driver) + .LongPress(0.5, 75); + a.Perform(); + Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"longpress\",\"options\":{\"x\":0.5,\"y\":75}}]}"); + + a = new TouchAction(driver) + .LongPress(element); + a.Perform(); + Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"longpress\",\"options\":{\"element\":\"5\"}}]}"); + } + + [Test] + public void MoveToTestCase() + { + IOSDriver driver = new IOSDriver(defaultUri, capabilities); + RequestProcessor re = setupTouchAction(); + IWebElement element = driver.FindElementByIosUIAutomation(".elements()"); + + ITouchAction a; + + a = new TouchAction(driver) + .MoveTo(element, 50, 75); + a.Perform(); + Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"moveTo\",\"options\":{\"element\":\"5\",\"x\":50,\"y\":75}}]}"); + + a = new TouchAction(driver) + .MoveTo(element, 0.5, 75); + a.Perform(); + Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"moveTo\",\"options\":{\"element\":\"5\",\"x\":0.5,\"y\":75}}]}"); + + a = new TouchAction(driver) + .MoveTo(0.5, 75); + a.Perform(); + Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"moveTo\",\"options\":{\"x\":0.5,\"y\":75}}]}"); + + a = new TouchAction(driver) + .MoveTo(element); + a.Perform(); + Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"moveTo\",\"options\":{\"element\":\"5\"}}]}"); + } + + [Test] + public void PressTestCase() + { + IOSDriver driver = new IOSDriver(defaultUri, capabilities); + RequestProcessor re = setupTouchAction(); + IWebElement element = driver.FindElementByIosUIAutomation(".elements()"); + + ITouchAction a; + + a = new TouchAction(driver) + .Press(element, 50, 75); + a.Perform(); + Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"press\",\"options\":{\"element\":\"5\",\"x\":50,\"y\":75}}]}"); + + a = new TouchAction(driver) + .Press(element, 0.5, 75); + a.Perform(); + Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"press\",\"options\":{\"element\":\"5\",\"x\":0.5,\"y\":75}}]}"); + + a = new TouchAction(driver) + .Press(0.5, 75); + a.Perform(); + Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"press\",\"options\":{\"x\":0.5,\"y\":75}}]}"); + + a = new TouchAction(driver) + .Press(element); + a.Perform(); + Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"press\",\"options\":{\"element\":\"5\"}}]}"); + } + + [Test] + public void ReleaseTestCase() + { + IOSDriver driver = new IOSDriver(defaultUri, capabilities); + RequestProcessor re = setupTouchAction(); + ITouchAction a; + + a = new TouchAction(driver) + .Release(); + a.Perform(); + Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"release\"}]}"); + } + + [Test] + public void TapTestCase() + { + IOSDriver driver = new IOSDriver(defaultUri, capabilities); + RequestProcessor re = setupTouchAction(); + IWebElement element = driver.FindElementByIosUIAutomation(".elements()"); + + ITouchAction a; + + a = new TouchAction(driver) + .Tap(element, 50, 75); + a.Perform(); + Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"tap\",\"options\":{\"element\":\"5\",\"x\":50,\"y\":75}}]}"); + + a = new TouchAction(driver) + .Tap(element, 50, 75, 10); + a.Perform(); + Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"tap\",\"options\":{\"element\":\"5\",\"x\":50,\"y\":75,\"count\":10}}]}"); + + a = new TouchAction(driver) + .Tap(element, 0.5, 75); + a.Perform(); + Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"tap\",\"options\":{\"element\":\"5\",\"x\":0.5,\"y\":75}}]}"); + + a = new TouchAction(driver) + .Tap(0.5, 75); + a.Perform(); + Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"tap\",\"options\":{\"x\":0.5,\"y\":75}}]}"); + + a = new TouchAction(driver) + .Tap(0.5, 75, 10); + a.Perform(); + Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"tap\",\"options\":{\"x\":0.5,\"y\":75,\"count\":10}}]}"); + + a = new TouchAction(driver) + .Tap(element); + a.Perform(); + Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"tap\",\"options\":{\"element\":\"5\"}}]}"); + + a = new TouchAction(driver) + .Tap(element, count: 10); + a.Perform(); + Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"tap\",\"options\":{\"element\":\"5\",\"count\":10}}]}"); + + } + + [Test] + public void WaitTestCase() + { + IOSDriver driver = new IOSDriver(defaultUri, capabilities); + RequestProcessor re = setupTouchAction(); + ITouchAction a; + + a = new TouchAction(driver) + .Wait(1000); + a.Perform(); + Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"wait\",\"options\":{\"ms\":1000}}]}"); + + a = new TouchAction(driver) + .Wait(); + a.Perform(); + Assert.AreEqual(re.inputData, "{\"actions\":[{\"action\":\"wait\"}]}"); + } + + private RequestProcessor setupMultiAction() + { + server.respondTo("POST", "/element", new Dictionary {
 {"ELEMENT", '5'}
 }); + return server.respondTo("POST", "/touch/multi/perform", null); + } + + [Test] + public void MultiActionTestCase() + { + IOSDriver driver = new IOSDriver(defaultUri, capabilities); + RequestProcessor re = setupMultiAction(); + IWebElement element = driver.FindElementByIosUIAutomation(".elements()"); + + MultiAction m = new MultiAction(driver); + m.Perform(); + Assert.AreEqual(re.inputData, ""); + + TouchAction a1 = new TouchAction(); + a1 + .Press(element, 100, 100) + .Wait(1000) + .Release(); + m.Add(a1); + m.Perform(); + Assert.AreEqual(re.inputData, "{\"actions\":[[{\"action\":\"press\",\"options\":{\"element\":\"5\",\"x\":100,\"y\":100}},{\"action\":\"wait\",\"options\":{\"ms\":1000}},{\"action\":\"release\"}]]}"); + + TouchAction a2 = new TouchAction(); + a2 + .Tap(100, 100) + .MoveTo(element); + m.Add(a2); + m.Perform(); + Assert.AreEqual(re.inputData, "{\"actions\":[[{\"action\":\"press\",\"options\":{\"element\":\"5\",\"x\":100,\"y\":100}},{\"action\":\"wait\",\"options\":{\"ms\":1000}},{\"action\":\"release\"}],[{\"action\":\"tap\",\"options\":{\"x\":100,\"y\":100}},{\"action\":\"moveTo\",\"options\":{\"element\":\"5\"}}]]}"); + } + } }