Created
August 10, 2012 07:35
-
-
Save scompt/3312344 to your computer and use it in GitHub Desktop.
Calabash verify list size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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