public static void MoveFromNotInGroupToGroup(int pickRow, int toGroup, int dropRow) { try { AndroidElement dragItem = null; AndroidElement dropItem = null; //get drag item var root = Appium.Instance.Driver.FindElementById("groups_grid"); var groupList = root.FindElementsById("table"); dropItem = (AndroidElement)groupList[toGroup].FindElementsByClassName("android.widget.TableRow")[dropRow]; //get drop item dragItem = (AndroidElement)NotInGroupList.GetInternalElement().FindElementsById("row_layout")[pickRow]; //drag n drop TouchAction action = new TouchAction(Appium.Instance.Driver); action.Press(dragItem).Wait(1500).MoveTo(dragItem).MoveTo(dropItem).Release().Perform(); ConsoleMessage.Pass( String.Format( "{0}. Take row at position: {1} from group not in group and drop to group at position: {2} at row: {3}", ActivityName, pickRow, toGroup, dropRow)); } catch (Exception ex) { ConsoleMessage.Fail( String.Format( String.Format( "{0}. Can't take row at position: {1} from group not in group and drop to group at position: {2} at row: {3}", ActivityName, pickRow, toGroup, dropRow)), ex); throw; } }
public void SwipeTest() { driver.StartActivity("io.appium.android.apis", ".graphics.FingerPaint"); AndroidElement element = driver.FindElementById("android:id/content"); Point point = element.Coordinates.LocationInDom; Size size = element.Size; driver.Swipe ( point.X + 5, point.Y + 5, point.X + size.Width - 5, point.Y + size.Height - 5, 200 ); driver.Swipe ( point.X + size.Width - 5, point.Y + 5, point.X + 5, point.Y + size.Height - 5, 2000 ); }
public void Test1() { AndroidElement registerButton = _driver.FindElementById("home_onboarding_email_register_button"); registerButton.Click(); Assert.Pass(); }
private static AndroidElement GetPropertyItem(string propertyName) { try { AndroidElement propItem = null; ReadOnlyCollection <AppiumWebElement> propertyItems = PropertyList.GetInternalElement().FindElementsByClassName("android.widget.RelativeLayout"); foreach (var element in propertyItems) { string currPropName = element.FindElementById("property_name").Text; if (currPropName.Contains(propertyName)) { propItem = (AndroidElement)element; return(propItem); } } Assert.Fail("Can't find property with name: " + propertyName); return(null); } catch (Exception ex) { ConsoleMessage.Fail( String.Format( "{0}. Can't find property.", ActivityName), ex); throw; } }
public ReadOnlyCollection <AndroidElement> GetElementsByClassName(AndroidElement parentElement, string className, bool errorNone) { DateTime startTime = DateTime.Now; while ((DateTime.Now - startTime).TotalMilliseconds < OperateTimeout) { Thread.Sleep(StatusCheckInterval); ReadOnlyCollection <AppiumWebElement> allChildElements = parentElement.FindElementsByClassName(className); if (allChildElements.Count > 0) { List <AndroidElement> elements = new List <AndroidElement>(); foreach (AppiumWebElement element in allChildElements) { elements.Add((AndroidElement)element); } return(new ReadOnlyCollection <AndroidElement>(elements)); } } if (errorNone) { throw new Exception("GetElementsByClassNameAndText获取元素超时, className=" + className); } else { return(null); } }
public void FromElementTestCase() { AndroidDriver <IWebElement> driver = new AndroidDriver <IWebElement>(defaultUri, capabilities); server.respondTo("POST", "/element", new Dictionary <string, object> { { "ELEMENT", '5' } }); AndroidElement element = (AndroidElement)driver.FindElementByAndroidUIAutomator(".elements()"); server.clear(); server.respondTo("POST", "/element/5/element", new Dictionary <string, object> { { "ELEMENT", '6' } }); element.FindElementByAndroidUIAutomator(".elements()"); server.clear(); List <object> results = new List <object>(); results.Add(new Dictionary <string, object> { { "ELEMENT", "4" } }); server.respondTo("POST", "/element/5/elements", results); element.FindElementsByAndroidUIAutomator(".elements()"); }
public AndroidElement GetElementById(string id, bool errorNone) { DateTime startTime = DateTime.Now; while ((DateTime.Now - startTime).TotalMilliseconds < OperateTimeout) { Thread.Sleep(StatusCheckInterval); try { AndroidElement element = Driver.FindElementById(id); if (element != null) { return(element); } } catch (NoSuchElementException ex) { //没有此元素 } catch (Exception ex) { throw ex; } } if (errorNone) { throw new Exception("GetElementById获取元素超时, Id = " + id); } else { return(null); } }
public AndroidElement GetElementByClassNameAndText(AndroidElement parentElement, string className, string[] texts, bool fullMatch, bool andCondition, bool errorNone) { DateTime startTime = DateTime.Now; while ((DateTime.Now - startTime).TotalMilliseconds < OperateTimeout) { Thread.Sleep(StatusCheckInterval); ReadOnlyCollection <AppiumWebElement> elements = parentElement.FindElementsByClassName(className); if (elements.Count > 0) { foreach (AndroidElement element in elements) { if (CheckElementContainText(element, texts, andCondition)) { return(element); } } } } if (errorNone) { string allText = CommonUtil.StringArrayToString(texts, ","); throw new Exception("GetElementByClassNameAndText获取元素超时, className=" + className + ", text = " + allText); } else { return(null); } }
public void ValidarTextoDoElemento(AndroidElement elemento, string texto) { Thread.Sleep(1); string txtElement = ObterTextoDoElemento(elemento); Assert.AreEqual(txtElement, texto); }
public string ObterTextoDoElemento(AndroidElement elemento) { string txt = elemento.Text; Console.WriteLine("Texto obtido: " + txt); return(txt); }
public static void PressButton(AppiumDriver <AndroidElement> driver, int number) { driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(3); AndroidElement Button = driver.FindElementByXPath($"//*[contains(@class,'Button') and contains(@text,'{number}')]"); Button.Click(); }
public void Authorization_NegativeTest() { string login = "******"; string password = "******"; string errorMessageText = ""; wait.Until(ExpectedConditions.ElementExists(By.Id("com.alibaba.aliexpresshd:id/et_email"))); AndroidElement emailField = driver.FindElementById("com.alibaba.aliexpresshd:id/et_email"); emailField.SendKeys(login); AndroidElement passwordField = driver.FindElementById("com.alibaba.aliexpresshd:id/et_password"); passwordField.SendKeys(password); AndroidElement loginButton = driver.FindElementById("com.alibaba.aliexpresshd:id/tv_signin_btn_label"); loginButton.Click(); try { AndroidElement errorMessage = driver.FindElementById("com.alibaba.aliexpresshd:id/textinput_error"); errorMessageText = errorMessage.Text; } catch (Exception) { throw new Exception("Элемент с сообщением об ошибке не представлен на странице"); } Assert.IsTrue(errorMessageText == "???", "Текст сообщения об ошибке - '" + errorMessageText + "' отличается от ожидаемого" + "???"); }
public void BeforeAll() { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.SetCapability(MobileCapabilityType.BrowserName, ""); capabilities.SetCapability(MobileCapabilityType.PlatformName, App.AndroidDeviceName()); capabilities.SetCapability(MobileCapabilityType.PlatformVersion, App.AndroidPlatformVersion()); capabilities.SetCapability(MobileCapabilityType.AutomationName, "UIAutomator2"); capabilities.SetCapability(MobileCapabilityType.DeviceName, "Nokia"); capabilities.SetCapability(MobileCapabilityType.App, App.AndroidApp()); driver = new AndroidDriver <AndroidElement>(Env.ServerUri(), capabilities, Env.INIT_TIMEOUT_SEC); driver.Manage().Timeouts().ImplicitWait = Env.IMPLICIT_TIMEOUT_SEC; wait = new WebDriverWait(driver, Env.IMPLICIT_TIMEOUT_SEC); AndroidElement menuButton = driver.FindElementById("com.alibaba.aliexpresshd:id/left_action"); menuButton.Click(); AndroidElement authorizationMenuButton = driver.FindElementById("com.alibaba.aliexpresshd:id/chosen_account_content_view"); authorizationMenuButton.Click(); AndroidElement loginMenuButton = driver.FindElementById("com.alibaba.aliexpresshd:id/btn_sign_in"); loginMenuButton.Click(); AndroidElement list = driver.FindElementById("android:id/autofill_dataset_list"); TouchAction action = new TouchAction(driver); action.Press(300, 100).Release().Perform(); }