コード例 #1
0
        /// <summary>
        /// Adds/merges server-specific capabilities
        /// </summary>
        /// <param name="options">is an instance of OpenQA.Selenium.Remote.AppiumOptions</param>
        /// <returns>the self-reference</returns>
        public OptionCollector AddCapabilities(AppiumOptions options)
        {
            if (this.options == null)
            {
                this.options = options;
            }
            else
            {
                Dictionary <string, object> originalDictionary = this.options.ToDictionary();
                Dictionary <string, object> givenDictionary    = options.ToDictionary();
                Dictionary <string, object> result             = new Dictionary <string, object>(originalDictionary);

                foreach (var item in givenDictionary)
                {
                    if (originalDictionary.ContainsKey(item.Key))
                    {
                        result[item.Key] = item.Value;
                    }
                    else
                    {
                        result.Add(item.Key, item.Value);
                    }
                }

                this.options = new AppiumOptions();

                foreach (var item in result)
                {
                    this.options.AddAdditionalCapability(item.Key, item.Value);
                }
            }

            return(this);
        }
コード例 #2
0
 /// <summary>
 /// Set additional capabilities on driver
 /// </summary>
 /// <param name="additionalCapability">key value pair for additional capabilities.</param>
 internal void SetAdditionalOptions(Dictionary <string, object> additionalCapability = null)
 {
     if (additionalCapability != null && additionalCapability.Count > 0)
     {
         //Log Section
         TestLogs.WriteLogSection("Test Specific Capabilities",
                                  () => {
             foreach (KeyValuePair <string, object> capability in additionalCapability)
             {
                 LogOverrideSetCapability(capability, options.ToDictionary());
                 options.AddAdditionalCapability(capability.Key, capability.Value);
             }
         });
     }
 }
コード例 #3
0
        private static AppiumOptions AddAdditionalOptions(AppiumOptions options, string key, string value)
        {
            if (!options.ToDictionary().ContainsKey(key))
            {
                options.AddAdditionalCapability(key, value);
            }

            return(options);
        }
コード例 #4
0
ファイル: AppiumDriverFactory.cs プロジェクト: Magenic/MAQS
        /// <summary>
        /// Get the default Appium driver based on the test run configuration
        /// </summary>
        /// <param name="deviceType">The platform type we want to use</param>
        /// <returns>An AppiumDriver</returns>
        public static AppiumDriver GetDefaultMobileDriver(PlatformType deviceType)
        {
            AppiumDriver appiumDriver;

            Uri           mobileHub = AppiumConfig.GetMobileHubUrl();
            TimeSpan      timeout   = AppiumConfig.GetMobileCommandTimeout();
            AppiumOptions options   = GetDefaultMobileOptions();

            switch (deviceType)
            {
            case PlatformType.Android:
                appiumDriver = GetAndroidDriver(mobileHub, options, timeout);
                break;

            case PlatformType.iOS:
                appiumDriver = GetIOSDriver(mobileHub, options, timeout);
                break;

            case PlatformType.Windows:
                appiumDriver = GetWindowsDriver(mobileHub, options, timeout);
                break;

            default:
                throw new ArgumentException($"Mobile OS type '{deviceType}' is not supported");
            }

            // Check options to see if we are doing browser or app tests
            var  allOption      = options.ToDictionary();
            bool hasBrowserName = allOption.Any(kvp => kvp.Key.ToLower().Contains("browsername"));
            bool hasApp         = allOption.Any(kvp => kvp.Key.ToLower().Contains("app"));
            bool hasBundleId    = allOption.Any(kvp => kvp.Key.ToLower().Contains("bundleid"));

            // Only browser automation supports setting the associated timeouts
            if (hasBrowserName && !(hasApp || hasBundleId))
            {
                appiumDriver.SetDefaultTimeouts();
            }

            return(appiumDriver);
        }