Exemple #1
0
        public CalculatorAppPageObject Launch(string file = null)
        {
            if (CurrentApplication != null)
            {
                CloseCurrentApplication();
            }

            File = file;
            CurrentApplication = CalculatorAppPageObject.Launch(file);
            return(CurrentApplication);
        }
        public CalculatorAppPageObject Launch(string url = null, TargetBrowser targetBrowser = TargetBrowser.Undefined, int width = 0, int height = 0)
        {
            if (url == null)
            {
                url = TestContext?.Properties["baseUrl"]?.ToString();
                if (url == null)
                {
                    throw new ArgumentNullException("Invalid base url parameter detected in the test context");
                }
            }

            if (targetBrowser == TargetBrowser.Undefined)
            {
                if (!Enum.TryParse(TestContext?.Properties["targetBrowser"]?.ToString(), true, out targetBrowser))
                {
                    throw new ArgumentNullException("Invalid target browser parameter detected in the test context");
                }
            }

            if (width <= 0 || height <= 0)
            {
                if (!int.TryParse(TestContext?.Properties["resolutionWidth"].ToString(), out width))
                {
                    throw new ArgumentNullException("Invalid resolution width parameter detected in the test context");
                }

                if (!int.TryParse(TestContext?.Properties["resolutionHeight"].ToString(), out height))
                {
                    throw new ArgumentNullException("Invalid resolution height parameter detected in the test context");
                }
            }

            if (CurrentApplication != null)
            {
                CloseCurrentApplication();
            }

            this.BaseUrl            = url;
            this.CurrentApplication = CalculatorAppPageObject.Launch(url, targetBrowser, width, height);
            return(CurrentApplication);
        }
        public static CalculatorAppPageObject Launch(Uri appiumServerUrl = null, Dictionary <string, object> customCapabilities = null)
        {
            if (appiumServerUrl == null)
            {
                if (!Uri.TryCreate(TestContext?.Properties["Appium.Server.RemoteAddress"]?.ToString(), UriKind.RelativeOrAbsolute, out appiumServerUrl))
                {
                    throw new ArgumentNullException("Invalid appium server url detected in the test context");
                }
            }

            string capPrefix           = "Appium.Cap.";
            var    contextCapabilities = TestContext.Properties.Where(p => p.Key.StartsWith(capPrefix, true, CultureInfo.InvariantCulture))
                                         .ToDictionary(i => i.Key.Substring(capPrefix.Count()), i => i.Value);

            var appiumCapabilities = new Dictionary <string, object>();

            if (customCapabilities != null)
            {
                // merge appium capabilities from context and parameter
                customCapabilities.ToList().ForEach(x => appiumCapabilities.Add(x.Key, x.Value));
            }

            if (contextCapabilities != null)
            {
                // merge appium capabilities from context and parameter
                contextCapabilities.ToList().ForEach(x => appiumCapabilities.Add(x.Key, x.Value));
            }

            if (CurrentApplication != null)
            {
                CloseCurrentApplication();
            }

            CurrentApplication = CalculatorAppPageObject.Launch(appiumServerUrl, appiumCapabilities);

            return(CurrentApplication);
        }
 private static void CloseCurrentApplication()
 {
     CurrentApplication?.Quit();
     CurrentApplication = null;
 }
 private void CloseCurrentApplication()
 {
     this.CurrentApplication?.Close();
     this.CurrentApplication = null;
 }