/// <summary> /// Incrementally scrolls down until the desired elements are found /// </summary> public static AppResult[] ScrollDownEnough(this AndroidApp app, Func <AppQuery, AppQuery> lambda, string screenshot = null) { AppResult rootView = null; int count = 0; int maxTries = 20; AppResult[] lastTry; while (count < maxTries) { lastTry = app.Query(lambda); if (lastTry.Any()) { if (screenshot != null) { app.Screenshot(screenshot); } return(lastTry); } if (rootView == null) { rootView = app.Query(e => e.All()).FirstOrDefault(); if (rootView == null) { throw new Exception("Unable to get root view"); } } //Will try to scroll +/-100 from the vertical center point float gap = 100; //Take into account where the screen is not large and the gap would be too big if (rootView.Rect.Height < gap * 2) { gap = rootView.Rect.Height / 4; } app.DragCoordinates(rootView.Rect.CenterX, rootView.Rect.CenterY + gap, rootView.Rect.CenterX, rootView.Rect.CenterY - gap); count++; } if (count == maxTries) { throw new Exception("Unable to scroll down to find element"); } return(new AppResult[0]); }
public static void DragFromTo(this AndroidApp app, float xStart, float yStart, float xEnd, float yEnd, Speed speed = Speed.Fast) { // No effect on Android app.DragCoordinates(xStart, yStart, xEnd, yEnd); }