Sha256: b378030e83a45a816a243e5a2871fb3ae604dfac76d97f0387c3ccde93a77144

Contents?: true

Size: 1.64 KB

Versions: 2

Compression:

Stored size: 1.64 KB

Contents

package sh.calaba.instrumentationbackend.actions.wait;

import sh.calaba.instrumentationbackend.InstrumentationBackend;
import sh.calaba.instrumentationbackend.Result;
import sh.calaba.instrumentationbackend.actions.Action;

public class WaitForScreen implements Action {

    @Override
    public Result execute(String... args) {

        final int DEFAULT_TIMEOUT = 5 * 1000;

        switch (args.length) {
        case 0:
            return new Result(false, "Cannot check for correct screen. No Activity name supplied!");
        case 1: {
            if (InstrumentationBackend.solo.waitForActivity(args[0], DEFAULT_TIMEOUT)) {
                return Result.successResult();
            } else {
                return new Result(false, "Screen " + args[0] + " not found");
            }
        }
        case 2: { // 1st arg is Activity name, 2nd arg is timeout
            int timeout = DEFAULT_TIMEOUT;
            
            try {
                // given seconds; want milliseconds
                timeout = 1000 * Integer.parseInt(args[1]);
            } catch (NumberFormatException e) {
                return new Result(false, "Invalid timeout supplied. Should be an integer!"); 
            }
            
            if (InstrumentationBackend.solo.waitForActivity(args[0], timeout)) {
                return Result.successResult();
            } else {
                return new Result(false, "Screen " + args[0] + " not found");
            }
        }
        default:
            return new Result(false, "Too many argument supplied to wait_for_screen!");
        }
    }

    @Override
    public String key() {
        return "wait_for_screen";
    }

}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
calabash-android-0.2.11 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForScreen.java
calabash-android-0.2.10 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForScreen.java