//Licensed under the Apache License, Version 2.0 (the "License"); //you may not use this file except in compliance with the License. //See the NOTICE file distributed with this work for additional //information regarding copyright ownership. //You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // //Unless required by applicable law or agreed to in writing, software //distributed under the License is distributed on an "AS IS" BASIS, //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //See the License for the specific language governing permissions and //limitations under the License. using OpenQA.Selenium.Appium.Enums; using OpenQA.Selenium.Appium.Interfaces; using OpenQA.Selenium.Appium.Service; using OpenQA.Selenium.Remote; using System; using System.Drawing; using OpenQA.Selenium.Appium.iOS.Interfaces; using System.Collections.Generic; namespace OpenQA.Selenium.Appium.iOS { public class IOSDriver : AppiumDriver, IFindByIosUIAutomation, IFindsByIosClassChain, IFindsByIosNSPredicate, IHidesKeyboardWithKeyName, IHasClipboard, IShakesDevice, IPerformsTouchID, IHasSettings where W : IWebElement { private static readonly string Platform = MobilePlatform.IOS; /// /// Initializes a new instance of the IOSDriver class /// /// An object which executes commands for the driver. /// An object containing the Appium options. public IOSDriver(ICommandExecutor commandExecutor, DriverOptions driverOptions) : base(commandExecutor, SetPlatformToCapabilities(driverOptions, Platform)) { } /// /// Initializes a new instance of the IOSDriver class using Appium options /// /// An object containing the Appium options of the browser. public IOSDriver(DriverOptions driverOptions) : base(SetPlatformToCapabilities(driverOptions, Platform)) { } /// /// Initializes a new instance of the IOSDriver class using Appium options and command timeout /// /// An object containing the Appium options. /// The maximum amount of time to wait for each command. public IOSDriver(DriverOptions driverOptions, TimeSpan commandTimeout) : base(SetPlatformToCapabilities(driverOptions, Platform), commandTimeout) { } /// /// Initializes a new instance of the IOSDriver class using the AppiumServiceBuilder instance and Appium options /// /// object containing settings of the Appium local service which is going to be started /// An object containing the Appium options. public IOSDriver(AppiumServiceBuilder builder, DriverOptions driverOptions) : base(builder, SetPlatformToCapabilities(driverOptions, Platform)) { } /// /// Initializes a new instance of the IOSDriver class using the AppiumServiceBuilder instance, Appium options and command timeout /// /// object containing settings of the Appium local service which is going to be started /// An object containing the Appium options. /// The maximum amount of time to wait for each command. public IOSDriver(AppiumServiceBuilder builder, DriverOptions driverOptions, TimeSpan commandTimeout) : base(builder, SetPlatformToCapabilities(driverOptions, Platform), commandTimeout) { } /// /// Initializes a new instance of the IOSDriver class using the specified remote address and Appium options /// /// URI containing the address of the WebDriver remote server (e.g. http://127.0.0.1:4723/wd/hub). /// An object containing the Appium options. public IOSDriver(Uri remoteAddress, DriverOptions driverOptions) : base(remoteAddress, SetPlatformToCapabilities(driverOptions, Platform)) { } /// /// Initializes a new instance of the IOSDriver class using the specified Appium local service and Appium options /// /// the specified Appium local service /// An object containing the Appium options of the browser. public IOSDriver(AppiumLocalService service, DriverOptions driverOptions) : base(service, SetPlatformToCapabilities(driverOptions, Platform)) { } /// /// Initializes a new instance of the IOSDriver class using the specified remote address, Appium options, and command timeout. /// /// URI containing the address of the WebDriver remote server (e.g. http://127.0.0.1:4723/wd/hub). /// An object containing the Appium options. /// The maximum amount of time to wait for each command. public IOSDriver(Uri remoteAddress, DriverOptions driverOptions, TimeSpan commandTimeout) : base(remoteAddress, SetPlatformToCapabilities(driverOptions, Platform), commandTimeout) { } /// /// Initializes a new instance of the IOSDriver class using the specified Appium local service, Appium options, and command timeout. /// /// the specified Appium local service /// An object containing the Appium options. /// The maximum amount of time to wait for each command. public IOSDriver(AppiumLocalService service, DriverOptions driverOptions, TimeSpan commandTimeout) : base(service, SetPlatformToCapabilities(driverOptions, Platform), commandTimeout) { } #region IFindByIosUIAutomation Members public W FindElementByIosUIAutomation(string selector) => FindElement(MobileSelector.iOSAutomatoion, selector); public IReadOnlyCollection FindElementsByIosUIAutomation(string selector) => FindElements(MobileSelector.iOSAutomatoion, selector); #endregion IFindByIosUIAutomation Members #region IFindsByIosClassChain Members public W FindElementByIosClassChain(string selector) => FindElement(MobileSelector.iOSClassChain, selector); public IReadOnlyCollection FindElementsByIosClassChain(string selector) => FindElements(MobileSelector.iOSClassChain, selector); #endregion IFindsByIosClassChain Members #region IFindsByIosNSPredicate Members public W FindElementByIosNsPredicate(string selector) => FindElement(MobileSelector.iOSPredicateString, selector); public IReadOnlyCollection FindElementsByIosNsPredicate(string selector) => FindElements(MobileSelector.iOSPredicateString, selector); #endregion IFindsByIosNSPredicate Members public void SetSetting(string setting, object value) => IOSCommandExecutionHelper.SetSetting(this, setting, value); public Dictionary Settings { get => IOSCommandExecutionHelper.GetSettings(this); set { foreach (var entry in value) { SetSetting(entry.Key, entry.Value); } } } public void ShakeDevice() => IOSCommandExecutionHelper.ShakeDevice(this); public void HideKeyboard(string key, string strategy = null) => AppiumCommandExecutionHelper.HideKeyboard(this, strategy, key); protected override RemoteWebElementFactory CreateElementFactory() => new IOSElementFactory(this); /// /// Locks the device. /// /// The number of seconds during which the device need to be locked for. public void Lock(int seconds) => AppiumCommandExecutionHelper.Lock(this, seconds); public void PerformTouchID(bool match) => IOSCommandExecutionHelper.PerformTouchID(this, match); public bool IsLocked() => IOSCommandExecutionHelper.IsLocked(this); public void Unlock() => IOSCommandExecutionHelper.Unlock(this); public void Lock() => IOSCommandExecutionHelper.Lock(this); /// /// Sets the content to the clipboard /// /// /// public void SetClipboard(ClipboardContentType contentType, string base64Content) => AppiumCommandExecutionHelper.SetClipboard(this, contentType, base64Content); /// /// Get the content of the clipboard. /// /// /// Android supports plaintext only /// The content of the clipboard as base64-encoded string or an empty string if the clipboard is empty public string GetClipboard(ClipboardContentType contentType) => AppiumCommandExecutionHelper.GetClipboard(this, contentType); /// /// Sets text to the clipboard /// /// /// For Android only - A user visible label for the clipboard content. public void SetClipboardText(string textContent, string label = null) => AppiumCommandExecutionHelper.SetClipboardText(this, textContent, null); /// /// Get the plaintext content of the clipboard. /// /// Android supports plaintext only /// The string content of the clipboard or an empty string if the clipboard is empty public string GetClipboardText() => AppiumCommandExecutionHelper.GetClipboardText(this); /// /// Sets the url string to the clipboard /// /// public void SetClipboardUrl(string url) => IOSCommandExecutionHelper.SetClipboardUrl(this, url); /// /// Gets the url string from the clipboard /// /// The url string content of the clipboard or an empty string if the clipboard is empty public string GetClipboardUrl() => IOSCommandExecutionHelper.GetClipboardUrl(this); /// /// Sets the image to the clipboard /// /// public void SetClipboardImage(Image image) => IOSCommandExecutionHelper.SetClipboardImage(this, image); /// /// Gets the image from the clipboard /// /// The image content of the clipboard as an Image object or null if there is no image on the clipboard public Image GetClipboardImage() => IOSCommandExecutionHelper.GetClipboardImage(this); } }