コード例 #1
0
ファイル: AppiumDriverFactory.cs プロジェクト: row49382/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 <IWebElement> GetDefaultMobileDriver(PlatformType deviceType)
        {
            AppiumDriver <IWebElement> appiumDriver;

            Uri           mobileHub = AppiumConfig.GetMobileHubUrl();
            TimeSpan      timeout   = AppiumConfig.GetCommandTimeout();
            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(StringProcessor.SafeFormatter("Mobile OS type '{0}' is not supported", deviceType));
            }

            // Windows automation does not support setting the associated timeouts
            if (deviceType != PlatformType.Windows)
            {
                appiumDriver.SetDefaultTimeouts();
            }

            return(appiumDriver);
        }
コード例 #2
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);
        }