sample/src/androidTest/java/com/urbanairship/sample/SampleTest.java
@Test
    public void testInAppMessage() throws Exception {

        // Add tag action for yes interactive button
        ActionsPayload yesActions = ActionsPayload.newBuilder()
                                                  .addTag("YES_INTERACTIVE_BUTTON_TAG")
                                                  .build();

        // Add tag action for no interactive button
        ActionsPayload noActions = ActionsPayload.newBuilder()
                                                 .addTag("NO_INTERACTIVE_BUTTON_TAG")
                                                 .build();

        // Landing page action for opening in-app message
        ActionsPayload openActions = ActionsPayload.newBuilder()
                                                   .setLandingPage("Hi!")
                                                   .build();

        InAppMessagePayload inAppMessagePayload = InAppMessagePayload.newBuilder()
                                                                     .setAlert("in-app test")
                                                                     .setInteractiveType("ua_yes_no_foreground")
                                                                     .addButtonActions("yes", yesActions)
                                                                     .addButtonActions("no", noActions)
                                                                     .setOpenActions(openActions)
                                                                     .build();

        PushPayload pushPayload = PushPayload.newChannelPushBuilder(channelId)
                                             .setAlert(UUID.randomUUID().toString())
                                             .setInAppMessage(inAppMessagePayload)
                                             .build();

        pushSender.send(pushPayload);
        if (airshipReceiver.postedAlerts.poll(15, TimeUnit.SECONDS) == null) {
            fail("Unable to send in-app message.");
        }

        // Wait for in-app message to be displayed
        Thread.sleep(TimeUnit.SECONDS.toMillis(1));

        clickAndVerifyTagAdded("Yes","YES_INTERACTIVE_BUTTON_TAG");

        // Test in-app message with interactive buttons
        pushSender.send(pushPayload);
        if (airshipReceiver.postedAlerts.poll(15, TimeUnit.SECONDS) == null) {
            fail("Unable to send in-app message.");
        }

        // Wait for in-app message to be displayed
        Thread.sleep(TimeUnit.SECONDS.toMillis(1));

        // Click the in-app message
        onView(withText(inAppMessagePayload.getAlert()))
                .perform(click());

        // Verify the landing page opens
        intended(hasAction("com.urbanairship.actions.SHOW_LANDING_PAGE_INTENT_ACTION"));

        // Close the landing page
        Espresso.pressBack();
    }
/**
     * Test an in-app message with landing page and interactive buttons.
     *
     * @throws Exception
     */
Test an in-app message with landing page and interactive buttons.
@throws Exception
Test an in - app message with landing page and interactive buttons . @throws Exception
@Test
    public void testInAppMessage() throws Exception {
        ActionsPayload yesActions = ActionsPayload.newBuilder()
                                                  .addTag("YES_INTERACTIVE_BUTTON_TAG")
                                                  .build();
        ActionsPayload noActions = ActionsPayload.newBuilder()
                                                 .addTag("NO_INTERACTIVE_BUTTON_TAG")
                                                 .build();
        ActionsPayload openActions = ActionsPayload.newBuilder()
                                                   .setLandingPage("Hi!")
                                                   .build();
        InAppMessagePayload inAppMessagePayload = InAppMessagePayload.newBuilder()
                                                                     .setAlert("in-app test")
                                                                     .setInteractiveType("ua_yes_no_foreground")
                                                                     .addButtonActions("yes", yesActions)
                                                                     .addButtonActions("no", noActions)
                                                                     .setOpenActions(openActions)
                                                                     .build();
        PushPayload pushPayload = PushPayload.newChannelPushBuilder(channelId)
                                             .setAlert(UUID.randomUUID().toString())
                                             .setInAppMessage(inAppMessagePayload)
                                             .build();
        pushSender.send(pushPayload);
        if (airshipReceiver.postedAlerts.poll(15, TimeUnit.SECONDS) == null) {
            fail("Unable to send in-app message.");
        }
        Thread.sleep(TimeUnit.SECONDS.toMillis(1));
        clickAndVerifyTagAdded("Yes","YES_INTERACTIVE_BUTTON_TAG");
        pushSender.send(pushPayload);
        if (airshipReceiver.postedAlerts.poll(15, TimeUnit.SECONDS) == null) {
            fail("Unable to send in-app message.");
        }
        Thread.sleep(TimeUnit.SECONDS.toMillis(1));
        onView(withText(inAppMessagePayload.getAlert()))
                .perform(click());
        intended(hasAction("com.urbanairship.actions.SHOW_LANDING_PAGE_INTENT_ACTION"));
        Espresso.pressBack();
    }
@ Test public void testInAppMessage ( ) throws Exception { ActionsPayload yesActions = ActionsPayload . newBuilder ( ) . addTag ( "YES_INTERACTIVE_BUTTON_TAG" ) . build ( ) ; ActionsPayload noActions = ActionsPayload . newBuilder ( ) . addTag ( "NO_INTERACTIVE_BUTTON_TAG" ) . build ( ) ; ActionsPayload openActions = ActionsPayload . newBuilder ( ) . setLandingPage ( "Hi!" ) . build ( ) ; InAppMessagePayload inAppMessagePayload = InAppMessagePayload . newBuilder ( ) . setAlert ( "in-app test" ) . setInteractiveType ( "ua_yes_no_foreground" ) . addButtonActions ( "yes" , yesActions ) . addButtonActions ( "no" , noActions ) . setOpenActions ( openActions ) . build ( ) ; PushPayload pushPayload = PushPayload . newChannelPushBuilder ( channelId ) . setAlert ( UUID . randomUUID ( ) . toString ( ) ) . setInAppMessage ( inAppMessagePayload ) . build ( ) ; pushSender . send ( pushPayload ) ; if ( airshipReceiver . postedAlerts . poll ( 15 , TimeUnit . SECONDS ) == null ) { fail ( "Unable to send in-app message." ) ; } Thread . sleep ( TimeUnit . SECONDS . toMillis ( 1 ) ) ; clickAndVerifyTagAdded ( "Yes" , "YES_INTERACTIVE_BUTTON_TAG" ) ; pushSender . send ( pushPayload ) ; if ( airshipReceiver . postedAlerts . poll ( 15 , TimeUnit . SECONDS ) == null ) { fail ( "Unable to send in-app message." ) ; } Thread . sleep ( TimeUnit . SECONDS . toMillis ( 1 ) ) ; onView ( withText ( inAppMessagePayload . getAlert ( ) ) ) . perform ( click ( ) ) ; intended ( hasAction ( "com.urbanairship.actions.SHOW_LANDING_PAGE_INTENT_ACTION" ) ) ; Espresso . pressBack ( ) ; }
Test an in-app message with landing page and interactive buttons.
Test an in - app message with landing page and interactive buttons .
// Add tag action for yes interactive button // Add tag action for no interactive button // Landing page action for opening in-app message // Wait for in-app message to be displayed // Test in-app message with interactive buttons // Wait for in-app message to be displayed // Click the in-app message // Verify the landing page opens // Close the landing page