Jemmy入门之Waiter , In 测试 , Views: 553 , Comments: 0 , Index: 1933 , 10 April 2013

Jemmy中Waiter主要用于等待某个动作做完或者等待某个对象出现。在规定时间没做完的话会抛出超时异常。

/**
 * 可以看到它实现了Waitable, Timeoutable, Outputable这三个接口
 * 不过不是很明白它为啥要实现Waitable
 */
public class Waiter implements Waitable, Timeoutable, Outputable {
	/**
	 * timeout 常量,其中WAIT_TIME一般后来会被覆盖
	 */
	private final static long TIME_DELTA = 10;
	private final static long WAIT_TIME = 60000;
	private final static long AFTER_WAIT_TIME = 0;
 
	private Waitable waitable;
	private long startTime = 0;
	private long endTime = -1;
	private Object result;
	private Timeouts timeouts;
	private String waitingTimeOrigin;
	private TestOut out;
Jemmy入门之接口 , In 测试 , Views: 451 , Comments: 0 , Index: 2295 , 30 March 2013

Jemmy里定义了很多的接口,比如做一个动作的时候(ActionProducer)会实现Action, Waitable,Timeoutable这三个接口。

public interface Waitable{
    /**
     * Checks if wait criteria have been met.
     * @param obj optional waiting parameter.
     * @return null is criteria have not been met.
     */
    public Object actionProduced(Object obj);
 
    /**
     * Returns description.
     * @return a description of the wait criteria.
     */
    public String getDescription();
}
public interface Timeoutable {
    /**
     * Defines current timeouts.
     * @param t A collection of timeout assignments.
     * @see #getTimeouts
     */
    public void setTimeouts(Timeouts t);
 
    /**
     * Return current timeouts.
     * @return the collection of current timeout assignments.
     * @see #setTimeouts
     */
    public Timeouts getTimeouts();
}
Jemmy入门之ActionProducer , In 测试 , Views: 499 , Comments: 0 , Index: 2578 , 10 March 2013

ActionProducer是Scenario的基类,主要是执行一个在预期时间内要完成的动作。

public class ActionProducer extends Thread implements Action, Waitable,	Timeoutable {
	/**
	 * timeout 常量,一般用来覆盖Waiter的WAIT_TIME
	 */
	private final static long ACTION_TIMEOUT = 10000;
 
	private Action action;
	private boolean needWait = true;
	private Object parameter;
	private boolean finished;
	private Object result = null;
	private Timeouts timeouts;
	private Waiter waiter;
	private TestOut output;
	private Throwable exception;