From 93fafe6997028301b167baf0cb0dd7d3089fec07 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavliuchyk Date: Fri, 30 Apr 2021 16:54:35 +0300 Subject: [PATCH 1/3] fixing UI tests (DemoApp Java) --- .../org/prebid/mobile/app/DFPBannerTest.java | 26 ++++++------- .../mobile/app/DFPInterstitialTest.java | 26 ++++++------- .../org/prebid/mobile/app/DFPNativeTest.java | 38 ++++++++----------- .../prebid/mobile/app/MoPubBannerTest.java | 26 ++++++------- .../mobile/app/MoPubInterstitialTest.java | 26 ++++++------- .../prebid/mobile/app/MoPubNativeTest.java | 31 +++++++-------- .../app/RubiconBannerGamDemoActivity.java | 7 ++++ .../app/RubiconBannerMoPubDemoActivity.java | 6 +++ .../RubiconInterstitialGamDemoActivity.java | 7 ++++ .../RubiconInterstitialMoPubDemoActivity.java | 7 ++++ .../app/XandrNativeInAppGAMDemoActivity.java | 12 ++++++ .../XandrNativeInAppMoPubDemoActivity.java | 27 +++++++++---- 12 files changed, 140 insertions(+), 99 deletions(-) diff --git a/Example/PrebidDemoJava/src/androidTest/java/org/prebid/mobile/app/DFPBannerTest.java b/Example/PrebidDemoJava/src/androidTest/java/org/prebid/mobile/app/DFPBannerTest.java index d0025957a..2fd83e25e 100644 --- a/Example/PrebidDemoJava/src/androidTest/java/org/prebid/mobile/app/DFPBannerTest.java +++ b/Example/PrebidDemoJava/src/androidTest/java/org/prebid/mobile/app/DFPBannerTest.java @@ -51,15 +51,15 @@ public void testDFPBannerWithoutAutoRefreshAndSize300x250() throws Exception { onView(withId(R.id.autoRefreshInput)).perform(typeText("0")); onView(withId(R.id.showAd)).perform(click()); Thread.sleep(10000); - assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); + assertEquals(ResultCode.SUCCESS, ((RubiconBannerGamDemoActivity) TestUtil.getCurrentActivity()).resultCode); onView(withId(R.id.adFrame)) .check(matches(isDisplayed())) .check(matches(new ViewMinSizeMatcher(2, 2))); onWebView().check(webMatches(getCurrentUrl(), containsString("pubads.g.doubleclick.net/gampad/ads"))); onWebView().check(webContent(containingTextInBody("ucTag.renderAd"))); - assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(1, ((RubiconBannerGamDemoActivity) TestUtil.getCurrentActivity()).refreshCount); Thread.sleep(120000); - assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(1, ((RubiconBannerGamDemoActivity) TestUtil.getCurrentActivity()).refreshCount); } @Test @@ -70,14 +70,14 @@ public void testRubiconDFPBannerWithoutAutoRefreshAndSize300x250() throws Except onView(withId(R.id.autoRefreshInput)).perform(typeText("0")); onView(withId(R.id.showAd)).perform(click()); Thread.sleep(10000); - assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); + assertEquals(ResultCode.SUCCESS, ((RubiconBannerGamDemoActivity) TestUtil.getCurrentActivity()).resultCode); onView(withId(R.id.adFrame)) .check(matches(isDisplayed())) .check(matches(new ViewMinSizeMatcher(2, 2))); onWebView().check(webMatches(getCurrentUrl(), containsString("pubads.g.doubleclick.net/gampad/ads"))); onWebView().check(webContent(containingTextInBody("ucTag.renderAd"))); - assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(1, ((RubiconBannerGamDemoActivity) TestUtil.getCurrentActivity()).refreshCount); } @Test @@ -87,15 +87,15 @@ public void testDFPBannerWithoutAutoRefreshAndSize320x50() throws Exception { // onData(allOf(is(instanceOf(String.class)), is("320x50"))).perform(click()); onView(withId(R.id.showAd)).perform(click()); Thread.sleep(10000); - assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); + assertEquals(ResultCode.SUCCESS, ((RubiconBannerGamDemoActivity) TestUtil.getCurrentActivity()).resultCode); onView(withId(R.id.adFrame)) .check(matches(isDisplayed())) .check(matches(new ViewMinSizeMatcher(2, 2))); onWebView().check(webMatches(getCurrentUrl(), containsString("pubads.g.doubleclick.net/gampad/ads"))); onWebView().check(webContent(containingTextInBody("ucTag.renderAd"))); - assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(1, ((RubiconBannerGamDemoActivity) TestUtil.getCurrentActivity()).refreshCount); Thread.sleep(120000); - assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(1, ((RubiconBannerGamDemoActivity) TestUtil.getCurrentActivity()).refreshCount); } @Test @@ -103,18 +103,18 @@ public void testDFPBannerWithAutoRefreshAndSize300x250() throws Exception { onView(withId(R.id.autoRefreshInput)).perform(typeText("30000")); onView(withId(R.id.showAd)).perform(click()); Thread.sleep(10000); - assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); + assertEquals(ResultCode.SUCCESS, ((RubiconBannerGamDemoActivity) TestUtil.getCurrentActivity()).resultCode); onView(withId(R.id.adFrame)) .check(matches(isDisplayed())) .check(matches(new ViewMinSizeMatcher(2, 2))); onWebView().check(webMatches(getCurrentUrl(), containsString("pubads.g.doubleclick.net/gampad/ads"))); onWebView().check(webContent(containingTextInBody("ucTag.renderAd"))); - assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(1, ((RubiconBannerGamDemoActivity) TestUtil.getCurrentActivity()).refreshCount); Thread.sleep(120000); - assertEquals(5, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); - ((DemoActivity) TestUtil.getCurrentActivity()).stopAutoRefresh(); + assertEquals(5, ((RubiconBannerGamDemoActivity) TestUtil.getCurrentActivity()).refreshCount); + ((RubiconBannerGamDemoActivity) TestUtil.getCurrentActivity()).adUnit.stopAutoRefresh(); Thread.sleep(12000); - assertEquals(5, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(5, ((RubiconBannerGamDemoActivity) TestUtil.getCurrentActivity()).refreshCount); } } diff --git a/Example/PrebidDemoJava/src/androidTest/java/org/prebid/mobile/app/DFPInterstitialTest.java b/Example/PrebidDemoJava/src/androidTest/java/org/prebid/mobile/app/DFPInterstitialTest.java index a06214a93..0dc6c8a08 100644 --- a/Example/PrebidDemoJava/src/androidTest/java/org/prebid/mobile/app/DFPInterstitialTest.java +++ b/Example/PrebidDemoJava/src/androidTest/java/org/prebid/mobile/app/DFPInterstitialTest.java @@ -16,15 +16,15 @@ package org.prebid.mobile.app; +import androidx.test.espresso.Espresso; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.rule.ActivityTestRule; + import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.prebid.mobile.ResultCode; -import androidx.test.espresso.Espresso; -import androidx.test.ext.junit.runners.AndroidJUnit4; -import androidx.test.rule.ActivityTestRule; - import static androidx.test.espresso.Espresso.onData; import static androidx.test.espresso.Espresso.onView; import static androidx.test.espresso.action.ViewActions.click; @@ -60,9 +60,9 @@ public void testDFPInterstitialWithoutAutoRefresh() throws Exception { onWebView().check(webContent(containingTextInBody("ucTag.renderAd"))); Espresso.pressBack(); Thread.sleep(30000); - assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(1, ((RubiconInterstitialGamDemoActivity) TestUtil.getCurrentActivity()).refreshCount); } else if ("org.prebid.mobile.app.DemoActivity".equals(activityName)) { - assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); + assertEquals(ResultCode.SUCCESS, ((RubiconInterstitialGamDemoActivity) TestUtil.getCurrentActivity()).resultCode); fail("Prebid Demand was fetched successfully, but DFP interstitial not loaded and show successfully"); } else { fail("Demo app not working properly."); @@ -81,27 +81,27 @@ public void testDFPInterstitialWithAutoRefresh() throws Exception { onWebView().check(webMatches(getCurrentUrl(), containsString("pubads.g.doubleclick.net/gampad/ads"))); onWebView().check(webContent(containingTextInBody("ucTag.renderAd"))); Espresso.pressBack(); - assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(1, ((RubiconInterstitialGamDemoActivity) TestUtil.getCurrentActivity()).refreshCount); Thread.sleep(30000); activityName = TestUtil.getCurrentActivity().getClass().getName(); if ("com.google.android.gms.ads.AdActivity".equals(activityName)) { onWebView().check(webMatches(getCurrentUrl(), containsString("pubads.g.doubleclick.net/gampad/ads"))); onWebView().check(webContent(containingTextInBody("ucTag.renderAd"))); Espresso.pressBack(); - assertEquals("Auto refresh not happening", 2, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); - ((DemoActivity) TestUtil.getCurrentActivity()).stopAutoRefresh(); + assertEquals("Auto refresh not happening", 2, ((RubiconInterstitialGamDemoActivity) TestUtil.getCurrentActivity()).refreshCount); + ((RubiconInterstitialGamDemoActivity) TestUtil.getCurrentActivity()).adUnit.stopAutoRefresh(); Thread.sleep(30000); - assertEquals("Auto refresh didn't stop", 2, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals("Auto refresh didn't stop", 2, ((RubiconInterstitialGamDemoActivity) TestUtil.getCurrentActivity()).refreshCount); } else if ("org.prebid.mobile.app.DemoActivity".equals(activityName)) { - assertEquals("Auto refresh not happening", 2, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); - assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); + assertEquals("Auto refresh not happening", 2, ((RubiconInterstitialGamDemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(ResultCode.SUCCESS, ((RubiconInterstitialGamDemoActivity) TestUtil.getCurrentActivity()).resultCode); fail("Prebid Demand was fetched successfully, but DFP interstitial not loaded and show successfully"); } else { fail("Demo app not working properly."); } } else if ("org.prebid.mobile.app.DemoActivity".equals(activityName)) { - assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); + assertEquals(ResultCode.SUCCESS, ((RubiconInterstitialGamDemoActivity) TestUtil.getCurrentActivity()).resultCode); fail("Prebid Demand was fetched successfully, but DFP interstitial not loaded and show successfully"); } else { fail("Demo app not working properly."); diff --git a/Example/PrebidDemoJava/src/androidTest/java/org/prebid/mobile/app/DFPNativeTest.java b/Example/PrebidDemoJava/src/androidTest/java/org/prebid/mobile/app/DFPNativeTest.java index d2fc539c5..9714d84ff 100644 --- a/Example/PrebidDemoJava/src/androidTest/java/org/prebid/mobile/app/DFPNativeTest.java +++ b/Example/PrebidDemoJava/src/androidTest/java/org/prebid/mobile/app/DFPNativeTest.java @@ -16,7 +16,6 @@ package org.prebid.mobile.app; -import androidx.test.espresso.Espresso; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.rule.ActivityTestRule; @@ -30,18 +29,11 @@ import static androidx.test.espresso.action.ViewActions.click; import static androidx.test.espresso.action.ViewActions.typeText; import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static androidx.test.espresso.web.assertion.WebViewAssertions.webContent; -import static androidx.test.espresso.web.assertion.WebViewAssertions.webMatches; -import static androidx.test.espresso.web.matcher.DomMatchers.containingTextInBody; -import static androidx.test.espresso.web.model.Atoms.getCurrentUrl; -import static androidx.test.espresso.web.sugar.Web.onWebView; -import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.core.AllOf.allOf; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; @RunWith(AndroidJUnit4.class) public class DFPNativeTest { @@ -54,10 +46,10 @@ public void testAppNexusDFPNativeSanityAppCheckTest() throws Exception { onData(allOf(is(instanceOf(String.class)), is("Native"))).perform(click()); onView(withId(R.id.showAd)).perform(click()); Thread.sleep(10000); - assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); - assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); - assertTrue(((DemoActivity) TestUtil.getCurrentActivity()).request.getCustomTargeting().keySet().contains("hb_pb")); - assertTrue(((DemoActivity) TestUtil.getCurrentActivity()).request.getCustomTargeting().keySet().contains("hb_cache_id")); + assertEquals(1, ((XandrNativeInAppGAMDemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(ResultCode.SUCCESS, ((XandrNativeInAppGAMDemoActivity) TestUtil.getCurrentActivity()).resultCode); + assertTrue(((XandrNativeInAppGAMDemoActivity) TestUtil.getCurrentActivity()).request.getCustomTargeting().keySet().contains("hb_pb")); + assertTrue(((XandrNativeInAppGAMDemoActivity) TestUtil.getCurrentActivity()).request.getCustomTargeting().keySet().contains("hb_cache_id")); } @Test @@ -67,13 +59,13 @@ public void testDFPNativeWithValidAutoRefresh() throws Exception { onView(withId(R.id.autoRefreshInput)).perform(typeText("30000")); onView(withId(R.id.showAd)).perform(click()); Thread.sleep(10000); - assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); - assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); + assertEquals(1, ((XandrNativeInAppGAMDemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(ResultCode.SUCCESS, ((XandrNativeInAppGAMDemoActivity) TestUtil.getCurrentActivity()).resultCode); Thread.sleep(30000); - assertEquals("Auto refresh not happening", 2, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); - ((DemoActivity) TestUtil.getCurrentActivity()).stopAutoRefresh(); + assertEquals("Auto refresh not happening", 2, ((XandrNativeInAppGAMDemoActivity) TestUtil.getCurrentActivity()).refreshCount); + ((XandrNativeInAppGAMDemoActivity) TestUtil.getCurrentActivity()).adUnit.stopAutoRefresh(); Thread.sleep(30000); - assertEquals("Auto refresh didn't stop", 2, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals("Auto refresh didn't stop", 2, ((XandrNativeInAppGAMDemoActivity) TestUtil.getCurrentActivity()).refreshCount); } @Test @@ -83,10 +75,10 @@ public void testDFPNativeWithoutAutoRefresh() throws Exception { onView(withId(R.id.autoRefreshInput)).perform(typeText("0")); onView(withId(R.id.showAd)).perform(click()); Thread.sleep(10000); - assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); - assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); + assertEquals(1, ((XandrNativeInAppGAMDemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(ResultCode.SUCCESS, ((XandrNativeInAppGAMDemoActivity) TestUtil.getCurrentActivity()).resultCode); Thread.sleep(30000); - assertEquals("Auto refresh not happening", 1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals("Auto refresh not happening", 1, ((XandrNativeInAppGAMDemoActivity) TestUtil.getCurrentActivity()).refreshCount); } @Test @@ -96,10 +88,10 @@ public void testDFPNativeWithInvalidAutoRefresh() throws Exception { onView(withId(R.id.autoRefreshInput)).perform(typeText("20000")); onView(withId(R.id.showAd)).perform(click()); Thread.sleep(10000); - assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); - assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); + assertEquals(1, ((XandrNativeInAppGAMDemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(ResultCode.SUCCESS, ((XandrNativeInAppGAMDemoActivity) TestUtil.getCurrentActivity()).resultCode); Thread.sleep(30000); - assertEquals("Auto refresh not happening", 1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals("Auto refresh not happening", 1, ((XandrNativeInAppGAMDemoActivity) TestUtil.getCurrentActivity()).refreshCount); } } diff --git a/Example/PrebidDemoJava/src/androidTest/java/org/prebid/mobile/app/MoPubBannerTest.java b/Example/PrebidDemoJava/src/androidTest/java/org/prebid/mobile/app/MoPubBannerTest.java index 6567c6edf..288740650 100644 --- a/Example/PrebidDemoJava/src/androidTest/java/org/prebid/mobile/app/MoPubBannerTest.java +++ b/Example/PrebidDemoJava/src/androidTest/java/org/prebid/mobile/app/MoPubBannerTest.java @@ -56,13 +56,13 @@ public void testMoPubWithoutAutoRefreshAndSize300x250() throws Exception { onView(withId(R.id.autoRefreshInput)).perform(typeText("0")); onView(withId(R.id.showAd)).perform(click()); Thread.sleep(10000); - assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); + assertEquals(ResultCode.SUCCESS, ((RubiconBannerMoPubDemoActivity) TestUtil.getCurrentActivity()).resultCode); onView(withId(R.id.adFrame)).check(matches(isDisplayed())); onWebView().check(webMatches(getCurrentUrl(), containsString("ads.mopub.com"))); onWebView().check(webContent(containingTextInBody("ucTag.renderAd"))); - assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(1, ((RubiconBannerMoPubDemoActivity) TestUtil.getCurrentActivity()).refreshCount); Thread.sleep(120000); - assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(1, ((RubiconBannerMoPubDemoActivity) TestUtil.getCurrentActivity()).refreshCount); } @Test @@ -75,11 +75,11 @@ public void testRubiconMoPubWithoutAutoRefreshAndSize300x250() throws Exception onView(withId(R.id.autoRefreshInput)).perform(typeText("0")); onView(withId(R.id.showAd)).perform(click()); Thread.sleep(10000); - assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); + assertEquals(ResultCode.SUCCESS, ((RubiconBannerMoPubDemoActivity) TestUtil.getCurrentActivity()).resultCode); onView(withId(R.id.adFrame)).check(matches(isDisplayed())); onWebView().check(webMatches(getCurrentUrl(), containsString("ads.mopub.com"))); onWebView().check(webContent(containingTextInBody("ucTag.renderAd"))); - assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(1, ((RubiconBannerMoPubDemoActivity) TestUtil.getCurrentActivity()).refreshCount); } @Test @@ -91,13 +91,13 @@ public void testMoPubWithoutAutoRefreshAndSize320x50() throws Exception { onView(withId(R.id.autoRefreshInput)).perform(typeText("15000")); onView(withId(R.id.showAd)).perform(click()); Thread.sleep(10000); - assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); + assertEquals(ResultCode.SUCCESS, ((RubiconBannerMoPubDemoActivity) TestUtil.getCurrentActivity()).resultCode); onView(withId(R.id.adFrame)).check(matches(isDisplayed())); onWebView().check(webMatches(getCurrentUrl(), containsString("ads.mopub.com"))); onWebView().check(webContent(containingTextInBody("pbm.showAdFromCacheId"))); - assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(1, ((RubiconBannerMoPubDemoActivity) TestUtil.getCurrentActivity()).refreshCount); Thread.sleep(120000); - assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(1, ((RubiconBannerMoPubDemoActivity) TestUtil.getCurrentActivity()).refreshCount); } @Test @@ -107,15 +107,15 @@ public void testMoPubWithAutoRefreshAndSize300x250() throws Exception { onView(withId(R.id.autoRefreshInput)).perform(typeText("30000")); onView(withId(R.id.showAd)).perform(click()); Thread.sleep(10000); - assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); + assertEquals(ResultCode.SUCCESS, ((RubiconBannerMoPubDemoActivity) TestUtil.getCurrentActivity()).resultCode); onView(withId(R.id.adFrame)).check(matches(isDisplayed())); onWebView().check(webMatches(getCurrentUrl(), containsString("ads.mopub.com"))); onWebView().check(webContent(containingTextInBody("ucTag.renderAd"))); - assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(1, ((RubiconBannerMoPubDemoActivity) TestUtil.getCurrentActivity()).refreshCount); Thread.sleep(120000); - assertEquals(5, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); - ((DemoActivity) TestUtil.getCurrentActivity()).stopAutoRefresh(); + assertEquals(5, ((RubiconBannerMoPubDemoActivity) TestUtil.getCurrentActivity()).refreshCount); + ((RubiconBannerMoPubDemoActivity) TestUtil.getCurrentActivity()).adUnit.stopAutoRefresh(); Thread.sleep(120000); - assertEquals(5, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(5, ((RubiconBannerMoPubDemoActivity) TestUtil.getCurrentActivity()).refreshCount); } } diff --git a/Example/PrebidDemoJava/src/androidTest/java/org/prebid/mobile/app/MoPubInterstitialTest.java b/Example/PrebidDemoJava/src/androidTest/java/org/prebid/mobile/app/MoPubInterstitialTest.java index a7b1c2167..163c5a991 100644 --- a/Example/PrebidDemoJava/src/androidTest/java/org/prebid/mobile/app/MoPubInterstitialTest.java +++ b/Example/PrebidDemoJava/src/androidTest/java/org/prebid/mobile/app/MoPubInterstitialTest.java @@ -16,15 +16,15 @@ package org.prebid.mobile.app; +import androidx.test.espresso.Espresso; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.rule.ActivityTestRule; + import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.prebid.mobile.ResultCode; -import androidx.test.espresso.Espresso; -import androidx.test.ext.junit.runners.AndroidJUnit4; -import androidx.test.rule.ActivityTestRule; - import static androidx.test.espresso.Espresso.onData; import static androidx.test.espresso.Espresso.onView; import static androidx.test.espresso.action.ViewActions.click; @@ -62,9 +62,9 @@ public void testMoPubInterstitialWithoutAutoRefresh() throws Exception { onWebView().check(webContent(containingTextInBody("ucTag.renderAd"))); Espresso.pressBack(); Thread.sleep(30000); - assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(1, ((RubiconInterstitialMoPubDemoActivity) TestUtil.getCurrentActivity()).refreshCount); } else if ("org.prebid.mobile.app.DemoActivity".equals(currentActivityName)) { - assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); + assertEquals(ResultCode.SUCCESS, ((RubiconInterstitialMoPubDemoActivity) TestUtil.getCurrentActivity()).resultCode); fail("Prebid Demand was fetched successfully, but MoPub interstitial not loaded and show successfully"); } else { fail("Demo app not working properly"); @@ -85,26 +85,26 @@ public void testMoPubInterstitialWithAutoRefresh() throws Exception { onWebView().check(webMatches(getCurrentUrl(), containsString("ads.mopub.com"))); onWebView().check(webContent(containingTextInBody("ucTag.renderAd"))); Espresso.pressBack(); - assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(1, ((RubiconInterstitialMoPubDemoActivity) TestUtil.getCurrentActivity()).refreshCount); Thread.sleep(30000); activityName = TestUtil.getCurrentActivity().getClass().getName(); if ("com.mopub.mobileads.MoPubActivity".equals(activityName)) { onWebView().check(webMatches(getCurrentUrl(), containsString("ads.mopub.com"))); onWebView().check(webContent(containingTextInBody("ucTag.renderAd"))); Espresso.pressBack(); - assertEquals("Auto refresh not happening", 2, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); - ((DemoActivity) TestUtil.getCurrentActivity()).stopAutoRefresh(); + assertEquals("Auto refresh not happening", 2, ((RubiconInterstitialMoPubDemoActivity) TestUtil.getCurrentActivity()).refreshCount); + ((RubiconInterstitialMoPubDemoActivity) TestUtil.getCurrentActivity()).adUnit.stopAutoRefresh(); Thread.sleep(30000); - assertEquals("Auto refresh didn't stop", 2, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals("Auto refresh didn't stop", 2, ((RubiconInterstitialMoPubDemoActivity) TestUtil.getCurrentActivity()).refreshCount); } else if ("org.prebid.mobile.app.DemoActivity".equals(activityName)) { - assertEquals("Auto refresh not happening", 2, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); - assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); + assertEquals("Auto refresh not happening", 2, ((RubiconInterstitialMoPubDemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(ResultCode.SUCCESS, ((RubiconInterstitialMoPubDemoActivity) TestUtil.getCurrentActivity()).resultCode); fail("Prebid Demand was fetched successfully, but MoPub interstitial not loaded and show successfully"); } else { fail("Demo app not working properly"); } } else if ("org.prebid.mobile.app.DemoActivity".equals(activityName)) { - assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); + assertEquals(ResultCode.SUCCESS, ((RubiconInterstitialMoPubDemoActivity) TestUtil.getCurrentActivity()).resultCode); fail("Prebid Demand was fetched successfully, but MoPub interstitial not loaded and show successfully"); } else { fail("Demo app not working properly"); diff --git a/Example/PrebidDemoJava/src/androidTest/java/org/prebid/mobile/app/MoPubNativeTest.java b/Example/PrebidDemoJava/src/androidTest/java/org/prebid/mobile/app/MoPubNativeTest.java index de1c732d2..ba1456da7 100644 --- a/Example/PrebidDemoJava/src/androidTest/java/org/prebid/mobile/app/MoPubNativeTest.java +++ b/Example/PrebidDemoJava/src/androidTest/java/org/prebid/mobile/app/MoPubNativeTest.java @@ -29,14 +29,11 @@ import static androidx.test.espresso.action.ViewActions.click; import static androidx.test.espresso.action.ViewActions.typeText; import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static androidx.test.espresso.web.assertion.WebViewAssertions.webMatches; -import static androidx.test.espresso.web.sugar.Web.onWebView; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.core.AllOf.allOf; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; @RunWith(AndroidJUnit4.class) public class MoPubNativeTest { @@ -51,9 +48,9 @@ public void testAppNexusMoPubNativeSanityAppCheckTest() throws Exception { onData(allOf(is(instanceOf(String.class)), is("MoPub"))).perform(click()); onView(withId(R.id.showAd)).perform(click()); Thread.sleep(10000); - assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); - assertTrue(((DemoActivity) TestUtil.getCurrentActivity()).adView.getKeywords().contains("hb_pb")); - assertTrue(((DemoActivity) TestUtil.getCurrentActivity()).adView.getKeywords().contains("hb_cache_id")); + assertEquals(ResultCode.SUCCESS, ((XandrNativeInAppMoPubDemoActivity) TestUtil.getCurrentActivity()).resultCode); + assertTrue(((XandrNativeInAppMoPubDemoActivity) TestUtil.getCurrentActivity()).request.getKeywords().contains("hb_pb")); + assertTrue(((XandrNativeInAppMoPubDemoActivity) TestUtil.getCurrentActivity()).request.getKeywords().contains("hb_cache_id")); } @Test @@ -65,13 +62,13 @@ public void testMoPubNativeWithValidAutoRefresh() throws Exception { onView(withId(R.id.autoRefreshInput)).perform(typeText("30000")); onView(withId(R.id.showAd)).perform(click()); Thread.sleep(10000); - assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); - assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); + assertEquals(1, ((XandrNativeInAppMoPubDemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(ResultCode.SUCCESS, ((XandrNativeInAppMoPubDemoActivity) TestUtil.getCurrentActivity()).resultCode); Thread.sleep(30000); - assertEquals("Auto refresh not happening", 2, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); - ((DemoActivity) TestUtil.getCurrentActivity()).stopAutoRefresh(); + assertEquals("Auto refresh not happening", 2, ((XandrNativeInAppMoPubDemoActivity) TestUtil.getCurrentActivity()).refreshCount); + ((XandrNativeInAppMoPubDemoActivity) TestUtil.getCurrentActivity()).adUnit.stopAutoRefresh(); Thread.sleep(30000); - assertEquals("Auto refresh didn't stop", 2, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals("Auto refresh didn't stop", 2, ((XandrNativeInAppMoPubDemoActivity) TestUtil.getCurrentActivity()).refreshCount); } @Test @@ -83,10 +80,10 @@ public void testMoPubNativeWithoutAutoRefresh() throws Exception { onView(withId(R.id.autoRefreshInput)).perform(typeText("0")); onView(withId(R.id.showAd)).perform(click()); Thread.sleep(10000); - assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); - assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); + assertEquals(1, ((XandrNativeInAppMoPubDemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(ResultCode.SUCCESS, ((XandrNativeInAppMoPubDemoActivity) TestUtil.getCurrentActivity()).resultCode); Thread.sleep(30000); - assertEquals("Auto refresh not happening", 1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals("Auto refresh not happening", 1, ((XandrNativeInAppMoPubDemoActivity) TestUtil.getCurrentActivity()).refreshCount); } @Test @@ -98,9 +95,9 @@ public void testMoPubNativeWithInvalidAutoRefresh() throws Exception { onView(withId(R.id.autoRefreshInput)).perform(typeText("20000")); onView(withId(R.id.showAd)).perform(click()); Thread.sleep(10000); - assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); - assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); + assertEquals(1, ((XandrNativeInAppMoPubDemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals(ResultCode.SUCCESS, ((XandrNativeInAppMoPubDemoActivity) TestUtil.getCurrentActivity()).resultCode); Thread.sleep(30000); - assertEquals("Auto refresh not happening", 1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); + assertEquals("Auto refresh not happening", 1, ((XandrNativeInAppMoPubDemoActivity) TestUtil.getCurrentActivity()).refreshCount); } } diff --git a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/app/RubiconBannerGamDemoActivity.java b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/app/RubiconBannerGamDemoActivity.java index 202a5e255..ef338cef7 100644 --- a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/app/RubiconBannerGamDemoActivity.java +++ b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/app/RubiconBannerGamDemoActivity.java @@ -28,6 +28,10 @@ public class RubiconBannerGamDemoActivity extends AppCompatActivity { BannerAdUnit adUnit; + //Used by UI tests + int refreshCount; + ResultCode resultCode; + @Override protected void onDestroy() { super.onDestroy(); @@ -100,6 +104,9 @@ public void onComplete(ResultCode resultCode) { // PublisherAdRequest request = builder.build(); AdManagerAdRequest request = builder.build(); amBanner.loadAd(request); + + refreshCount++; + RubiconBannerGamDemoActivity.this.resultCode = resultCode; } }); diff --git a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/app/RubiconBannerMoPubDemoActivity.java b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/app/RubiconBannerMoPubDemoActivity.java index 7947ef027..5a48c1bbf 100644 --- a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/app/RubiconBannerMoPubDemoActivity.java +++ b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/app/RubiconBannerMoPubDemoActivity.java @@ -21,6 +21,10 @@ public class RubiconBannerMoPubDemoActivity extends AppCompatActivity { BannerAdUnit adUnit; + //Used by UI tests + int refreshCount; + ResultCode resultCode; + @Override protected void onDestroy() { super.onDestroy(); @@ -62,6 +66,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { public void onComplete(ResultCode resultCode) { adView.loadAd(); + refreshCount++; + RubiconBannerMoPubDemoActivity.this.resultCode = resultCode; } }); } diff --git a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/app/RubiconInterstitialGamDemoActivity.java b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/app/RubiconInterstitialGamDemoActivity.java index 16439a04a..fcec7017c 100644 --- a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/app/RubiconInterstitialGamDemoActivity.java +++ b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/app/RubiconInterstitialGamDemoActivity.java @@ -23,6 +23,10 @@ public class RubiconInterstitialGamDemoActivity extends AppCompatActivity { AdUnit adUnit; + //Used by UI tests + int refreshCount; + ResultCode resultCode; + @Override protected void onDestroy() { super.onDestroy(); @@ -79,6 +83,9 @@ public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) { } } ); + + refreshCount++; + RubiconInterstitialGamDemoActivity.this.resultCode = resultCode; } }); } diff --git a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/app/RubiconInterstitialMoPubDemoActivity.java b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/app/RubiconInterstitialMoPubDemoActivity.java index eec13b954..dafd0cb2c 100644 --- a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/app/RubiconInterstitialMoPubDemoActivity.java +++ b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/app/RubiconInterstitialMoPubDemoActivity.java @@ -20,6 +20,10 @@ public class RubiconInterstitialMoPubDemoActivity extends AppCompatActivity { AdUnit adUnit; + //Used by UI tests + int refreshCount; + ResultCode resultCode; + @Override protected void onDestroy() { super.onDestroy(); @@ -80,6 +84,9 @@ public void onInterstitialDismissed(MoPubInterstitial interstitial) { @Override public void onComplete(ResultCode resultCode) { mpInterstitial.load(); + + refreshCount++; + RubiconInterstitialMoPubDemoActivity.this.resultCode = resultCode; } }); diff --git a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/app/XandrNativeInAppGAMDemoActivity.java b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/app/XandrNativeInAppGAMDemoActivity.java index 24bbe7c0e..725cd2a6d 100644 --- a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/app/XandrNativeInAppGAMDemoActivity.java +++ b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/app/XandrNativeInAppGAMDemoActivity.java @@ -21,6 +21,7 @@ import com.google.android.gms.ads.formats.OnAdManagerAdViewLoadedListener; import com.google.android.gms.ads.formats.UnifiedNativeAd; +import org.prebid.mobile.AdUnit; import org.prebid.mobile.Host; import org.prebid.mobile.LogUtil; import org.prebid.mobile.NativeAdUnit; @@ -46,6 +47,12 @@ public class XandrNativeInAppGAMDemoActivity extends AppCompatActivity { private AdLoader adLoader; private UnifiedNativeAd unifiedNativeAd; + //Used by UI tests + int refreshCount; + ResultCode resultCode; + AdManagerAdRequest request; + AdUnit adUnit; + private void removePreviousAds() { ((FrameLayout) findViewById(R.id.adFrame)).removeAllViews(); if (adView != null) { @@ -106,6 +113,7 @@ private void loadInAppNative() { nativeAdUnit.setContextType(NativeAdUnit.CONTEXT_TYPE.SOCIAL_CENTRIC); nativeAdUnit.setPlacementType(NativeAdUnit.PLACEMENTTYPE.CONTENT_FEED); nativeAdUnit.setContextSubType(NativeAdUnit.CONTEXTSUBTYPE.GENERAL_SOCIAL); + adUnit = nativeAdUnit; ArrayList methods = new ArrayList<>(); methods.add(NativeEventTracker.EVENT_TRACKING_METHOD.IMAGE); methods.add(NativeEventTracker.EVENT_TRACKING_METHOD.JS); @@ -158,6 +166,10 @@ public void onComplete(ResultCode resultCode) { } else { Toast.makeText(XandrNativeInAppGAMDemoActivity.this, "Native Ad Unit: " + resultCode.name(), Toast.LENGTH_SHORT).show(); } + + refreshCount++; + XandrNativeInAppGAMDemoActivity.this.resultCode = resultCode; + request = adManagerAdRequest; } }); diff --git a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/app/XandrNativeInAppMoPubDemoActivity.java b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/app/XandrNativeInAppMoPubDemoActivity.java index fcf72a956..9ad02c8f7 100644 --- a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/app/XandrNativeInAppMoPubDemoActivity.java +++ b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/app/XandrNativeInAppMoPubDemoActivity.java @@ -25,6 +25,7 @@ import com.mopub.nativeads.RequestParameters; import com.mopub.nativeads.StaticNativeAd; +import org.prebid.mobile.AdUnit; import org.prebid.mobile.Host; import org.prebid.mobile.NativeAdUnit; import org.prebid.mobile.NativeDataAsset; @@ -43,18 +44,24 @@ import java.util.ArrayList; public class XandrNativeInAppMoPubDemoActivity extends AppCompatActivity { - private MoPubNative mMoPubNative; + private MoPubNative moPubNative; private NativeAd ad; + //Used by UI tests + int refreshCount; + ResultCode resultCode; + RequestParameters request; + AdUnit adUnit; + private void removePreviousAds() { ((FrameLayout) findViewById(R.id.adFrame)).removeAllViews(); if (ad != null) { ad.destroy(); ad = null; } - if (mMoPubNative != null) { - mMoPubNative.destroy(); - mMoPubNative = null; + if (moPubNative != null) { + moPubNative.destroy(); + moPubNative = null; } } @@ -151,6 +158,7 @@ private void loadInAppNativeMopub() { nativeAdUnit.setContextType(NativeAdUnit.CONTEXT_TYPE.SOCIAL_CENTRIC); nativeAdUnit.setPlacementType(NativeAdUnit.PLACEMENTTYPE.CONTENT_FEED); nativeAdUnit.setContextSubType(NativeAdUnit.CONTEXTSUBTYPE.GENERAL_SOCIAL); + adUnit = nativeAdUnit; ArrayList methods = new ArrayList<>(); methods.add(NativeEventTracker.EVENT_TRACKING_METHOD.IMAGE); methods.add(NativeEventTracker.EVENT_TRACKING_METHOD.JS); @@ -191,7 +199,7 @@ private void loadInAppNativeMopub() { cta.setDataType(NativeDataAsset.DATA_TYPE.CTATEXT); nativeAdUnit.addAsset(cta); - mMoPubNative = new MoPubNative(XandrNativeInAppMoPubDemoActivity.this, "2674981035164b2db5ef4b4546bf3d49", new MoPubNative.MoPubNativeNetworkListener() { + moPubNative = new MoPubNative(XandrNativeInAppMoPubDemoActivity.this, "2674981035164b2db5ef4b4546bf3d49", new MoPubNative.MoPubNativeNetworkListener() { @Override public void onNativeLoad(final NativeAd nativeAd) { Log.d("Prebid", "MoPub native ad loaded"); @@ -221,17 +229,22 @@ public void onNativeFail(NativeErrorCode errorCode) { Log.d("Prebid", "MoPub native failed to load: " + errorCode.toString()); } }); - mMoPubNative.registerAdRenderer(new MoPubStaticNativeAdRenderer(null)); + moPubNative.registerAdRenderer(new MoPubStaticNativeAdRenderer(null)); RequestParameters.Builder mRP = new RequestParameters.Builder(); + // Fetching the demannd using OnCompleteListener nativeAdUnit.fetchDemand(mRP, new OnCompleteListener() { @Override public void onComplete(ResultCode resultCode) { if (resultCode == ResultCode.SUCCESS) { - mMoPubNative.makeRequest(mRP.build()); + moPubNative.makeRequest(mRP.build()); } else { Toast.makeText(XandrNativeInAppMoPubDemoActivity.this, "Native Ad Unit: " + resultCode.name(), Toast.LENGTH_SHORT).show(); } + + refreshCount++; + XandrNativeInAppMoPubDemoActivity.this.resultCode = resultCode; + request = mRP.build(); } }); From 4ebc656f428183e38f71357855742dcd051a9fea Mon Sep 17 00:00:00 2001 From: Oleksandr Pavliuchyk Date: Fri, 30 Apr 2021 17:00:45 +0300 Subject: [PATCH 2/3] building UI tests --- .travis.yml | 2 +- scripts/testPrebidDemo.sh | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0a1c08af3..73cc0a4b6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,4 +33,4 @@ before_install: script: - "./scripts/buildPrebidMobile.sh" - "./scripts/testPrebidMobile.sh" -# - "./scripts/testPrebidDemo.sh" \ No newline at end of file + - "./scripts/testPrebidDemo.sh" \ No newline at end of file diff --git a/scripts/testPrebidDemo.sh b/scripts/testPrebidDemo.sh index 8bcabdd61..147095ae3 100755 --- a/scripts/testPrebidDemo.sh +++ b/scripts/testPrebidDemo.sh @@ -17,4 +17,9 @@ echoX "clean previous build" ./gradlew clean echoX "start UI tests" -./gradlew PrebidDemoJava:connectedSourceCodeDebugAndroidTest + +#building +./gradlew assembleSourceCodeDebugAndroidTest + +# testing +# ./gradlew PrebidDemoJava:connectedSourceCodeDebugAndroidTest From dce657a049187a533b8c5089592731f93b6f6c75 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavliuchyk Date: Fri, 30 Apr 2021 17:30:04 +0300 Subject: [PATCH 3/3] minor fix --- scripts/testPrebidDemo.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/testPrebidDemo.sh b/scripts/testPrebidDemo.sh index 147095ae3..fde07bfeb 100755 --- a/scripts/testPrebidDemo.sh +++ b/scripts/testPrebidDemo.sh @@ -16,10 +16,10 @@ echo -e "✅ PREBID TESTLOG: $@" echoX "clean previous build" ./gradlew clean -echoX "start UI tests" - #building +echoX "start building UI tests" ./gradlew assembleSourceCodeDebugAndroidTest # testing +echoX "start UI tests" # ./gradlew PrebidDemoJava:connectedSourceCodeDebugAndroidTest