Skip to content

Instantly share code, notes, and snippets.

@scompt
Created August 10, 2012 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scompt/3312344 to your computer and use it in GitHub Desktop.
Save scompt/3312344 to your computer and use it in GitHub Desktop.
Calabash verify list size
package sh.calaba.instrumentationbackend.actions.list;
import android.widget.ListView;
import sh.calaba.instrumentationbackend.InstrumentationBackend;
import sh.calaba.instrumentationbackend.Result;
import sh.calaba.instrumentationbackend.actions.Action;
import java.lang.Integer;
import java.lang.String;
import java.util.List;
public class AssertListSizeAction implements Action {
@Override
public Result execute(String... args) {
String listName = args[0];
int listSize = Integer.parseInt(args[1]);
List<ListView> listViews = InstrumentationBackend.solo.getCurrentListViews();
for (ListView listView : listViews) {
if(listName.equals(listView.getContentDescription())) {
int actualRowCount = listView.getAdapter().getCount();
if(actualRowCount == listSize) {
return Result.successResult();
} else {
return new Result(false, String.format("Wanted to find %d rows, but found %d", listSize, actualRowCount));
}
}
}
return new Result(false, String.format("Could not find '%s' list", listName));
}
@Override
public String key() {
return "assert_list_size";
}
}
Then /^the "([^\"]*)" list contains (\d+)/ do |list_name, count|
performAction('assert_list_size', list_name, count)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment