// ************ DATE 10/16/2020 ************ // In charge of the instantiation of multi Action functions // ************ --------------- ************ #region MULTI ACTION FUNCTIONS #region PRESS ACTIONS public static void MultiPressByClassName(string className, int duration = 0) { var multiAction = BuildMultiAction(); var position = 0; try { var elements = GetControl.CollectionByClass(className); var actions = BuildActions(elements.Count()); //Create the press actions for every element found foreach (var elem in elements) { actions[position].Press(elem).Wait(duration).Release(); position++; } //add every action created before for (int i = 0; i < position; i++) { multiAction.Add(actions[i]); } multiAction.Perform(); } catch (Exception ex) { Assert.Fail("MultiPressByClassName threw an exception: " + ex.Message); } }
public static void Title(string className, string text, bool isBold = true) { try { var elements = GetControl.CollectionByClass(className); foreach (var elem in elements) { if (isBold) { // && elem.GetCssValue("font-weight").ToLower().Equals("bold") if (elem.Text.Equals(text)) { return; } } else { if (elem.Text.Equals(text)) { return; } } } Assert.Fail("The text was not found or isn't bold"); } catch (Exception ex) { Assert.Fail("VerifyTitle threw an exception: " + ex.Message); } }
public Head() { Position = Settings.DefaultHeadPosition; PreviousPosition = Position; Manager.Add(this); Manager.SetHead(this); CurrentWay = GetControl.GetCurrent(); }
// ************ DATE 10/16/2020 ************ // All the possible Selectors to search for a single element till date. // ************ --------------- ************ #region USING SINGLE SELECTORS /// <summary> /// Finds the first element in the screen that matches the UiAutomator criteria using a UiSelector and click it. /// </summary> /// <param name="selector"> Represents the Enum in Share class </param> /// <param name="value"> the boolean value of an element to be found </param> /// <param name="position"> position of an object on the layout hierarchy </param> public static void ByUiAutomatorSingleSelector(Share.Selector selector, bool value, int position = 0) { try { var element = GetControl.ByUiAutomatorSingleSelector(selector, value, position); element.Click(); } catch (Exception ex) { Assert.Fail("ClickByUiAutomatorSingleSelector threw an exception: " + ex.Message); } }
/// <summary> /// Finds the first element in the screen that matches the UiAutomator criteria using a Parent UiSelector and click it. /// </summary> /// <param name="selector"> Represents the Enum in Share class </param> /// <param name="text"> the partial/complete text of an element to be found </param> /// <param name="position"> position of an object on the layout hierarchy </param> public static void ByUiAutomatorParentSelector(Share.Selector selector, string text, int position = 0) { try { var element = GetControl.ByUiAutomatorParentSelector(selector, text, position); element.Click(); } catch (Exception ex) { Assert.Fail("ClickByUiAutomatorParentSelector threw an exception: " + ex.Message); } }
// ************ DATE 10/16/2020 ************ // ***** IMPORTANT: All Click by ID will search an element and then click it. // ************ --------------- ************ #region BY ID /// <summary> /// Finds the first element in the screen that matches the id criteria and then click it. /// </summary> /// <param name="id">Id to find the object</param> public static void ById(string id) { try { AppiumWebElement element = GetControl.ById(id); element.Click(); } catch (Exception ex) { Assert.Fail("ClickById threw an exception: " + ex.Message); } }
// ************ DATE 10/16/2020 ************ // ***** IMPORTANT: All Click by CLASSNAME will search an element and then click it. // ************ --------------- ************ #region BY CLASSNAME /// <summary> /// Finds the first element in the screen that matches the className criteria and clicks it. /// </summary> /// <param name="className">ClassName to find the object</param> public static void ByClassName(string className) { try { var element = GetControl.ByClass(className); element.Click(); } catch (Exception ex) { Assert.Fail("ClickByClassName threw an exception: " + ex.Message); } }
// ************ DATE 10/16/2020 ************ // ***** IMPORTANT: All Click by XPATH will search an element and then click it. // ************ --------------- ************ #region BY XPATH /// <summary> /// Finds the first element in the screen that matches the xPath criteria and then click it. /// </summary> /// <param name="position">Position to match a specific element</param> /// <param name="elem">Represents the Enum in Share class</param> /// <param name="widget">boolean if this is a widget</param> public static void ByXPath(int position, Share.Element elem = Share.Element.EditText, bool widget = true) { try { AppiumWebElement element = GetControl.ByXPath(position, elem, widget); element.Click(); } catch (Exception ex) { Assert.Fail("ClickByXPath threw an exception: " + ex.Message); } }
// ************ DATE 10/16/2020 ************ // ***** IMPORTANT: All Click by UIAUTOMATOR will search an element and then click it. // ************ --------------- ************ #region BY UIAUTOMATOR /// <summary> /// Finds the first element in the screen that matches the UiAutomator criteria and click it. /// </summary> /// <param name="attribute">All the possible attributes that an element has, like text</param> /// <param name="value">The value to match with the attribute</param> public static void ByUiAutomator(string attribute, string value) { try { var element = GetControl.ByUiAutomator(attribute, value); element.Click(); } catch (Exception ex) { Assert.Fail("ClickByUiAutomator threw an exception: " + ex.Message); } }
/// <summary> /// Finds the first element in the screen that matches the id criteria and then simulates typing text into the element. /// </summary> /// <param name="id">Id to find the object</param> /// <param name="text">Text to match a specific element</param> /// <param name="inputText">The text to type into the element.</param> public static void ById(string id, string text, string inputText) { try { var element = GetControl.ById(id, text); element.Clear(); element.SendKeys(inputText); } catch (Exception ex) { Assert.Fail("InputById threw an exception: " + ex.Message); } }
// ************ DATE 10/16/2020 ************ // All the possible Selectors to search for a child element till date. // ************ --------------- ************ #region USING CHILD SELECTORS /// <summary> /// Finds the first element in the screen that matches the UiAutomator criteria using a Child UiSelector and then simulates typing text into the element. /// </summary> /// <param name="inputText">The text to type into the element.</param> /// <param name="selector"> Represents the Enum in Share class </param> /// <param name="value"> the boolean value of an element to be found </param> /// <param name="text"> text to found the element</param> /// <param name="position"> position of an object on the layout hierarchy </param> public static void ByUiAutomatorChildSelector(string inputText, Share.Selector selector, bool value, string text, int position = 0) { try { var element = GetControl.ByUiAutomatorChildSelector(selector, value, position); element.Clear(); element.Click(); } catch (Exception ex) { Assert.Fail("InputByUiAutomatorChildSelector threw an exception: " + ex.Message); } }
// ************ DATE 10/16/2020 ************ // ***** IMPORTANT: All Input by CLASSNAME will search an element and then simulates typing text into the element. // ************ --------------- ************ #region BY CLASSNAME /// <summary> /// Finds the first element in the screen that matches the className criteria and then simulates typing text into the element. /// </summary> /// <param name="className">ClassName to find the object</param> /// <param name="inputText">The text to type into the element.</param> public static void ByClassName(string className, string inputText) { try { var element = GetControl.ByClass(className); element.Clear(); element.SendKeys(inputText); } catch (Exception ex) { Assert.Fail("InputByClassName threw an exception: " + ex.Message); } }
// ************ DATE 10/16/2020 ************ // ***** IMPORTANT: All Input by UIAUTOMATOR will search an element and then simulates typing text into the element. // ************ --------------- ************ #region BY UIAUTOMATOR /// <summary> /// Finds the first element in the screen that matches the UiAutomator criteria and then simulates typing text into the element. /// </summary> /// <param name="inputText">The text to type into the element.</param> /// <param name="attribute">All the possible attributes that an element has, like text</param> /// <param name="value">The value to match with the attribute</param> public static void ByUiAutomator(string inputText, string attribute, string value) { try { var element = GetControl.ByUiAutomator(attribute, value); element.Clear(); element.SendKeys(inputText); } catch (Exception ex) { Assert.Fail("InputByUiAutomator threw an exception: " + ex.Message); } }
/// <summary> /// Finds the first element in the screen that matches the UiAutomator criteria using a Parent UiSelector and then simulates typing text into the element. /// </summary> /// <param name="inputText">The text to type into the element.</param> /// <param name="selector"> Represents the Enum in Share class </param> /// <param name="text"> the partial/complete text of an element to be found </param> /// <param name="position"> position of an object on the layout hierarchy </param> public static void ByUiAutomatorParentSelector(string inputText, Share.Selector selector, string text, int position = 0) { try { var element = GetControl.ByUiAutomatorParentSelector(selector, text, position); element.Clear(); element.SendKeys(inputText); } catch (Exception ex) { Assert.Fail("InputByUiAutomatorParentSelector threw an exception: " + ex.Message); } }
/// <summary> /// LongPress over a specific element that will be found using it's classname. /// </summary> /// <param name="className"> classname of the element to be found </param> /// <param name="duration"> time to wait until swipe to position </param> public static void LongPressByClassName(string className, int duration = 1) { ITouchAction action = BuildSingleAction(); try { AppiumWebElement element = GetControl.ByClass(className); action.LongPress(element).Wait(duration).Release().Perform(); } catch (Exception ex) { Assert.Fail("PressByClassName threw an exception: " + ex.Message); } }
/// <summary> /// Moves to a specific position of an element that will be found using it's classname /// </summary> /// <param name="className"> classname of the element to be found </param> /// <param name="x"> value to move on X axis </param> /// <param name="y"> value to move on Y axis </param> public static void MoveToByClassName(string className, int x, int y) { ITouchAction action = BuildSingleAction(); try { AppiumWebElement scrollView = GetControl.ByClass(className); action.MoveTo(scrollView, x, y).Perform(); } catch (Exception ex) { Assert.Fail("MoveToByClassName threw an exception: " + ex.Message); } }
/// <summary> /// Tap over a specific element that will be found using it's classname /// </summary> /// <param name="className"> classname of the element to be found </param> /// <param name="x"> value to move on X axis </param> /// <param name="y"> value to move on Y axis </param> /// <param name="duration"> time to wait until swipe to position </param> public static void TapByClassName(string className, int x, int y, int duration = 0) { ITouchAction action = BuildSingleAction(); try { AppiumWebElement element = GetControl.ByClass(className); action.Tap(element, x, y).Wait(duration).Perform(); } catch (Exception ex) { Assert.Fail("TapByClassName threw an exception: " + ex.Message); } }
/// <summary> /// LongPress over a specific element that will be found using it's classname. /// Can be used when that element shows a toggle or a popUp if press. /// </summary> /// <param name="className1"></param> /// <param name="className2"></param> /// <param name="duration"></param> public static void LongPressByClassName(string className1, string className2, int duration = 0) { ITouchAction action = BuildSingleAction(); try { AppiumWebElement firstElem = GetControl.ByClass(className1); AppiumWebElement secondElem = GetControl.ByClass(className2); action.LongPress(firstElem).Wait(duration).MoveTo(secondElem).Release().Perform(); } catch (Exception ex) { Assert.Fail("LongPressByClassName threw an exception: " + ex.Message); } }
public static void CheckBox(string id, string text, bool check = true) { try { var checkbox = text.IsNullOrEmpty() ? GetControl.ById(id) : GetControl.ById(id, text); if (!checkbox.GetAttribute("checked").Contains("true")) { checkbox.Click(); } } catch (Exception ex) { Assert.Fail("VerifyCheckBox threw an exception: " + ex.Message); } }
public static void Message(string id, string text) { try { var messageBox = GetControl.ById(id); if (messageBox.Text.Contains(text)) { return; } Assert.Fail("The message was not found"); } catch (Exception ex) { Assert.Fail("VerifyMessage threw an exception: " + ex.Message); } }
/// <summary> /// Finds the first element in the screen that matches the xPath criteria and then click it. /// </summary> /// <param name="text">text to match the element to be found</param> /// <param name="elem">Represents the Enum in Share class</param> /// <param name="widget">boolean if this is a widget</param> public static void ByXPath(string text, Share.Element elem = Share.Element.EditText, bool widget = true) { try { var elements = GetControl.CollectionByXPath(elem, widget); foreach (var element in elements) { if (element.Text.Contains(text)) { element.Click(); } } } catch (Exception ex) { Assert.Fail("ClickByXPath threw an exception: " + ex.Message); } }
/// <summary> /// Finds the first element in the screen that matches the id criteria and then click it. /// </summary> /// <param name="id">Id to find the object</param> /// <param name="text">Text to match a specific element</param> public static void ById(string id, string text) { try { var elements = GetControl.CollectionById(id); foreach (var elem in elements) { if (elem.Text.Contains(text)) { elem.Click(); } } } catch (Exception ex) { Assert.Fail("ClickById threw an exception: " + ex.Message); } }
/// <summary> /// Finds a collection of elements in the screen that matches the UiAutomator criteria using a Parent UiSelector. /// </summary> /// <param name="selector"> Represents the Enum in Share class </param> /// <param name="value"> the boolean value of an element to be found </param> /// <param name="position"> position of an object on the layout hierarchy </param> public static void CollectionByUiAutomatorParentSelector(Share.Selector selector, bool value, string text, int position = 0) { try { var elements = GetControl.CollectionByUiAutomatorParentSelector(selector, value, position); foreach (var element in elements) { if (element.Text.Contains(text)) { element.Click(); } } } catch (Exception ex) { Assert.Fail("ClicksCollectionByUiAutomatorParentSelector threw an exception: " + ex.Message); } }
/// <summary> /// Finds a collection of elements in the screen that matches the UiAutomator criteria using a Child UiSelector. /// </summary> /// <param name="inputText">The text to type into the element.</param> /// <param name="selector"> Represents the Enum in Share class </param> /// <param name="value"> the boolean value of an element to be found </param> /// <param name="text"> text to found the element to be Input</param> /// <param name="position"> position of an object on the layout hierarchy </param> public static void CollectionByUiAutomatorChildSelector(string inputText, Share.Selector selector, bool value, string text, int position = 0) { try { var elements = GetControl.CollectionByUiAutomatorChildSelector(selector, value, position); foreach (var element in elements) { if (element.Text.Contains(text)) { element.Clear(); element.SendKeys(inputText); } } } catch (Exception ex) { Assert.Fail("InputCollectionByUiAutomatorChildSelector threw an exception: " + ex.Message); } }
// ************ DATE 10/16/2020 ************ // In charge of the instantiation of single Action functions // ************ --------------- ************ #region SINGLE ACTION FUNCTIONS #region MOVE ACTIONS /// <summary> /// Emulates the swipe till the end of a specific element over the X & Y axis. /// </summary> /// <param name="className"> className of the element to swipe </param> /// <param name="direction"> represents the Enum in Share class </param> /// <param name="duration"> time to wait until swipe to position </param> public static void SwipeByClassName(string className, Direction direction = Direction.Up, int duration = 0) { ITouchAction action = BuildSingleAction(); try { AppiumWebElement scrollView = GetControl.ByClass(className); var initialWidth = scrollView.Size.Width - (scrollView.Size.Width - 5); var initialHeight = scrollView.Size.Height - (scrollView.Size.Height - 5); var centerWidth = scrollView.Size.Width / 2; var centerHeight = scrollView.Size.Height / 2; var endWidth = scrollView.Size.Width - 5; var endHeight = scrollView.Size.Height - 5; switch (direction) { case Direction.Up: action.Press(scrollView, centerWidth, initialHeight).Wait(duration).MoveTo(scrollView, centerWidth, endHeight).Release().Perform(); break; case Direction.Down: action.Press(scrollView, centerWidth, endHeight).Wait(duration).MoveTo(scrollView, centerWidth, initialHeight).Release().Perform(); break; case Direction.Left: action.Press(scrollView, initialWidth, centerHeight).Wait(duration).MoveTo(scrollView, endWidth, centerHeight).Release().Perform(); break; case Direction.Right: action.Press(scrollView, endWidth, centerHeight).Wait(duration).MoveTo(scrollView, initialWidth, centerHeight).Release().Perform(); break; } } catch (Exception ex) { Assert.Fail("SwipeByClassName threw an exception: " + ex.Message); } }
public static void Images() { try { var images = GetControl.CollectionByClass("widget.ImageView"); var firstImg = images.ElementAt(2); var secondImg = images.ElementAt(3); if (firstImg.Location.Y != secondImg.Location.Y) { Assert.Fail("Images hasn't the same vertical alignment"); } else if (firstImg.Location.X > secondImg.Location.X) { Assert.Fail("The images are not in the right order"); } } catch (Exception ex) { Assert.Fail("VerifyImage threw an exception: " + ex.Message); } }
public void ChangeWay(Keys key) { CurrentWay = GetControl.GetCurrent(key); }