Skip to content

Commit

Permalink
Merge pull request #260 from prebid/bugfix/UI_tests
Browse files Browse the repository at this point in the history
Adapt UI tests
  • Loading branch information
yoalex5 authored Jun 2, 2021
2 parents aaf771f + f625952 commit ba79773
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ before_install:
script:
- "./scripts/buildPrebidMobile.sh"
- "./scripts/testPrebidMobile.sh"
# - "./scripts/testPrebidDemo.sh"
- "./scripts/testPrebidDemo.sh"
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -87,34 +87,34 @@ 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
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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.");
Expand All @@ -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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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);
}

}
Loading

0 comments on commit ba79773

Please sign in to comment.