public abstract class Condition extends java.lang.Object implements Condition, java.io.Serializable
public class MyCondition extends Condition{
public boolean isSatisfied() {
boolean satisfied = true;
try{
List<Object> views = this.getObjects();
//The first object is reserved by TestRunner object
//RobotiumTestRunner runner = (RobotiumTestRunner) views.get(0);
//Solo solo = runner.getSolo();
//From 1, they are View objects
for(int i=1;i<views.size();i++){
satisfied = satisfied && ((View) views.get(i)).isShown();
}
}catch(Exception e){
e.printStackTrace();
satisfied = false;
}
return satisfied;
}
}
The class MyCondition needs to be put into the TestRunner project. The TestRunner projectaddObjects(List)/addObject(Object) to add the view's UID.
private void testWaitForCondition(){
try {
Condition condition = new MyCondition();
List listviews = solo.getCurrentListViews();
condition.addObjects(listviews);
boolean isSatisfied = solo.waitForCondition(condition, 10);
System.out.println("waitForCondition isSatisfied: " + isSatisfied);
} catch (Exception e1) {
e1.printStackTrace();
}
}
At the device side, we receive that object 'condition', which can be used by Robotium's APIs.| Modifier and Type | Field and Description |
|---|---|
(package private) java.util.List<java.lang.Object> |
objects
This field is also used to transport view's UID from controller to device.
At the controller side, we put the views' UID into the list objectsAt the device side, we get the real instance of View from cache and replace the UID so that the list objects will contain instances of View.The first object is an instance of class AbstractTestRunner. |
| Constructor and Description |
|---|
Condition() |
| Modifier and Type | Method and Description |
|---|---|
void |
addObject(java.lang.Object object)
Append an object to the list
objects. |
void |
addObject(java.lang.Object object,
boolean asFirstItem)
Add an object to the list
objects. |
void |
addObjects(java.util.List<java.lang.Object> objects)
Append all objects to the existing list
objects |
java.util.List<java.lang.Object> |
getObjects() |
abstract boolean |
isSatisfied()
Should do the necessary work needed to check a condition and then return whether this condition is satisfied or not.
|
void |
setObject(java.lang.Object object,
int index)
Replace the existing object in the list
objects |
void |
setObjects(java.util.List<java.lang.Object> objects) |
java.util.List<java.lang.Object> objects
objectsobjects will contain instances of View.AbstractTestRunner,
Viewpublic abstract boolean isSatisfied()
isSatisfied in interface Conditiontrue if condition is satisfied and false if it is not satisfiedpublic java.util.List<java.lang.Object> getObjects()
public void setObjects(java.util.List<java.lang.Object> objects)
public void addObjects(java.util.List<java.lang.Object> objects)
objectspublic void addObject(java.lang.Object object)
objects.addObject(Object, boolean)public void addObject(java.lang.Object object,
boolean asFirstItem)
objects.object - Object, to be added to the list objectsasFirstItem - boolean, if we add the object as the first item of list.public void setObject(java.lang.Object object,
int index)
objectsCopyright © SAS Institute. All Rights Reserved.