Skip to content

Commit

Permalink
Add app and browser switch tests to demo app
Browse files Browse the repository at this point in the history
  • Loading branch information
lkorth committed Dec 10, 2015
1 parent 0bb593a commit 1cfa138
Show file tree
Hide file tree
Showing 8 changed files with 406 additions and 9 deletions.
26 changes: 17 additions & 9 deletions Demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ android {
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
minSdkVersion 18
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode rootProject.ext.versionCode
versionName rootProject.ext.versionName
Expand All @@ -14,16 +14,16 @@ android {

signingConfigs {
debug {
storeFile file("debug.keystore")
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
release {
storeFile file("debug.keystore")
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
}

Expand All @@ -49,6 +49,12 @@ android {
}
}

repositories {
maven {
url "https://jitpack.io"
}
}

configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:23.0.1'
}
Expand All @@ -65,4 +71,6 @@ dependencies {
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'

testCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile project(':TestUtils')
androidTestCompile 'com.github.lkorth:device-automator:e2f12ded31'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.braintreepayments.demo.test;

import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import static com.braintreepayments.demo.test.utilities.TestHelper.clearPreferences;
import static com.braintreepayments.demo.test.utilities.TestHelper.ensureEnvironmentIsSandbox;
import static com.braintreepayments.demo.test.utilities.TestHelper.launchDemoApp;
import static com.lukekorth.deviceautomator.AutomatorAction.click;
import static com.lukekorth.deviceautomator.AutomatorAction.setText;
import static com.lukekorth.deviceautomator.AutomatorAssertion.text;
import static com.lukekorth.deviceautomator.DeviceAutomator.onDevice;
import static com.lukekorth.deviceautomator.UiObjectMatcher.withText;
import static com.lukekorth.deviceautomator.UiObjectMatcher.withTextStartingWith;
import static org.hamcrest.CoreMatchers.containsString;

@RunWith(AndroidJUnit4.class)
@LargeTest
public class CustomTest {

@Before
public void setup() {
clearPreferences();
launchDemoApp();
ensureEnvironmentIsSandbox();
onDevice(withText("Custom")).waitForEnabled().perform(click());
}

@Test(timeout = 60000)
public void tokenizesACard() {
onDevice(withText("Card Number")).perform(setText("4111111111111111"));
onDevice(withText("Expiration")).perform(setText("1220"));
onDevice(withText("Purchase")).perform(click());
onDevice(withTextStartingWith("Card Last Two:")).check(text(containsString("11")));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.braintreepayments.demo.test;

import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import static com.braintreepayments.demo.test.utilities.TestHelper.clearPreferences;
import static com.braintreepayments.demo.test.utilities.TestHelper.ensureEnvironmentIsSandbox;
import static com.braintreepayments.demo.test.utilities.TestHelper.launchDemoApp;
import static com.lukekorth.deviceautomator.AutomatorAction.click;
import static com.lukekorth.deviceautomator.AutomatorAction.setText;
import static com.lukekorth.deviceautomator.AutomatorAssertion.text;
import static com.lukekorth.deviceautomator.DeviceAutomator.onDevice;
import static com.lukekorth.deviceautomator.UiObjectMatcher.withText;
import static com.lukekorth.deviceautomator.UiObjectMatcher.withTextContaining;
import static com.lukekorth.deviceautomator.UiObjectMatcher.withTextStartingWith;
import static org.hamcrest.CoreMatchers.containsString;

@RunWith(AndroidJUnit4.class)
@LargeTest
public class DropInTest {

@Before
public void setup() {
clearPreferences();
launchDemoApp();
ensureEnvironmentIsSandbox();
onDevice(withText("Drop-In")).waitForEnabled().perform(click());
}

@Test(timeout = 60000)
public void tokenizesACard() {
onDevice(withText("Card Number")).perform(setText("4111111111111111"));
onDevice(withText("Expiration")).perform(setText("1220"));
onDevice(withTextContaining("BUY")).perform(click());
onDevice(withTextStartingWith("Card Last Two:")).check(text(containsString("11")));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package com.braintreepayments.demo.test;

import android.os.SystemClock;
import android.support.test.filters.SdkSuppress;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import static com.braintreepayments.demo.test.utilities.TestHelper.clearPreferences;
import static com.braintreepayments.demo.test.utilities.TestHelper.ensureEnvironmentIsSandbox;
import static com.braintreepayments.demo.test.utilities.TestHelper.installPayPalWallet;
import static com.braintreepayments.demo.test.utilities.TestHelper.isAppInstalled;
import static com.braintreepayments.demo.test.utilities.TestHelper.launchDemoApp;
import static com.braintreepayments.demo.test.utilities.TestHelper.uninstallPayPalWallet;
import static com.lukekorth.deviceautomator.AutomatorAction.click;
import static com.lukekorth.deviceautomator.AutomatorAction.setText;
import static com.lukekorth.deviceautomator.AutomatorAssertion.text;
import static com.lukekorth.deviceautomator.DeviceAutomator.onDevice;
import static com.lukekorth.deviceautomator.UiObjectMatcher.withContentDescription;
import static com.lukekorth.deviceautomator.UiObjectMatcher.withText;
import static com.lukekorth.deviceautomator.UiObjectMatcher.withTextContaining;
import static org.hamcrest.Matchers.containsString;

@RunWith(AndroidJUnit4.class)
@LargeTest
public class PayPalTest {

@Before
public void setup() {
clearPreferences();
launchDemoApp();
ensureEnvironmentIsSandbox();
onDevice(withText("PayPal")).waitForEnabled().perform(click());
}

@SdkSuppress(minSdkVersion = 21)
@Test(timeout = 60000)
public void browserSwitch_makesASinglePayment() {
uninstallPayPalWallet();

onDevice(withText("Single Payment")).waitForEnabled().perform(click());
onDevice(withContentDescription("Proceed with Sandbox Purchase")).perform(click());

onDevice(withTextContaining("Email:")).check(text(containsString("[email protected]")));
}

@SdkSuppress(minSdkVersion = 21)
@Test(timeout = 60000)
public void browserSwitch_makesAFuturePayment() {
uninstallPayPalWallet();

onDevice(withText("Future Payment")).waitForEnabled().perform(click());
onDevice(withContentDescription("Email")).perform(click(), setText("[email protected]"));
onDevice().pressDPadDown().typeText("password");
onDevice(withContentDescription("Log In")).perform(click());
onDevice(withContentDescription("Agree")).perform(click());

onDevice(withTextContaining("Email:")).check(text(containsString("[email protected]")));
}

@SdkSuppress(minSdkVersion = 21)
@Test(timeout = 60000)
public void browserSwitch_makesAFuturePaymentWithAddressScope() {
uninstallPayPalWallet();

onDevice(withText("Future Payment (Address Scope)")).waitForEnabled().perform(click());
onDevice(withContentDescription("Email")).perform(click(), setText("[email protected]"));
onDevice().pressDPadDown().typeText("password");
onDevice(withContentDescription("Log In")).perform(click());
onDevice(withContentDescription("Agree")).perform(click());

onDevice(withTextContaining("Email:")).check(text(containsString("[email protected]")));
SystemClock.sleep(10000);
}

@SdkSuppress(minSdkVersion = 21)
@Test(timeout = 60000)
public void browserSwitch_makesABillingAgreement() {
uninstallPayPalWallet();

onDevice(withText("Billing Agreement")).waitForEnabled().perform(click());
onDevice(withContentDescription("Proceed with Sandbox Purchase")).perform(click());

onDevice(withTextContaining("Email:")).check(text(containsString("[email protected]")));
}

@Test(timeout = 120000)
public void appSwitch_forSinglePayment() {
installPayPalWallet();

onDevice(withText("Single Payment")).waitForEnabled().perform(click());

onDevice().checkForegroundAppIs("com.paypal.android.p2pmobile");
}

@Test(timeout = 120000)
public void appSwitch_forFuturePayment() {
installPayPalWallet();

onDevice(withText("Future Payment")).waitForEnabled().perform(click());

onDevice().checkForegroundAppIs("com.paypal.android.p2pmobile");
}

@Test(timeout = 120000)
public void appSwitch_forFuturePaymentWithAddressScope() {
installPayPalWallet();

onDevice(withText("Future Payment (Address Scope)")).waitForEnabled().perform(click());

onDevice().checkForegroundAppIs("com.paypal.android.p2pmobile");
}

@Test(timeout = 120000)
public void appSwitch_usesBrowserForBillingAgreement() {
installPayPalWallet();

onDevice(withText("Billing Agreement")).waitForEnabled().perform(click());

if (isAppInstalled("com.android.chrome")) {
onDevice().checkForegroundAppIs("com.android.chrome");
} else {
onDevice().checkForegroundAppIs("com.android.browser");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.braintreepayments.demo.test;

import android.os.SystemClock;
import android.support.test.filters.SdkSuppress;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import static com.braintreepayments.demo.test.utilities.TestHelper.clearPreferences;
import static com.braintreepayments.demo.test.utilities.TestHelper.ensureEnvironmentIsSandbox;
import static com.braintreepayments.demo.test.utilities.TestHelper.launchDemoApp;
import static com.braintreepayments.demo.test.utilities.TestHelper.uninstallPayPalWallet;
import static com.lukekorth.deviceautomator.AutomatorAction.click;
import static com.lukekorth.deviceautomator.AutomatorAction.setText;
import static com.lukekorth.deviceautomator.AutomatorAssertion.text;
import static com.lukekorth.deviceautomator.DeviceAutomator.onDevice;
import static com.lukekorth.deviceautomator.UiObjectMatcher.withContentDescription;
import static com.lukekorth.deviceautomator.UiObjectMatcher.withText;
import static com.lukekorth.deviceautomator.UiObjectMatcher.withTextContaining;
import static org.hamcrest.CoreMatchers.containsString;

@RunWith(AndroidJUnit4.class)
@LargeTest
public class PaymentButtonTest {

@Before
public void setup() {
clearPreferences();
launchDemoApp();
ensureEnvironmentIsSandbox();
onDevice(withText("Payment Button")).waitForEnabled().perform(click());
}

@SdkSuppress(minSdkVersion = 21)
@Test(timeout = 60000)
public void tokenizesPayPal() {
uninstallPayPalWallet();

SystemClock.sleep(5000);
onDevice(withContentDescription("Pay with PayPal")).waitForEnabled().perform(click());
onDevice(withContentDescription("Email")).perform(click(), setText("[email protected]"));
onDevice().pressDPadDown().typeText("password");
onDevice(withContentDescription("Log In")).perform(click());
onDevice(withContentDescription("Agree")).perform(click());

onDevice(withTextContaining("Email:")).check(text(containsString("[email protected]")));
}
}
Loading

0 comments on commit 1cfa138

Please sign in to comment.