Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        /// <summary>
        /// Soft assert method to check if the files are equal
        /// </summary>
        /// <param name="expectedText">Expected text</param>
        /// <param name="actualText">Actual text</param>
        /// <param name="softAssertName">Soft assert name</param>
        /// <param name="message">Exception message if desired</param>
        /// <returns>Boolean if the assert is true</returns>
        public override bool AreEqual(string expectedText, string actualText, string softAssertName, string message = "")
        {
            bool didPass = base.AreEqual(expectedText, actualText, softAssertName, message);

            if (!didPass && this.appiumTestObject.GetDriverManager <MobileDriverManager>().IsDriverIntialized())
            {
                if (AppiumConfig.GetSoftAssertScreenshot())
                {
                    AppiumUtilities.CaptureScreenshot(this.appiumTestObject.AppiumDriver, this.appiumTestObject, this.TextToAppend(softAssertName));
                }

                if (AppiumConfig.GetSavePagesourceOnFail())
                {
                    AppiumUtilities.SavePageSource(this.appiumTestObject.AppiumDriver, this.appiumTestObject, StringProcessor.SafeFormatter(" ({0})", this.NumberOfAsserts));
                }

                return(false);
            }
            else if (!didPass)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Get the mobile options
        /// </summary>
        /// <returns>The mobile options</returns>
        public static AppiumOptions GetDefaultMobileOptions()
        {
            AppiumOptions options = new AppiumOptions();

            options.AddAdditionalCapability(MobileCapabilityType.DeviceName, AppiumConfig.GetDeviceName());
            options.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, AppiumConfig.GetPlatformVersion());
            options.AddAdditionalCapability(MobileCapabilityType.PlatformName, AppiumConfig.GetPlatformName().ToUpper());
            options.SetMobileOptions(AppiumConfig.GetCapabilitiesAsObjects());

            return(options);
        }
Esempio n. 4
0
        /// <summary>
        /// Get the mobile options
        /// </summary>
        /// <returns>The mobile options</returns>
        public static AppiumOptions GetDefaultMobileOptions()
        {
            AppiumOptions options = new AppiumOptions();

            options.App             = AppiumConfig.GetApp();
            options.BrowserName     = AppiumConfig.GetBrowserName();
            options.BrowserVersion  = AppiumConfig.GetBrowserVersion();
            options.DeviceName      = AppiumConfig.GetDeviceName();
            options.PlatformVersion = AppiumConfig.GetPlatformVersion();
            options.PlatformName    = AppiumConfig.GetPlatformName().ToUpper();
            options.SetMobileOptions(AppiumConfig.GetCapabilitiesAsObjects());

            return(options);
        }
Esempio n. 5
0
        /// <summary>
        /// Soft assert method to check if the Action is false
        /// </summary>
        /// <param name="assertFunction">Function to use</param>
        /// <param name="failureMessage">Message to log</param>
        /// <param name="assertName">Soft assert name or name of expected assert being called.</param>
        /// <returns>Boolean of the assert</returns>
        public override bool Assert(Action assertFunction, string assertName, string failureMessage = "")
        {
            bool didPass = base.Assert(assertFunction, assertName, failureMessage);

            if (!didPass && this.appiumTestObject.GetDriverManager <AppiumDriverManager>().IsDriverIntialized())
            {
                if (AppiumConfig.GetSoftAssertScreenshot())
                {
                    AppiumUtilities.CaptureScreenshot(this.appiumTestObject.AppiumDriver, this.appiumTestObject, this.TextToAppend(assertName));
                }

                if (AppiumConfig.GetSavePagesourceOnFail())
                {
                    AppiumUtilities.SavePageSource(this.appiumTestObject.AppiumDriver, this.appiumTestObject, $" ({ this.NumberOfAsserts})");
                }

                return(false);
            }
            return(didPass);
        }
Esempio n. 6
0
        /// <summary>
        /// Take a screen shot if needed and tear down the appium driver
        /// </summary>
        /// <param name="resultType">The test result</param>
        protected override void BeforeLoggingTeardown(TestResultType resultType)
        {
            try
            {
                // Captures screenshot if test result is not a pass and logging is enabled
                if (this.TestObject.GetDriverManager <MobileDriverManager>().IsDriverIntialized() && this.Log is FileLogger && resultType != TestResultType.PASS &&
                    this.LoggingEnabledSetting != LoggingEnabled.NO)
                {
                    AppiumUtilities.CaptureScreenshot(this.AppiumDriver, this.TestObject);

                    if (AppiumConfig.GetSavePagesourceOnFail())
                    {
                        AppiumUtilities.SavePageSource(this.AppiumDriver, this.TestObject, "FinalPageSource");
                    }
                }
            }
            catch (Exception exception)
            {
                this.TryToLog(MessageType.WARNING, "Failed to get screen shot because: {0}", exception.Message);
            }
        }
Esempio n. 7
0
        /// <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);
        }
Esempio n. 8
0
 /// <summary>
 /// Get the wait default wait driver
 /// </summary>
 /// <param name="driver">Brings in an AppiumDriver</param>
 /// <returns>An WebDriverWait</returns>
 public static WebDriverWait GetDefaultWaitDriver(AppiumDriver <IWebElement> driver)
 {
     return(GetWaitDriver(driver, AppiumConfig.GetMobileTimeout(), AppiumConfig.GetMobileWaitTime()));
 }
Esempio n. 9
0
 /// <summary>
 /// Get the default Appium driver based on the test run configuration
 /// </summary>
 /// <returns>An AppiumDriver</returns>
 public static AppiumDriver GetDefaultMobileDriver()
 {
     return(GetDefaultMobileDriver(AppiumConfig.GetDeviceType()));
 }
Esempio n. 10
0
 /// <summary>
 /// Set the script and page timeouts
 /// </summary>
 /// <param name="driver">Brings in an AppiumDriver</param>
 public static void SetDefaultTimeouts(this AppiumDriver driver)
 {
     driver.SetTimeouts(AppiumConfig.GetMobileTimeout());
 }