public IElement FindFirst(IElement context, LocatorStrategy strategy, string locator) { AutomationProperty property = this.ToAutomationProperty(strategy); AutomationElement element = null; switch (strategy) { case LocatorStrategy.Id: case LocatorStrategy.Name: case LocatorStrategy.ClassName: element = context.AutomationElement.FindFirst( TreeScope.Descendants, new PropertyCondition(property, locator)); break; case LocatorStrategy.TagName: ControlType type = this.uiAutomation.FromTagName(locator); element = context.AutomationElement.FindFirst( TreeScope.Descendants, new PropertyCondition(property, type)); break; case LocatorStrategy.XPath: element = this.uiAutomation.FindFirstByXPath(context.AutomationElement, locator); break; default: throw new FailedCommandException( string.Format("Usupported locator startegy: {0}", strategy.ToString()), 32); // InvalidSelector (32) } return element == null ? null : this.elementFactory.GetElement(element); }
public void TestMethodMain() { /*APPIUM config*/ _capabilities.SetCapability("platformName", ProjectConfig.PlataformName); _capabilities.SetCapability("platformVersion", ProjectConfig.PlatformVersion); _capabilities.SetCapability("deviceName", ProjectConfig.DeviceName); _capabilities.SetCapability("appPackage", ProjectConfig.AppPackage); _capabilities.SetCapability("newCommandTimeout", "3000"); _capabilities.SetCapability("sessionOverride", "true"); Uri defaultUri = new Uri(ProjectConfig.AppiumServer); if (ProjectConfig.PlataformName == "Android") { _capabilities.SetCapability("app", ProjectConfig.AppPath); _capabilities.SetCapability("appActivity", ProjectConfig.AppActivity); _driver = new AndroidDriver <IWebElement>(defaultUri, _capabilities, TimeSpan.FromSeconds(3000)); } else if (ProjectConfig.PlataformName == "iOS") { _capabilities.SetCapability("automationName", "XCUITest"); _capabilities.SetCapability("app", ProjectConfig.AppPath); _capabilities.SetCapability("bundleId", ProjectConfig.AppPackage); _capabilities.SetCapability("udid", ProjectConfig.Uuid); _driver = new IOSDriver <IWebElement>(defaultUri, _capabilities, TimeSpan.FromSeconds(3000)); } System.Threading.Thread.Sleep(8000); Exec.Create("MovieApp", ProjectConfig.OutputDeviceID, "F3", 1, "IndividualExpressionAncestorIndex", ProjectConfig.OutputPath); Exec.Instance.Start(); _locator = new LocatorStrategy(_driver, Exec.Instance); /*initialing test*/ ScrollToBottom(); btnTopRatedSendClick_Test(); //btnTopRated Exec.Instance.EndSuccefull(); }
public void TestMethodMain() { /*APPIUM config*/ _capabilities.SetCapability("platformName", ProjectConfig.PlataformName); _capabilities.SetCapability("platformVersion", ProjectConfig.PlatformVersion); _capabilities.SetCapability("deviceName", ProjectConfig.DeviceName); _capabilities.SetCapability("appPackage", ProjectConfig.AppPackage); _capabilities.SetCapability("newCommandTimeout", "3000"); _capabilities.SetCapability("sessionOverride", "true"); Uri defaultUri = new Uri(ProjectConfig.AppiumServer); if (ProjectConfig.PlataformName == "Android") { _capabilities.SetCapability("app", ProjectConfig.AppPath); _capabilities.SetCapability("appActivity", ProjectConfig.AppActivity); _driver = new AndroidDriver <IWebElement>(defaultUri, _capabilities, TimeSpan.FromSeconds(3000)); } else if (ProjectConfig.PlataformName == "iOS") { _capabilities.SetCapability("app", ProjectConfig.AppPath); _capabilities.SetCapability("bundleId", ProjectConfig.AppPackage); _capabilities.SetCapability("udid", ProjectConfig.Uuid); _driver = new IOSDriver <IWebElement>(defaultUri, _capabilities, TimeSpan.FromSeconds(3000)); } Exec.Create("Tasky", ProjectConfig.OutputDeviceID, "F3", 3, "CombinedExpressionsMultiLocator", ProjectConfig.OutputPath); Exec.Instance.Start(); _locator = new LocatorStrategy(_driver, Exec.Instance); /*initialing test*/ btnaddSendClick_Test(); //btnadd inserirnomeSendKeys_Test(); //inserirnome btndeleteSendClick_Test(); //btndelete Exec.Instance.EndSuccefull(); }
public void TestMethodMain() { /*APPIUM config*/ _capabilities.SetCapability("platformName", ProjectConfig.PlataformName); _capabilities.SetCapability("platformVersion", ProjectConfig.PlatformVersion); _capabilities.SetCapability("deviceName", ProjectConfig.DeviceName); _capabilities.SetCapability("appPackage", ProjectConfig.AppPackage); _capabilities.SetCapability("newCommandTimeout", "3000"); _capabilities.SetCapability("sessionOverride", "true"); Uri defaultUri = new Uri(ProjectConfig.AppiumServer); if (ProjectConfig.PlataformName == "Android") { _capabilities.SetCapability("app", ProjectConfig.AppPath); _driver = new AndroidDriver <IWebElement>(defaultUri, _capabilities, TimeSpan.FromSeconds(3000)); } else if (ProjectConfig.PlataformName == "iOS") { _capabilities.SetCapability("app", ProjectConfig.AppPath); _capabilities.SetCapability("bundleId", ProjectConfig.AppPackage); _capabilities.SetCapability("udid", ProjectConfig.Uuid); _driver = new IOSDriver <IWebElement>(defaultUri, _capabilities, TimeSpan.FromSeconds(3000)); } Exec.Create("FFF", ProjectConfig.OutputDeviceID, "F1", 5, "IndividualExpressionIdentifyAttributes", ProjectConfig.OutputPath); Exec.Instance.Start(); _locator = new LocatorStrategy(_driver, Exec.Instance); /*initialing test*/ btnsearchSendClick_Test(); //btnsearch tpproductSendClick_Test(); //tpproduct tppaymentSendClick_Test(); //tppayment btnsearch2SendClick_Test(); //btnsearch2 mktSendClick_Test(); //mkt Exec.Instance.EndSuccefull(); }
private LocatorStrategy LocatorStrategyFromCss(LocatorStrategy locatorStrategy, string locator) { var firstChar = locator.First(); if (locatorStrategy == LocatorStrategy.Css) { if (firstChar == '#') { return(LocatorStrategy.Id); } if (firstChar == '.') { return(LocatorStrategy.Class); } } return(locatorStrategy); }
/// <summary> /// Locate elements by locatorStrategy and locator string. /// </summary> /// <param name="locatorStrategy">How will elements be found?</param> /// <param name="locator">String to locate elements based on the provided locationStrategy.</param> /// <returns></returns> public List <Element> Elements(LocatorStrategy locatorStrategy, string locator) { var elementsList = new List <Element>(); try { var elements = Driver.WebDriver.FindElements(Element(locatorStrategy, locator)); foreach (var element in elements) { elementsList.Add(new Element(element, LogManager, locator, locatorStrategy)); } } catch (Exception e) { Driver.LogManager.Error(e.Message); } return(elementsList); }
public IList <IElement> FindAll(IElement context, LocatorStrategy strategy, string locator) { AutomationProperty property = this.ToAutomationProperty(strategy); IEnumerable elements = null; switch (strategy) { case LocatorStrategy.Id: case LocatorStrategy.Name: case LocatorStrategy.ClassName: elements = context.AutomationElement.FindAll( TreeScope.Descendants, new PropertyCondition(property, locator)); break; case LocatorStrategy.TagName: ControlType type = this.uiAutomation.FromTagName(locator); elements = context.AutomationElement.FindAll( TreeScope.Descendants, new PropertyCondition(property, type)); break; case LocatorStrategy.XPath: elements = this.uiAutomation.FindAllByXPath(context.AutomationElement, locator); break; default: throw new FailedCommandException( string.Format("Usupported locator startegy: {0}", strategy.ToString()), 32); // InvalidSelector (32) } var results = new List <IElement>(); foreach (var element in elements) { results.Add(this.elementFactory.GetElement((AutomationElement)element)); } return(results); }
public IList<IElement> FindAll(IElement context, LocatorStrategy strategy, string locator) { AutomationProperty property = this.ToAutomationProperty(strategy); IEnumerable elements = null; switch (strategy) { case LocatorStrategy.Id: case LocatorStrategy.Name: case LocatorStrategy.ClassName: elements = context.AutomationElement.FindAll( TreeScope.Descendants, new PropertyCondition(property, locator)); break; case LocatorStrategy.TagName: ControlType type = this.uiAutomation.FromTagName(locator); elements = context.AutomationElement.FindAll( TreeScope.Descendants, new PropertyCondition(property, type)); break; case LocatorStrategy.XPath: elements = this.uiAutomation.FindAllByXPath(context.AutomationElement, locator); break; default: throw new FailedCommandException( string.Format("Usupported locator startegy: {0}", strategy.ToString()), 32); // InvalidSelector (32) } var results = new List<IElement>(); foreach (var element in elements) { results.Add(this.elementFactory.GetElement((AutomationElement)element)); } return results; }
private AutomationProperty ToAutomationProperty(LocatorStrategy strategy) { switch (strategy) { case LocatorStrategy.Name: return AutomationElement.NameProperty; case LocatorStrategy.TagName: return AutomationElement.ControlTypeProperty; case LocatorStrategy.ClassName: return AutomationElement.ClassNameProperty; default: return AutomationElement.AutomationIdProperty; } }
private string ElementsBorderScript(LocatorStrategy locatorStrategy, string locator, string color) => "{\n var x = document." + $"{GetLocatorStrategyForJsScript(locatorStrategy)}" + "(\"" + $"{locator}\");\n var i;\n for (i = 0; i < x.length; i++) " + "{\n " + "x[i].style.borderColor = \"" + $"{color}" + "\";\n }\n}";
private string ElementBorderScript(LocatorStrategy locatorStrategy, string locator, string color) => $"document.{GetLocatorStrategyForJsScript(locatorStrategy)}(\"{locator}\").style.borderColor = \"{color}\"";
/// <summary> /// Create an Element which can interact with web applications. /// </summary> /// <param name="element">Requested element.</param> /// <param name="logManager"><see cref="Logger.LogManager"/></param> /// <param name="locatorString">Locator string used to find the requested element.</param> /// <param name="locatorType">Type of locator used to find the requested element.</param> internal Element(IWebElement element, LogManager logManager, string locatorString = "", LocatorStrategy locatorType = 0) : this() { WebElement = element; LogManager = logManager; if (!string.IsNullOrEmpty(locatorString) && locatorType != 0) { Information.LocatorString = locatorString; Information.LocatorStrategy = locatorType; } IsInitialized = true; }
/// <summary> /// Find child element with the given locatorStrategy and locator string. /// </summary> /// <param name="element">Parent element to find a child of.</param> /// <param name="locatorStrategy">How will the element be found.</param> /// <param name="locator">String to locate child elements.</param> /// <returns></returns> public static Element FindElement(this Element element, LocatorStrategy locatorStrategy, string locator) => FindElements(element, locatorStrategy, locator)[0];
/// <summary> /// Find child elements with the given locatorStrategy and locator string. /// </summary> /// <param name="element">Parent element to find children of.</param> /// <param name="locatorStrategy">How will the element be found?</param> /// <param name="locator">String to locate child elements.</param> /// <returns></returns> public static List <Element> FindElements(this Element element, LocatorStrategy locatorStrategy, string locator) => element.FindElements(SeleniumFind.Element(locatorStrategy, locator));