Skip to content

Instantly share code, notes, and snippets.

@danwaters
Last active August 29, 2015 14:23
Show Gist options
  • Save danwaters/343261c5280520bfe806 to your computer and use it in GitHub Desktop.
Save danwaters/343261c5280520bfe806 to your computer and use it in GitHub Desktop.
Swipe to delete on iOS
[Test]
public void SwipeToDelete ()
{
app.SwipeToDelete ("MSCMoreOptionTableViewCell", 0);
app.Screenshot ("Swipe to delete");
}
public static class AppExtensions
{
public static void SwipeToDelete(this IApp app, string uiClass, int index)
{
// This line is just for convenience because I use this query twice.
System.Func<AppQuery, AppQuery> rowQuery = e => e.Class (uiClass).Index (index);
// Wait for the row
app.WaitForElement (rowQuery);
app.Screenshot ("Found the row");
// Find the row as an AppResult; this object gives you the size properties.
var row = app.Query (rowQuery).Single ();
// This is where we do The Magic. Eventually there will be an overload for app.Swipe* which takes a query as an argument.
// You can do app.SwipeLeft(e => e.Id("...")) today in the REPL, but not in code yet.
app.DragCoordinates (row.Rect.Width - 10, row.Rect.CenterY, 10, row.Rect.CenterY);
app.Screenshot ("Swipe to delete");
// Find and tap the Trash icon
app.WaitForElement (e => e.Marked ("Trash"));
app.Tap(e => e.Marked("Trash"));
app.Screenshot ("Trash icon tapped");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment