Java 类android.support.test.filters.RequiresDevice 实例源码

项目:unity-ads-android    文件:VideoViewTest.java   
@Test
@RequiresDevice
public void testConstruct () throws Exception {
    final ConditionVariable cv = new ConditionVariable();
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            VideoPlayerView vp = new VideoPlayerView(getInstrumentation().getTargetContext());
            assertNotNull("VideoPlayerView should not be null after constructing", vp);
            cv.open();
        }
    });

    boolean success = cv.block(30000);
    assertTrue("Condition variable was not opened properly: VideoPlayer was not created", success);
}
项目:Presenter-Client-Android    文件:SettingsActivityTest.java   
/**
 * Verify that the "Silence during presentation" setting is correctly stored and restored
 * on activity loading.
 *
 * @throws InterruptedException If sleep times fail
 */
@Test
@LargeTest
@RequiresDevice
public void verifySilenceDuringPresentationStoring() throws InterruptedException {
    onView(withId(R.id.silenceDuringPresentation))
            .perform(click());
    Thread.sleep(1000);
    onView(withId(R.id.silenceDuringPresentation))
            .check(matches(isChecked()));

    settingsActivityRule.getActivity().onStop();
    settingsActivityRule.getActivity().finish();
    Thread.sleep(1000);
    assertThat(settingsActivityRule.getActivity().isDestroyed(), is(true));

    settingsActivityRule.launchActivity(null);
    onView(withId(R.id.silenceDuringPresentation))
            .check(matches(isChecked()))
            .perform(click());
    Thread.sleep(1000);
    onView(withId(R.id.silenceDuringPresentation))
            .check(matches(isNotChecked()));

    settingsActivityRule.getActivity().onStop();
    settingsActivityRule.getActivity().finish();
    Thread.sleep(1000);
    assertThat(settingsActivityRule.getActivity().isDestroyed(), is(true));

    settingsActivityRule.launchActivity(null);
    onView(withId(R.id.silenceDuringPresentation)).check(matches(isNotChecked()));
}
项目:Presenter-Client-Android    文件:SettingsActivityTest.java   
/**
 * Verify that the "Use volume keys for navigation" setting is correctly stored and restored
 * on activity loading.
 *
 * @throws InterruptedException If sleep times fail
 */
@Test
@LargeTest
@RequiresDevice
public void verifyUseVolumeKeysForNavigationStoring() throws InterruptedException {
    onView(withId(R.id.useVolumeKeysForNavigation))
            .perform(click());
    Thread.sleep(1000);
    onView(withId(R.id.useVolumeKeysForNavigation))
            .check(matches(isNotChecked()));

    settingsActivityRule.getActivity().onStop();
    settingsActivityRule.getActivity().finish();
    Thread.sleep(1000);
    assertThat(settingsActivityRule.getActivity().isDestroyed(), is(true));

    settingsActivityRule.launchActivity(null);
    onView(withId(R.id.useVolumeKeysForNavigation))
            .check(matches(isNotChecked()))
            .perform(click());
    Thread.sleep(1000);
    onView(withId(R.id.useVolumeKeysForNavigation))
            .check(matches(isChecked()));

    settingsActivityRule.getActivity().onStop();
    settingsActivityRule.getActivity().finish();
    Thread.sleep(1000);
    assertThat(settingsActivityRule.getActivity().isDestroyed(), is(true));

    settingsActivityRule.launchActivity(null);
    onView(withId(R.id.useVolumeKeysForNavigation)).check(matches(isChecked()));
}
项目:braintree-android-drop-in    文件:DropInTest.java   
@RequiresDevice
@Test(timeout = 60000)
public void tokenizesAndroidPay() {
    onDevice(withText("Add Payment Method")).waitForEnabled().perform(click());

    onDevice(withText("Android Pay")).perform(click());
    onDevice(withText("CONTINUE")).perform(click());

    getNonceDetails().check(text(containsString("Underlying Card Last Two")));

    onDevice(withText("Purchase")).perform(click());
    onDevice(withTextStartingWith("created")).check(text(endsWith("authorized")));
}
项目:android-testing-guide    文件:MainActivityTest.java   
@Test
@RequiresDevice
public void testRequiresDevice() {
    Log.d("Test Filters", "This test requires a device");
    Activity activity = activityTestRule.getActivity();
    assertNotNull("MainActivity is not available", activity);
}
项目:braintree_android    文件:DropInTest.java   
@RequiresDevice
@Test(timeout = 60000)
public void tokenizesAndroidPay() {
    onDevice(withText("Android Pay")).perform(click());
    onDevice(withText("CONTINUE")).perform(click());

    getNonceDetails().check(text(containsString("Underlying Card Last Two")));

    onDevice(withText("Create a Transaction")).perform(click());
    onDevice(withTextStartingWith("created")).check(text(endsWith("authorized")));
}
项目:akvo-caddisfly    文件:ChamberInstructions.java   
@Test
    @RequiresDevice
    public void testInstructionsBackcase() {

        goToMainScreen();

        gotoSurveyForm();

        clickExternalSourceButton(0);

        sleep(1000);

        mDevice.waitForIdle();

        TestUtil.sleep(1000);

        String id = Constants.FLUORIDE_ID.substring(
                Constants.FLUORIDE_ID.lastIndexOf("-") + 1, Constants.FLUORIDE_ID.length());

        takeScreenshot(id, -1);

        mDevice.waitForIdle();

//        onView(withText(getString(mActivityTestRule.getActivity(), R.string.instructions))).perform(click());
//
//        for (int i = 0; i < 17; i++) {
//
//            try {
//                takeScreenshot(id, i);
//
//                onView(withId(R.id.image_pageRight)).perform(click());
//
//            } catch (Exception e) {
//                TestUtil.sleep(600);
//                Espresso.pressBack();
//                break;
//            }
//        }
    }
项目:akvo-caddisfly    文件:ChamberTest.java   
@Test
@RequiresDevice
public void testFreeChlorine() {
    saveCalibration("TestValidChlorine", Constants.FREE_CHLORINE_ID_2);

    onView(withId(R.id.actionSettings)).perform(click());

    onView(withText(R.string.about)).check(matches(isDisplayed()));
}
项目:akvo-caddisfly    文件:StriptestTest.java   
@Test
@RequiresDevice
public void startStriptest() {

    activateTestMode();

    test5in1(false);
    testSoilNitrogen(false);
    testMerckPH(false);
    testNitrate100();

    test5in1(true);
    testSoilNitrogen(true);
    testMerckPH(true);
}
项目:unity-ads-android    文件:VideoViewTest.java   
@Test
@RequiresDevice
public void testPrepare () throws Exception {
    final Activity activity = waitForActivityStart(null);
    assertNotNull("Started activity should not be null!", activity);

    WebViewApp.setCurrentApp(new MockWebViewApp() {
        @Override
        public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
            super.sendEvent(eventCategory, eventId, params);

            DeviceLog.debug("Event: " + eventCategory.name() + ", " + eventId.name());

            if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PREPARED)) {
                if (CONDITION_VARIABLE != null)
                    CONDITION_VARIABLE.open();
            }

            return true;
        }
    });

    final String validUrl = TestUtilities.getTestServerAddress() + "/blue_test_trailer.mp4";
    final Handler handler = new Handler(Looper.getMainLooper());

    final ConditionVariable viewAddCV = new ConditionVariable();
    handler.post(new Runnable() {
        @Override
        public void run() {
            ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW = new VideoPlayerView(getInstrumentation().getTargetContext());
            activity.addContentView(((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            viewAddCV.open();
        }
    });
    boolean success = viewAddCV.block(3000);
    assertTrue("ConditionVariable did not open in view add", success);

    MockWebViewApp mockWebViewApp = (MockWebViewApp)WebViewApp.getCurrentApp();
    ConditionVariable prepareCV = new ConditionVariable();
    mockWebViewApp.CONDITION_VARIABLE = prepareCV;
    DeviceLog.debug("URL_GIVEN: " + validUrl);
    ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW.prepare(validUrl, 1f, 0);
    success = prepareCV.block(30000);

    assertTrue("Condition Variable was not opened: PREPARE or PREPARE ERROR event was not received", success);
    assertTrue("Didn't get activity finish", waitForActivityFinish(activity));
}
项目:unity-ads-android    文件:VideoViewTest.java   
@Test
@RequiresDevice
public void testPrepareAndPlay () throws Exception {
    final Activity activity = waitForActivityStart(null);

    WebViewApp.setCurrentApp(new MockWebViewApp() {
        private boolean allowEvents = true;
        @Override
        public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
            super.sendEvent(eventCategory, eventId, params);
            if ("ON_FOCUS_GAINED".equals(eventId.name()) || "ON_FOCUS_LOST".equals(eventId.name())) {
                return true;
            }
            if (allowEvents) {
                EVENT_CATEGORIES.add(eventCategory);
                EVENTS.add(eventId);
                EVENT_PARAMS = params;
                EVENT_COUNT++;

                DeviceLog.debug(eventId.name());

                if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PREPARED)) {
                    VIDEOPLAYER_VIEW.play();
                }
                if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.COMPLETED)) {
                    allowEvents = false;
                    CONDITION_VARIABLE.open();
                }
            }

            return true;
        }
    });

    final String validUrl = TestUtilities.getTestServerAddress() + "/blue_test_trailer.mp4";
    final Handler handler = new Handler(Looper.getMainLooper());

    final ConditionVariable viewAddCV = new ConditionVariable();
    handler.post(new Runnable() {
        @Override
        public void run() {
            ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW = new VideoPlayerView(getInstrumentation().getTargetContext());
            activity.addContentView(((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            viewAddCV.open();
        }
    });
    boolean success = viewAddCV.block(3000);
    assertTrue("ConditionVariable did not open in view add", success);

    final MockWebViewApp mockWebViewApp = (MockWebViewApp)WebViewApp.getCurrentApp();
    ConditionVariable cv = new ConditionVariable();
    mockWebViewApp.CONDITION_VARIABLE = cv;
    DeviceLog.debug("URL_GIVEN: " + validUrl);
    ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW.prepare(validUrl, 1f, 0);
    success = cv.block(30000);

    assertTrue("Condition Variable was not opened: COMPLETED or PREPARE ERROR event was not received", success);
    assertEquals("Event category should be videoplayer category", WebViewEventCategory.VIDEOPLAYER, mockWebViewApp.EVENT_CATEGORIES.get(0));
    assertEquals("Event ID should be completed", VideoPlayerEvent.COMPLETED, mockWebViewApp.EVENTS.get(mockWebViewApp.EVENTS.size() - 1));
    assertEquals("The video url and the url received from the completed event should be the same", validUrl, mockWebViewApp.EVENT_PARAMS[0]);
    assertTrue("Didn't get activity finish", waitForActivityFinish(activity));
}
项目:unity-ads-android    文件:VideoViewTest.java   
@Test
@RequiresDevice
public void testPrepareAndPlayNonExistingUrl () throws Exception {
    final Activity activity = waitForActivityStart(null);

    WebViewApp.setCurrentApp(new MockWebViewApp() {
        private boolean allowEvents = true;
        @Override
        public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
            super.sendEvent(eventCategory, eventId, params);
            if ("ON_FOCUS_GAINED".equals(eventId.name()) || "ON_FOCUS_LOST".equals(eventId.name())) {
                return true;
            }
            if (allowEvents) {
                EVENT_CATEGORIES.add(eventCategory);
                EVENTS.add(eventId);
                EVENT_PARAMS = params;
                EVENT_COUNT++;

                DeviceLog.debug(eventId.name());

                if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PREPARED)) {
                    VIDEOPLAYER_VIEW.play();
                }
                if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.GENERIC_ERROR)) {
                    allowEvents = false;
                    CONDITION_VARIABLE.open();
                }
            }

            return true;
        }
    });

    final String invalidUrl = TestUtilities.getTestServerAddress() + "/blue_test_trailer-invalid.mp4";
    final Handler handler = new Handler(Looper.getMainLooper());

    final ConditionVariable viewAddCV = new ConditionVariable();
    handler.post(new Runnable() {
        @Override
        public void run() {
            ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW = new VideoPlayerView(getInstrumentation().getTargetContext());
            activity.addContentView(((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            viewAddCV.open();
        }
    });
    boolean success = viewAddCV.block(3000);
    assertTrue("ConditionVariable did not open in view add", success);

    final MockWebViewApp mockWebViewApp = (MockWebViewApp)WebViewApp.getCurrentApp();
    ConditionVariable cv = new ConditionVariable();
    mockWebViewApp.CONDITION_VARIABLE = cv;
    DeviceLog.debug("URL_GIVEN: " + invalidUrl);
    ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW.prepare(invalidUrl, 1f, 0);
    success = cv.block(30000);

    assertTrue("Condition Variable was not opened: VIDEOPLAYER GENERIC ERROR or PREPARE ERROR was not received", success);
    assertEquals("Event category should be videoplayer category", WebViewEventCategory.VIDEOPLAYER, mockWebViewApp.EVENT_CATEGORIES.get(0));
    assertEquals("Event ID should be generic error", VideoPlayerEvent.GENERIC_ERROR, mockWebViewApp.EVENTS.get(0));
    assertEquals("The video url and the url received from the completed event should be the same", invalidUrl, mockWebViewApp.EVENT_PARAMS[0]);
    assertTrue("Didn't get activity finish", waitForActivityFinish(activity));
}
项目:unity-ads-android    文件:VideoViewTest.java   
@Test
@RequiresDevice
public void testPreparePlaySeekToPause () throws Exception {
    final Activity activity = waitForActivityStart(null);

    WebViewApp.setCurrentApp(new MockWebViewApp() {
        private boolean allowEvents = true;
        @Override
        public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
            super.sendEvent(eventCategory, eventId, params);

            if ("ON_FOCUS_GAINED".equals(eventId.name()) || "ON_FOCUS_LOST".equals(eventId.name())) {
                return true;
            }

            EVENT_CATEGORIES.add(eventCategory);
            EVENTS.add(eventId);
            EVENT_PARAMS = params;
            EVENT_COUNT++;

            if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PREPARED)) {
                VIDEOPLAYER_VIEW.play();
            }
            if (!EVENT_TRIGGERED && eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PROGRESS)) {
                EVENT_TRIGGERED = true;
                VIDEOPLAYER_VIEW.seekTo(4080);
                VIDEOPLAYER_VIEW.pause();
                CONDITION_VARIABLE.open();
                allowEvents = false;
            }

            return true;
        }
    });

    final String validUrl = TestUtilities.getTestServerAddress() + "/blue_test_trailer.mp4";
    final Handler handler = new Handler(Looper.getMainLooper());
    final ConditionVariable viewAddCV = new ConditionVariable();
    handler.post(new Runnable() {
        @Override
        public void run() {
            ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW = new VideoPlayerView(getInstrumentation().getTargetContext());
            activity.addContentView(((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            viewAddCV.open();
        }
    });
    boolean success = viewAddCV.block(3000);
    assertTrue("ConditionVariable did not open in view add", success);

    final MockWebViewApp mockWebViewApp = (MockWebViewApp)WebViewApp.getCurrentApp();
    ConditionVariable cv = new ConditionVariable();
    mockWebViewApp.CONDITION_VARIABLE = cv;
    DeviceLog.debug("URL_GIVEN: " + validUrl);
    ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW.prepare(validUrl, 1f, 0);
    success = cv.block(30000);

    assertTrue("Condition Variable was not opened: PROGRESS or PREPARE ERROR event was not received", success);
    assertTrue("Current position should be over 300ms", mockWebViewApp.VIDEOPLAYER_VIEW.getCurrentPosition() > 300);
    int diff = Math.abs(4080 - mockWebViewApp.VIDEOPLAYER_VIEW.getCurrentPosition());
    DeviceLog.debug("Difference: " + diff);
    assertTrue("Difference between expected position and actual position should be less than 300ms", diff < 300);
    assertTrue("Didn't get activity finish", waitForActivityFinish(activity));
}
项目:unity-ads-android    文件:VideoViewTest.java   
@Test
@RequiresDevice
public void testPreparePlayStop () throws Exception {
    final Activity activity = waitForActivityStart(null);

    WebViewApp.setCurrentApp(new MockWebViewApp() {
        @Override
        public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
            super.sendEvent(eventCategory, eventId, params);

            if ("ON_FOCUS_GAINED".equals(eventId.name()) || "ON_FOCUS_LOST".equals(eventId.name())) {
                return true;
            }

            EVENT_CATEGORIES.add(eventCategory);
            EVENTS.add(eventId);
            EVENT_PARAMS = params;
            EVENT_COUNT++;

            if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PREPARED)) {
                VIDEOPLAYER_VIEW.play();
            }
            if (!EVENT_TRIGGERED && eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PROGRESS)) {
                if (EVENT_COUNT > 8) {
                    EVENT_TRIGGERED = true;
                    VIDEOPLAYER_VIEW.stop();
                    CONDITION_VARIABLE.open();
                }
            }

            return true;
        }
    });

    final String validUrl = TestUtilities.getTestServerAddress() + "/blue_test_trailer.mp4";

    final Handler handler = new Handler(Looper.getMainLooper());
    final ConditionVariable viewAddCV = new ConditionVariable();
    handler.post(new Runnable() {
        @Override
        public void run() {
            ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW = new VideoPlayerView(getInstrumentation().getTargetContext());
            activity.addContentView(((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            viewAddCV.open();
        }
    });
    boolean success = viewAddCV.block(3000);
    assertTrue("ConditionVariable did not open in view add", success);

    final MockWebViewApp mockWebViewApp = (MockWebViewApp)WebViewApp.getCurrentApp();
    ConditionVariable cv = new ConditionVariable();
    mockWebViewApp.CONDITION_VARIABLE = cv;
    ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW.prepare(validUrl, 1f, 0);
    success = cv.block(30000);

    assertTrue("Condition Variable was not opened: PREPARED or PREPARE ERROR event was not received", success);
    assertFalse("Videoplayer shoudn't be in isPlaying state", mockWebViewApp.VIDEOPLAYER_VIEW.isPlaying());
    assertTrue("Didn't get activity finish", waitForActivityFinish(activity));
}
项目:unity-ads-android    文件:VideoViewTest.java   
@Test
@RequiresDevice
public void testPreparePlaySetVolumePause () throws Exception {
    final Activity activity = waitForActivityStart(null);

    WebViewApp.setCurrentApp(new MockWebViewApp() {
        @Override
        public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
            super.sendEvent(eventCategory, eventId, params);

            if ("ON_FOCUS_GAINED".equals(eventId.name()) || "ON_FOCUS_LOST".equals(eventId.name())) {
                return true;
            }

            EVENT_CATEGORIES.add(eventCategory);
            EVENTS.add(eventId);
            EVENT_PARAMS = params;
            EVENT_COUNT++;

            if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PREPARED)) {
                VIDEOPLAYER_VIEW.play();
            }
            if (!EVENT_TRIGGERED && eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PROGRESS)) {
                if (EVENT_COUNT > 8) {
                    EVENT_TRIGGERED = true;
                    VIDEOPLAYER_VIEW.setVolume(0.666f);
                    VIDEOPLAYER_VIEW.pause();
                    CONDITION_VARIABLE.open();
                }
            }

            return true;
        }
    });

    final String validUrl = TestUtilities.getTestServerAddress() + "/blue_test_trailer.mp4";

    final Handler handler = new Handler(Looper.getMainLooper());
    final ConditionVariable viewAddCV = new ConditionVariable();
    handler.post(new Runnable() {
        @Override
        public void run() {
            ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW = new VideoPlayerView(getInstrumentation().getTargetContext());
            activity.addContentView(((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            viewAddCV.open();
        }
    });
    boolean success = viewAddCV.block(3000);
    assertTrue("ConditionVariable did not open in view add", success);

    final MockWebViewApp mockWebViewApp = (MockWebViewApp)WebViewApp.getCurrentApp();
    ConditionVariable cv = new ConditionVariable();
    mockWebViewApp.CONDITION_VARIABLE = cv;
    ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW.prepare(validUrl, 1f, 0);
    success = cv.block(30000);

    assertTrue("Condition Variable was not opened: PREPARED or PREPARE ERROR event was not received", success);
    assertFalse("Videoplayer shouldn't be in isPlaying state", mockWebViewApp.VIDEOPLAYER_VIEW.isPlaying());
    assertEquals("getVolume should return the same value as what was set as volume", 0.666f, mockWebViewApp.VIDEOPLAYER_VIEW.getVolume());
    assertTrue("Didn't get activity finish", waitForActivityFinish(activity));
}
项目:unity-ads-android    文件:VideoViewTest.java   
@Test
@RequiresDevice
public void testSetProgressInterval () throws Exception {
    final Activity activity = waitForActivityStart(null);

    WebViewApp.setCurrentApp(new MockWebViewApp() {
        @Override
        public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
            super.sendEvent(eventCategory, eventId, params);

            if ("ON_FOCUS_GAINED".equals(eventId.name()) || "ON_FOCUS_LOST".equals(eventId.name())) {
                return true;
            }

            EVENT_CATEGORIES.add(eventCategory);
            EVENTS.add(eventId);
            EVENT_PARAMS = params;
            EVENT_COUNT++;

            if (eventId.equals(VideoPlayerEvent.PROGRESS)) {
                EVENT_POSITIONS.add(System.currentTimeMillis());
            }

            if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PREPARED)) {
                VIDEOPLAYER_VIEW.play();
            }
            else if (!EVENT_TRIGGERED && eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PROGRESS)) {
                if (EVENT_COUNT > 12) {
                    EVENT_TRIGGERED = true;
                    VIDEOPLAYER_VIEW.pause();
                    CONDITION_VARIABLE.open();
                }
            }

            return true;
        }
    });

    final String validUrl = TestUtilities.getTestServerAddress() + "/blue_test_trailer.mp4";

    final Handler handler = new Handler(Looper.getMainLooper());
    final ConditionVariable viewAddCV = new ConditionVariable();
    handler.post(new Runnable() {
        @Override
        public void run() {
            ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW = new VideoPlayerView(getInstrumentation().getTargetContext());
            activity.addContentView(((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            viewAddCV.open();
        }
    });
    boolean success = viewAddCV.block(3000);
    assertTrue("ConditionVariable did not open in view add", success);

    final MockWebViewApp mockWebViewApp = (MockWebViewApp)WebViewApp.getCurrentApp();
    ConditionVariable cv = new ConditionVariable();
    mockWebViewApp.CONDITION_VARIABLE = cv;
    ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW.setProgressEventInterval(300);
    ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW.prepare(validUrl, 1f, 0);
    success = cv.block(30000);

    assertTrue("Condition Variable was not opened: VIDEO PROGRESS or PREPARE ERROR event was not received", success);

    int failedIntervals = 0;

    for (int idx = 0; idx < EVENT_POSITIONS.size(); idx++) {
        if (idx + 1 < EVENT_POSITIONS.size()) {
            long interval = Math.abs(300 - (EVENT_POSITIONS.get(idx + 1) - EVENT_POSITIONS.get(idx)));
            DeviceLog.debug("Interval is: " + interval);

            if (interval > 80) {
                failedIntervals++;
            }

            assertFalse("Too many intervals failed to arrive in 80ms threshold (" + failedIntervals + ")", failedIntervals > 3);
        }
    }

    assertFalse("Videoplayer shouldn't be in isPlaying state", mockWebViewApp.VIDEOPLAYER_VIEW.isPlaying());
    assertEquals("getProgressInterval should return the same value as what was set", 300, mockWebViewApp.VIDEOPLAYER_VIEW.getProgressEventInterval());
    assertTrue("Didn't get activity finish", waitForActivityFinish(activity));
}
项目:unity-ads-android    文件:VideoViewTest.java   
@Test
@RequiresDevice
public void testPreparePlayPause () throws Exception {
    final Activity activity = waitForActivityStart(null);

    WebViewApp.setCurrentApp(new MockWebViewApp() {
        @Override
        public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
            super.sendEvent(eventCategory, eventId, params);

            if ("ON_FOCUS_GAINED".equals(eventId.name()) || "ON_FOCUS_LOST".equals(eventId.name())) {
                return true;
            }

            EVENT_CATEGORIES.add(eventCategory);
            EVENTS.add(eventId);
            EVENT_PARAMS = params;
            EVENT_COUNT++;

            if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PREPARED)) {
                VIDEOPLAYER_VIEW.play();
            }
            else if (!EVENT_TRIGGERED && eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PROGRESS)) {
                if (EVENT_COUNT > 6) {
                    EVENT_TRIGGERED = true;
                    VIDEOPLAYER_VIEW.pause();
                    CONDITION_VARIABLE.open();
                }
            }

            return true;
        }
    });

    final String validUrl = TestUtilities.getTestServerAddress() + "/blue_test_trailer.mp4";

    final Handler handler = new Handler(Looper.getMainLooper());
    final ConditionVariable viewAddCV = new ConditionVariable();
    handler.post(new Runnable() {
        @Override
        public void run() {
            ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW = new VideoPlayerView(getInstrumentation().getTargetContext());
            activity.addContentView(((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            viewAddCV.open();
        }
    });
    boolean success = viewAddCV.block(3000);
    assertTrue("ConditionVariable did not open in view add", success);

    final MockWebViewApp mockWebViewApp = (MockWebViewApp)WebViewApp.getCurrentApp();
    ConditionVariable cv = new ConditionVariable();
    mockWebViewApp.CONDITION_VARIABLE = cv;
    ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW.prepare(validUrl, 1f, 0);
    success = cv.block(30000);

    assertTrue("Condition Variable was not opened: VIDEO PROGRESS or PREPARE ERROR event was not received", success);
    assertTrue("Current position should be over 300ms", mockWebViewApp.VIDEOPLAYER_VIEW.getCurrentPosition() > 300);
    assertTrue("Didn't get activity finish", waitForActivityFinish(activity));
}
项目:unity-ads-android    文件:VideoViewTest.java   
@Test
@RequiresDevice
@SdkSuppress(minSdkVersion = 17)
public void testInfoListener () throws Exception {
    final Activity activity = waitForActivityStart(null);

    WebViewApp.setCurrentApp(new MockWebViewApp() {
        @Override
        public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
            super.sendEvent(eventCategory, eventId, params);

            if ("ON_FOCUS_GAINED".equals(eventId.name()) || "ON_FOCUS_LOST".equals(eventId.name())) {
                return true;
            }

            EVENT_CATEGORIES.add(eventCategory);
            EVENTS.add(eventId);
            EVENT_PARAMS = params;
            EVENT_COUNT++;

            if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PREPARED)) {
                VIDEOPLAYER_VIEW.play();
            }
            if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.INFO)) {
                INFO_EVENTS = new ArrayList<>();
                INFO_EVENTS.add((Integer) params[1]);
            }
            if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.COMPLETED)) {
                CONDITION_VARIABLE.open();
            }

            return true;
        }
    });

    final String validUrl = TestUtilities.getTestServerAddress() + "/blue_test_trailer.mp4";

    final Handler handler = new Handler(Looper.getMainLooper());
    final ConditionVariable viewAddCV = new ConditionVariable();
    handler.post(new Runnable() {
        @Override
        public void run() {
            ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW = new VideoPlayerView(getInstrumentation().getTargetContext());
            activity.addContentView(((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            viewAddCV.open();
        }
    });
    boolean success = viewAddCV.block(3000);
    assertTrue("ConditionVariable did not open in view add", success);

    final MockWebViewApp mockWebViewApp = (MockWebViewApp)WebViewApp.getCurrentApp();
    ConditionVariable cv = new ConditionVariable();
    mockWebViewApp.CONDITION_VARIABLE = cv;
    ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW.prepare(validUrl, 1f, 0);
    success = cv.block(30000);

    assertTrue("Condition Variable was not opened: COMPLETED or PREPARE ERROR event was not received", success);
    assertEquals("Event category should be videoplayer category", WebViewEventCategory.VIDEOPLAYER, mockWebViewApp.EVENT_CATEGORIES.get(0));
    assertEquals("Event ID should be completed", VideoPlayerEvent.COMPLETED, mockWebViewApp.EVENTS.get(mockWebViewApp.EVENTS.size() - 1));
    assertEquals("The video url and the url received from the completed event should be the same", validUrl, mockWebViewApp.EVENT_PARAMS[0]);
    assertNotNull("Info events should not be NULL", mockWebViewApp.INFO_EVENTS);
    assertTrue("There should be at least one INFO event received", mockWebViewApp.INFO_EVENTS.size() > 0);
    assertTrue("Didn't get activity finish", waitForActivityFinish(activity));
}
项目:unity-ads-android    文件:VideoViewTest.java   
@Test
@RequiresDevice
@SdkSuppress(minSdkVersion = 17)
public void testDisableInfoListener () throws Exception {
    final Activity activity = waitForActivityStart(null);

    WebViewApp.setCurrentApp(new MockWebViewApp() {
        @Override
        public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
            super.sendEvent(eventCategory, eventId, params);

            if ("ON_FOCUS_GAINED".equals(eventId.name()) || "ON_FOCUS_LOST".equals(eventId.name())) {
                return true;
            }

            EVENT_CATEGORIES.add(eventCategory);
            EVENTS.add(eventId);
            EVENT_PARAMS = params;
            EVENT_COUNT++;

            if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PREPARED)) {
                VIDEOPLAYER_VIEW.play();
            }
            if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.INFO)) {
                INFO_EVENTS = new ArrayList<>();
                INFO_EVENTS.add((Integer) params[1]);
            }
            if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.COMPLETED)) {
                CONDITION_VARIABLE.open();
            }

            return true;
        }
    });

    final String validUrl = TestUtilities.getTestServerAddress() + "/blue_test_trailer.mp4";

    final Handler handler = new Handler(Looper.getMainLooper());
    final ConditionVariable viewAddCV = new ConditionVariable();
    handler.post(new Runnable() {
        @Override
        public void run() {
            ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW = new VideoPlayerView(getInstrumentation().getTargetContext());
            activity.addContentView(((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            viewAddCV.open();
        }
    });
    boolean success = viewAddCV.block(3000);
    assertTrue("ConditionVariable did not open in view add", success);

    final MockWebViewApp mockWebViewApp = (MockWebViewApp)WebViewApp.getCurrentApp();
    ConditionVariable cv = new ConditionVariable();
    mockWebViewApp.CONDITION_VARIABLE = cv;
    ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW.setInfoListenerEnabled(true);
    ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW.setInfoListenerEnabled(false);
    ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW.prepare(validUrl, 1f, 0);
    success = cv.block(30000);

    assertTrue("Condition Variable was not opened: COMPLETED or PREPARE ERROR event was not received", success);
    assertEquals("Event category should be videoplayer category", WebViewEventCategory.VIDEOPLAYER, mockWebViewApp.EVENT_CATEGORIES.get(0));
    assertEquals("Event ID should be completed", VideoPlayerEvent.COMPLETED, mockWebViewApp.EVENTS.get(mockWebViewApp.EVENTS.size() - 1));
    assertEquals("The video url and the url received from the completed event should be the same", validUrl, mockWebViewApp.EVENT_PARAMS[0]);
    assertNull("No info-events shoul've been received", mockWebViewApp.INFO_EVENTS);
    assertTrue("Didn't get activity finish", waitForActivityFinish(activity));
}
项目:unity-ads-android    文件:VideoViewTest.java   
@Test
@RequiresDevice
@SdkSuppress(minSdkVersion = 17)
public void testEnableInfoListener () throws Exception {
    final Activity activity = waitForActivityStart(null);

    WebViewApp.setCurrentApp(new MockWebViewApp() {
        @Override
        public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
            super.sendEvent(eventCategory, eventId, params);

            if ("ON_FOCUS_GAINED".equals(eventId.name()) || "ON_FOCUS_LOST".equals(eventId.name())) {
                return true;
            }

            EVENT_CATEGORIES.add(eventCategory);
            EVENTS.add(eventId);
            EVENT_PARAMS = params;
            EVENT_COUNT++;

            if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PREPARED)) {
                VIDEOPLAYER_VIEW.play();
            }
            if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.INFO)) {
                INFO_EVENTS = new ArrayList<>();
                INFO_EVENTS.add((Integer) params[1]);
            }
            if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.COMPLETED)) {
                CONDITION_VARIABLE.open();
            }

            return true;
        }
    });

    final String validUrl = TestUtilities.getTestServerAddress() + "/blue_test_trailer.mp4";

    final Handler handler = new Handler(Looper.getMainLooper());
    final ConditionVariable viewAddCV = new ConditionVariable();
    handler.post(new Runnable() {
        @Override
        public void run() {
            ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW = new VideoPlayerView(getInstrumentation().getTargetContext());
            activity.addContentView(((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            viewAddCV.open();
        }
    });
    boolean success = viewAddCV.block(3000);
    assertTrue("ConditionVariable did not open in view add", success);

    final MockWebViewApp mockWebViewApp = (MockWebViewApp)WebViewApp.getCurrentApp();
    ConditionVariable cv = new ConditionVariable();
    mockWebViewApp.CONDITION_VARIABLE = cv;
    ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW.setInfoListenerEnabled(false);
    ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW.setInfoListenerEnabled(true);
    ((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW.prepare(validUrl, 1f, 0);
    success = cv.block(30000);

    assertTrue("Condition Variable was not opened: COMPLETED or PREPARE ERROR event was not received", success);
    assertEquals("Event category should be videoplayer category", WebViewEventCategory.VIDEOPLAYER, mockWebViewApp.EVENT_CATEGORIES.get(0));
    assertEquals("Event ID should be completed", VideoPlayerEvent.COMPLETED, mockWebViewApp.EVENTS.get(mockWebViewApp.EVENTS.size() - 1));
    assertEquals("The video url and the url received from the completed event should be the same", validUrl, mockWebViewApp.EVENT_PARAMS[0]);
    assertNotNull("Info events should not be NULL", mockWebViewApp.INFO_EVENTS);
    assertTrue("There should be at least one INFO event received", mockWebViewApp.INFO_EVENTS.size() > 0);
    assertTrue("Didn't get activity finish", waitForActivityFinish(activity));
}
项目:unity-ads-android    文件:VideoViewTest.java   
@Test
@RequiresDevice
public void testInfoListenerTooLowApiLevel () throws Exception {
    if (Build.VERSION.SDK_INT < 17) {
        WebViewApp.setCurrentApp(new MockWebViewApp() {
            @Override
            public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
                super.sendEvent(eventCategory, eventId, params);
                return true;
            }

            @Override
            public boolean invokeCallback(Invocation invocation) {

                for (ArrayList<Object> response : invocation.getResponses()) {
                    CallbackStatus status = (CallbackStatus) response.get(0);
                    Enum error = (Enum) response.get(1);

                    if (status.equals(CallbackStatus.ERROR) && error.equals(VideoPlayerError.API_LEVEL_ERROR)) {
                        CONDITION_VARIABLE.open();
                    }

                    break;
                }

                return true;
            }
        });

        final MockWebViewApp mockWebViewApp = (MockWebViewApp)WebViewApp.getCurrentApp();

        ConditionVariable cv = new ConditionVariable();
        mockWebViewApp.CONDITION_VARIABLE = cv;

        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            @Override
            public void run() {
                Invocation i = new Invocation();
                VideoPlayer.setInfoListenerEnabled(true, new WebViewCallback("test", i.getId()));
                i.sendInvocationCallback();
            }
        });

        boolean success = cv.block(30000);
        assertTrue("Condition Variable was not opened: ERROR event was not received", success);
    }
    else {
        DeviceLog.debug("Skipping test \"testInfoListenerTooLowApiLevel\", API level too high: " + Build.VERSION.SDK_INT);
    }
}
项目:android-groovy-dagger-espresso-demo    文件:SpockTestRequestBuilder.java   
RequiresDeviceFilter() {
    super(RequiresDevice.class);
}
项目:android-proxy    文件:BasicAppTests.java   
@SuppressWarnings("unchecked")
@Test
@RequiresDevice
public void testsEnableStaticProxyForWifiNetwork()
{
    assertTrue(APL.getWifiManager().isWifiEnabled());

    openDrawer(R.id.drawer_layout);
    onView(withText(R.string.wifi_networks)).perform(click());

    Map<APLNetworkId, WiFiApConfig> configuredNetworks = APL.getWifiAPConfigurations();
    assertTrue(App.getDBManager().getProxiesCount() > 0);
    assertTrue(configuredNetworks.size() > 0);

    WiFiApConfig selectedWifiApConfig = null;
    ProxyEntity selectedProxyEntity = App.getDBManager().getRandomProxy();

    for (APLNetworkId networkId : configuredNetworks.keySet())
    {
        WiFiApConfig wifiApConfig = configuredNetworks.get(networkId);

        if ((wifiApConfig.getSecurityType() != SecurityType.SECURITY_EAP)
                && wifiApConfig.getProxySetting() == ProxySetting.NONE)
        {
            selectedWifiApConfig = wifiApConfig;
            break;
        }
    }

    assertNotNull(selectedWifiApConfig);
    assertNotNull(selectedProxyEntity);

    // Enable proxy
    onData(hasToString(containsString(String.format("SSID: %s\n",selectedWifiApConfig.getSSID()))))
            .inAdapterView(withId(android.R.id.list))
            .perform(click());

    onView(withId(R.id.wifi_name)).check(matches(withText(selectedWifiApConfig.getSSID())));

    onView(withId(R.id.wifi_proxy_switch)).perform(click());
    onView(withId(R.id.proxy_selector)).perform(click());

    onData(hasToString(containsString(String.format("%s", selectedProxyEntity.getHost()))))
            .inAdapterView(allOf(withId(android.R.id.list), isDescendantOfA(withId(R.id.static_proxy_list))))
            .perform(click());

    onView(isRoot()).perform(ViewActions.pressBack());


    // Disable proxy
    onData(hasToString(containsString(String.format("SSID: %s\n",selectedWifiApConfig.getSSID()))))
            .inAdapterView(withId(android.R.id.list))
            .perform(click());

    onView(withId(R.id.wifi_name)).check(matches(withText(selectedWifiApConfig.getSSID())));
    onView(withId(R.id.wifi_proxy_switch)).perform(click());

    onView(isRoot()).perform(ViewActions.pressBack());

    ViewActions.pressKey(KeyEvent.KEYCODE_HOME);
}
项目:android-proxy    文件:BasicAppTests.java   
@SuppressWarnings("unchecked")
@Test
@RequiresDevice
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.LOLLIPOP)
public void testsEnablePACProxyForWifiNetwork()
{
    assertTrue(APL.getWifiManager().isWifiEnabled());

    openDrawer(R.id.drawer_layout);
    onView(withText(R.string.wifi_networks)).perform(click());

    Map<APLNetworkId, WiFiApConfig> configuredNetworks = APL.getWifiAPConfigurations();

    assertTrue(App.getDBManager().getPacCount() > 0);
    assertTrue(configuredNetworks.size() > 0);

    WiFiApConfig selectedWifiApConfig = null;
    PacEntity selectedPacProxyEntity = App.getDBManager().getRandomPac();

    for (APLNetworkId networkId : configuredNetworks.keySet())
    {
        WiFiApConfig wifiApConfig = configuredNetworks.get(networkId);

        if ((wifiApConfig.getSecurityType() != SecurityType.SECURITY_EAP)
                && wifiApConfig.getProxySetting() == ProxySetting.NONE)
        {
            selectedWifiApConfig = wifiApConfig;
            break;
        }
    }

    assertNotNull(selectedWifiApConfig);
    assertNotNull(selectedPacProxyEntity);

    onData(hasToString(containsString(String.format("SSID: %s\n",selectedWifiApConfig.getSSID()))))
            .inAdapterView(withId(android.R.id.list))
            .perform(click());

    onView(withId(R.id.wifi_name)).check(matches(withText(selectedWifiApConfig.getSSID())));

    onView(withId(R.id.wifi_proxy_switch)).perform(click());
    onView(withId(R.id.proxy_selector)).perform(click());

    onView(withText(R.string.pac_proxies)).perform(click());

    onData(hasToString(containsString(String.format("%s",selectedPacProxyEntity.getPacUriFile().toString()))))
            .inAdapterView(allOf(withId(android.R.id.list), isDescendantOfA(withId(R.id.pac_proxy_list))))
            .perform(click());

    onView(isRoot()).perform(ViewActions.pressBack());

    // Disable proxy
    onData(hasToString(containsString(String.format("SSID: %s\n",selectedWifiApConfig.getSSID()))))
            .inAdapterView(withId(android.R.id.list))
            .perform(click());

    onView(withId(R.id.wifi_name)).check(matches(withText(selectedWifiApConfig.getSSID())));
    onView(withId(R.id.wifi_proxy_switch)).perform(click());

    onView(isRoot()).perform(ViewActions.pressBack());
}
项目:akvo-caddisfly    文件:SensorInstructions.java   
@Test
    @RequiresDevice
    public void testInstructionsAll() {

        goToMainScreen();

        onView(withText(getString(mActivityTestRule.getActivity(), R.string.sensors))).perform(click());

        TestConfigRepository testConfigRepository = new TestConfigRepository();
        List<TestInfo> testList = testConfigRepository.getTests(TestType.SENSOR);

        for (int i = 0; i < TestConstants.SENSOR_TESTS_COUNT; i++) {

            assertEquals(testList.get(i).getSubtype(), TestType.SENSOR);

            String id = testList.get(i).getUuid();
            id = id.substring(id.lastIndexOf("-") + 1, id.length());

            int pages = navigateToTest(i, id);

            jsArrayString.append("[").append("\"").append(id).append("\",").append(pages).append("],");
        }

//        Log.e("Caddisfly", jsArrayString.toString());

    }
项目:akvo-caddisfly    文件:ChamberInstructions.java   
@Test
    @RequiresDevice
    public void testInstructionsBackcase2() {

        goToMainScreen();

        gotoSurveyForm();

        clickExternalSourceButton(TestConstantKeys.NEXT);

        clickExternalSourceButton(0);

        sleep(1000);

        mDevice.waitForIdle();

        TestUtil.sleep(1000);

        String id = Constants.FREE_CHLORINE_ID.substring(
                Constants.FREE_CHLORINE_ID.lastIndexOf("-") + 1, Constants.FREE_CHLORINE_ID.length());

        takeScreenshot(id, -1);

        mDevice.waitForIdle();

        onView(withText(R.string.cannotStartTest)).check(matches(isDisplayed()));

//        onView(withText(getString(mActivityTestRule.getActivity(), R.string.instructions))).perform(click());

//        for (int i = 0; i < 17; i++) {
//
//            try {
//                takeScreenshot(id, i);
//
//                onView(withId(R.id.image_pageRight)).perform(click());
//
//            } catch (Exception e) {
//                TestUtil.sleep(600);
//                Espresso.pressBack();
//                break;
//            }
//        }
    }
项目:akvo-caddisfly    文件:ChamberInstructions.java   
@Test
    @RequiresDevice
    public void testInstructionsAll() {

        goToMainScreen();

        onView(withText(getString(mActivityTestRule.getActivity(), R.string.stripTest))).perform(click());

        TestConfigRepository testConfigRepository = new TestConfigRepository();
        List<TestInfo> testList = testConfigRepository.getTests(TestType.STRIP_TEST);

        for (int i = 0; i < TestConstants.STRIP_TESTS_COUNT; i++) {

            assertEquals(testList.get(i).getSubtype(), TestType.STRIP_TEST);

            String id = testList.get(i).getUuid();
            id = id.substring(id.lastIndexOf("-") + 1, id.length());

            int pages = navigateToTest(i, id);

            jsArrayString.append("[").append("\"").append(id).append("\",").append(pages).append("],");
        }

//        Log.e("Caddisfly", jsArrayString.toString());

    }
项目:akvo-caddisfly    文件:MiscTest.java   
@Test
@RequiresDevice
public void testSwatches() {

    onView(withId(R.id.actionSettings)).perform(click());

    onView(withText(R.string.about)).check(matches(isDisplayed())).perform(click());

    enterDiagnosticMode();

    goToMainScreen();

    onView(withText(R.string.calibrate)).perform(click());

    onView(withText(currentHashMap.get("fluoride"))).perform(click());

    if (TestUtil.isEmulator()) {

        onView(withText(R.string.errorCameraFlashRequired))
                .inRoot(withDecorView(not(is(mActivityRule.getActivity().getWindow()
                        .getDecorView())))).check(matches(isDisplayed()));
        return;
    }

    onView(withId(R.id.actionSwatches)).perform(click());

    Espresso.pressBack();

    onView(withId(R.id.actionSwatches)).check(matches(isDisplayed()));

    Espresso.pressBack();
}
项目:akvo-caddisfly    文件:BluetoothInstructions.java   
@Test
    @RequiresDevice
    @Ignore
    public void testInstructionsAll() {

        String path = Environment.getExternalStorageDirectory().getPath() + "/Akvo Caddisfly/screenshots";

        File folder = new File(path);
        if (!folder.exists()) {
            //noinspection ResultOfMethodCallIgnored
            folder.mkdirs();
        }

        mDevice.waitForWindowUpdate("", 2000);

        goToMainScreen();

        onView(withText("MD 610 Photometer")).perform(click());

        TestConfigRepository testConfigRepository = new TestConfigRepository();
        List<TestInfo> testList = testConfigRepository.getTests(TestType.BLUETOOTH);
        for (int i = 0; i < TestConstants.MD610_TESTS_COUNT; i++) {

            assertEquals(testList.get(i).getSubtype(), TestType.BLUETOOTH);

            String id = testList.get(i).getUuid();

            id = id.substring(id.lastIndexOf("-") + 1, id.length());

            int pages = navigateToTest(i, id);

            jsArrayString.append("[").append("\"").append(id).append("\",").append(pages).append("],");

        }

//        Log.d("Caddisfly", jsArrayString.toString());

    }
项目:akvo-caddisfly    文件:SensorTest.java   
@Test
@RequiresDevice
public void testSensorFromSurvey() {

    gotoSurveyForm();

    TestUtil.nextSurveyPage(7);

    clickExternalSourceButton("useExternalSource");

    SystemClock.sleep(6000);

    onView(allOf(withId(R.id.textTitle), withText("Water - Electrical Conductivity"))).check(matches(isDisplayed()));

    if (TestUtil.isEmulator()) {

        mDevice.pressBack();

        return;
    }

    onView(allOf(withId(R.id.textToolbarTitle), withText("Sensor!"))).check(matches(isDisplayed()));

    onView(allOf(withId(R.id.textSubtitle), withText("Sensor connected"))).check(matches(isDisplayed()));

    onView(allOf(withId(R.id.textUnit), withText("μS/cm"))).check(matches(isDisplayed()));

    onView(allOf(withId(R.id.textUnit2), withText("°Celsius"))).check(matches(isDisplayed()));

    onView(withId(R.id.buttonAcceptResult)).perform(click()).check(matches(isDisplayed()));

}
项目:akvo-caddisfly    文件:SensorTest.java   
@Test
@RequiresDevice
public void testEC() {

    goToMainScreen();

    mDevice.waitForWindowUpdate("", 2000);

    onView(withText(R.string.sensors)).perform(click());

    onView(withText(currentHashMap.get("electricalConductivity"))).perform(click());

    onView(withText(R.string.electricalConductivity)).check(matches(isDisplayed()));

    mDevice.waitForWindowUpdate("", 2000);

    onView(withText(R.string.deviceConnectSensor)).check(matches(isDisplayed()));

    mDevice.waitForWindowUpdate("", 2000);

    onView(withContentDescription(mActivityRule.getActivity()
            .getString(R.string.deviceConnectSensor))).check(matches(isDisplayed()));

    Espresso.pressBack();

    Espresso.pressBack();

}
项目:akvo-caddisfly    文件:DiagnosticTest.java   
@Test
@RequiresDevice
public void testDiagnosticMode() {

    onView(withId(R.id.actionSettings)).perform(click());

    onView(withText(R.string.about)).check(matches(isDisplayed())).perform(click());

    for (int i = 0; i < 10; i++) {
        onView(withId(R.id.textVersion)).perform(click());
    }

    goToMainScreen();

    onView(withId(R.id.fabDisableDiagnostics)).check(matches(isDisplayed()));

    goToMainScreen();

    onView(withText(R.string.calibrate)).perform(click());

    onView(withText(currentHashMap.get("fluoride"))).perform(click());

    if (TestUtil.isEmulator()){

        onView(withText(R.string.errorCameraFlashRequired))
                .inRoot(withDecorView(not(is(mActivityRule.getActivity().getWindow()
                        .getDecorView())))).check(matches(isDisplayed()));
        return;
    }

    onView(withId(R.id.actionSwatches)).perform(click());

}
项目:akvo-caddisfly    文件:SurveyTest.java   
@Test
    @RequiresDevice
    public void testChangeTestType() {

        onView(withText(R.string.calibrate)).perform(click());

        onView(withText(currentHashMap.get("fluoride"))).perform(click());

        if (TestUtil.isEmulator()) {

            onView(withText(R.string.errorCameraFlashRequired))
                    .inRoot(withDecorView(not(is(mActivityRule.getActivity().getWindow()
                            .getDecorView())))).check(matches(isDisplayed()));
            return;
        }

        DecimalFormatSymbols dfs = new DecimalFormatSymbols();

        onView(allOf(withId(R.id.calibrationList),
                childAtPosition(withClassName(is("android.widget.RelativeLayout")),
                        3))).perform(actionOnItemAtPosition(4, click()));

//        onView(withText("0" + dfs.getDecimalSeparator() + "0 mg/l")).check(matches(isDisplayed()));

        Espresso.pressBack();

        Espresso.pressBack();

        Espresso.pressBack();

        onView(withText(R.string.calibrate)).perform(click());

//        onView(withText(currentHashMap.get("chlorine"))).perform(click());

        onView(withText("Caddisfly, 0 - 1")).perform(click());

        onView(withText("1" + dfs.getDecimalSeparator() + "00")).check(matches(isDisplayed()));

//        onView(withText("0" + dfs.getDecimalSeparator() + "5 mg/l")).check(matches(isDisplayed()));

    }
项目:akvo-caddisfly    文件:SurveyTest.java   
@Test
@RequiresDevice
public void testStartASurvey() {

    saveCalibration("TestValid", Constants.FLUORIDE_ID);

    onView(withId(R.id.actionSettings)).perform(click());

    onView(withText(R.string.about)).check(matches(isDisplayed())).perform(click());

    enterDiagnosticMode();

    goToMainScreen();

    onView(withText(R.string.calibrate)).perform(click());

    onView(withText(currentHashMap.get("fluoride"))).perform(click());

    if (TestUtil.isEmulator()) {

        onView(withText(R.string.errorCameraFlashRequired))
                .inRoot(withDecorView(not(is(mActivityRule.getActivity().getWindow()
                        .getDecorView())))).check(matches(isDisplayed()));
        return;
    }

    onView(withId(R.id.menuLoad)).perform(click());

    sleep(1000);

    onData(hasToString(startsWith("TestValid"))).perform(click());

    goToMainScreen();

    gotoSurveyForm();

    clickExternalSourceButton(0);

    onView(withId(R.id.button_prepare)).check(matches(isDisplayed()));

    onView(withId(R.id.button_prepare)).perform(click());

    onView(withId(R.id.buttonNoDilution)).check(matches(isDisplayed()));

    onView(withId(R.id.buttonDilution1)).check(matches(isDisplayed()));

    onView(withId(R.id.buttonDilution2)).check(matches(isDisplayed()));

    onView(withId(R.id.buttonNoDilution)).perform(click());

    //onView(withId(R.id.buttonStart)).perform(click());

    mDevice.waitForWindowUpdate("", 1000);

}
项目:akvo-caddisfly    文件:MiscTest.java   
@Test
    @RequiresDevice
    public void testRestartAppDuringAnalysis() {

        onView(withText(R.string.calibrate)).perform(click());

        onView(withText(currentHashMap.get("fluoride"))).perform(click());

        if (TestUtil.isEmulator()) {

            onView(withText(R.string.errorCameraFlashRequired))
                    .inRoot(withDecorView(not(is(mActivityRule.getActivity().getWindow()
                            .getDecorView())))).check(matches(isDisplayed()));
            return;
        }

        DecimalFormatSymbols dfs = new DecimalFormatSymbols();

        onView(withId(R.id.fabEditCalibration)).perform(click());

        onView(withId(R.id.editBatchCode))
                .perform(typeText("TEST 123#*@!"), closeSoftKeyboard());

        onView(withId(R.id.editExpiryDate)).perform(click());

        onView(withClassName((Matchers.equalTo(DatePicker.class.getName()))))
                .perform(PickerActions.setDate(2025, 8, 25));

        onView(withId(android.R.id.button1)).perform(click());

        onView(withText(R.string.save)).perform(click());

        onView(allOf(withId(R.id.calibrationList),
                childAtPosition(withClassName(is("android.widget.RelativeLayout")),
                        3))).perform(actionOnItemAtPosition(4, click()));

//        onView(withText("2" + dfs.getDecimalSeparator() + "0 mg/l")).perform(click());

        //onView(withId(R.id.buttonStart)).perform(click());

        mDevice.pressHome();

        try {
            mDevice.pressRecentApps();
        } catch (RemoteException e) {
            Timber.e(e);
        }

        sleep(2000);

        mDevice.click(mDevice.getDisplayWidth() / 2, (mDevice.getDisplayHeight() / 2) + 300);

        mDevice.click(mDevice.getDisplayWidth() / 2, (mDevice.getDisplayHeight() / 2) + 300);

        mDevice.click(mDevice.getDisplayWidth() / 2, (mDevice.getDisplayHeight() / 2) + 300);

        mDevice.waitForWindowUpdate("", 1000);

        //clickListViewItem("Automated Tests");

        clickListViewItem("test caddisfly");

    }
项目:akvo-caddisfly    文件:CalibrationTest.java   
@Test
@RequiresDevice
@Ignore
public void testOutOfSequence() {

    saveCalibration("OutOfSequence", Constants.FLUORIDE_ID);

    goToMainScreen();

    onView(withId(R.id.actionSettings)).perform(click());

    onView(withText(R.string.about)).check(matches(isDisplayed())).perform(click());

    enterDiagnosticMode();

    goToMainScreen();

    onView(withText(R.string.calibrate)).perform(click());

    sleep(4000);

    onView(withText(currentHashMap.get(TestConstant.FLUORIDE))).perform(click());

    if (TestUtil.isEmulator()){

        onView(withText(R.string.errorCameraFlashRequired))
                .inRoot(withDecorView(not(is(mActivityRule.getActivity().getWindow()
                        .getDecorView())))).check(matches(isDisplayed()));
        return;
    }

    onView(withId(R.id.menuLoad)).perform(click());

    sleep(2000);

    onData(hasToString(startsWith("OutOfSequence"))).perform(click());

    sleep(2000);

    onView(withText(String.format("%s. %s", mActivityRule.getActivity().getString(R.string.calibrationIsInvalid),
            mActivityRule.getActivity().getString(R.string.tryRecalibrating)))).check(matches(isDisplayed()));

    onView(withId(R.id.menuLoad)).perform(click());

    sleep(2000);

    onData(hasToString(startsWith("TestValid"))).perform(click());

    sleep(2000);

    onView(withText(String.format("%s. %s", mActivityRule.getActivity().getString(R.string.calibrationIsInvalid),
            mActivityRule.getActivity().getString(R.string.tryRecalibrating)))).check(matches(not(isDisplayed())));

    sleep(2000);

    leaveDiagnosticMode();

    onView(withText(R.string.calibrate)).perform(click());

}
项目:akvo-caddisfly    文件:SensorTest.java   
@Test
@RequiresDevice
public void surveyQuestions() {

    goToMainScreen();

    gotoSurveyForm();

    TestUtil.nextSurveyPage(7);

    clickExternalSourceButton(0);

    onView(withText("Next")).perform(click());

    SystemClock.sleep(12000);

    onView(allOf(withId(R.id.textToolbarTitle), withText("Sensor"))).check(matches(isDisplayed()));

    onView(allOf(withId(R.id.textTitle), withText("Water - Electrical Conductivity"))).check(matches(isDisplayed()));

    if (TestUtil.isEmulator()) {
        return;
    }

    onView(allOf(withId(R.id.textSubtitle), withText("Sensor connected"))).check(matches(isDisplayed()));

    onView(allOf(withId(R.id.textUnit), withText("μS/cm"))).check(matches(isDisplayed()));

    onView(allOf(withId(R.id.textUnit2), withText("°Celsius"))).check(matches(isDisplayed()));

    onView(withId(R.id.buttonAcceptResult)).perform(click());

    clickExternalSourceButton(1);

    SystemClock.sleep(12000);

    onView(allOf(withId(R.id.textToolbarTitle), withText("Sensor"))).check(matches(isDisplayed()));

    onView(allOf(withId(R.id.textTitle), withText("Soil - Electrical Conductivity"))).check(matches(isDisplayed()));

    onView(allOf(withId(R.id.textSubtitle), withText("Sensor connected"))).check(matches(isDisplayed()));

    onView(allOf(withId(R.id.textUnit), withText("μS/cm"))).check(matches(isDisplayed()));

    onView(allOf(withId(R.id.textUnit2), withText("°Celsius"))).check(matches(isDisplayed()));

    onView(withId(R.id.buttonAcceptResult)).perform(click());

    clickExternalSourceButton(2);

    SystemClock.sleep(12000);

    onView(allOf(withId(R.id.textToolbarTitle), withText("Sensor"))).check(matches(isDisplayed()));

    onView(allOf(withId(R.id.textTitle), withText("Soil - Moisture"))).check(matches(isDisplayed()));

    onView(allOf(withId(R.id.textSubtitle), withText("Sensor connected"))).check(matches(isDisplayed()));

    onView(allOf(withId(R.id.textUnit), withText("% VWC"))).check(matches(isDisplayed()));

    onView(withId(R.id.textUnit2)).check(matches(not(isDisplayed())));

    onView(withId(R.id.buttonAcceptResult)).perform(click());

}