Skip to content

Commit 57ed028

Browse files
committed
Sample Espresso Test Application
1 parent 2553281 commit 57ed028

38 files changed

+1233
-1
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.externalNativeBuild

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,22 @@
1-
# espresso-browserstack
1+
# espresso-browserstack
2+
3+
[Espresso](https://developer.android.com/training/testing/espresso/index.html) Integration with BrowserStack
4+
5+
![BrowserStack Logo](https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-header.png?1469004780)
6+
7+
<img src ="https://developer.android.com/images/training/testing/espresso.png" height = "300">
8+
9+
## Setup
10+
11+
* Clone the repo
12+
* Build the app & test application
13+
* Use BrowserStack app-automate endpoints to run the test-suite
14+
15+
## Notes
16+
* You can check app-automate Espresso related endpoints on [BrowserStack app-automate Espresso](https://www.browserstack.com/app-automate/espresso/get-started)
17+
* You can view your test results on the [BrowserStack app-automate dashboard](https://www.browserstack.com/app-automate)
18+
19+
## Additional Resources
20+
* [Customizing your tests on BrowserStack](https://www.browserstack.com/app-automate/capabilities)
21+
* [Browsers & mobile devices for app-automate testing on BrowserStack](https://www.browserstack.com/list-of-browsers-and-platforms?product=app_automate)
22+
* [Using REST API to access information about your builds via the command-line interface](https://www.browserstack.com/app-automate/rest-api)

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 26
5+
dataBinding.enabled = true
6+
7+
defaultConfig {
8+
applicationId "com.sample.browserstack.samplecalculator"
9+
minSdkVersion 15
10+
targetSdkVersion 26
11+
versionCode 1
12+
versionName "1.0"
13+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14+
}
15+
buildTypes {
16+
release {
17+
minifyEnabled false
18+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19+
}
20+
}
21+
}
22+
23+
dependencies {
24+
implementation fileTree(dir: 'libs', include: ['*.jar'])
25+
implementation 'com.android.support:appcompat-v7:26.1.0'
26+
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
27+
testImplementation 'junit:junit:4.12'
28+
androidTestImplementation 'com.android.support.test:runner:1.0.1'
29+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
30+
}

app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.sample.browserstack.samplecalculator;
2+
3+
import android.support.test.filters.SmallTest;
4+
import android.support.test.rule.ActivityTestRule;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Rule;
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static android.support.test.espresso.Espresso.onView;
12+
import static android.support.test.espresso.action.ViewActions.click;
13+
import static android.support.test.espresso.assertion.ViewAssertions.matches;
14+
import static android.support.test.espresso.matcher.ViewMatchers.withId;
15+
import static android.support.test.espresso.matcher.ViewMatchers.withText;
16+
17+
/**
18+
* Espresso tests to ensure that editText box is updated appropriately
19+
* whenever buttons are clicked
20+
*/
21+
22+
@SmallTest
23+
@RunWith(AndroidJUnit4.class)
24+
public class EnsureInputTests {
25+
26+
@Rule
27+
public ActivityTestRule<MainActivity> activityRule =
28+
new ActivityTestRule<MainActivity>(MainActivity.class);
29+
30+
@Test
31+
public void ensureSingleInputIsHandled() {
32+
onView(withId(R.id.buttonOne)).perform(click());
33+
onView(withId(R.id.editText)).check(matches(withText("1")));
34+
}
35+
36+
@Test
37+
public void ensureMultipleInputIsHandled() {
38+
onView(withId(R.id.buttonOne)).perform(click());
39+
onView(withId(R.id.buttonTwo)).perform(click());
40+
onView(withId(R.id.editText)).check(matches(withText("12")));
41+
}
42+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.sample.browserstack.samplecalculator;
2+
3+
import android.support.test.filters.MediumTest;
4+
import android.support.test.rule.ActivityTestRule;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Rule;
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static android.support.test.espresso.Espresso.onView;
12+
import static android.support.test.espresso.action.ViewActions.click;
13+
import static android.support.test.espresso.assertion.ViewAssertions.matches;
14+
import static android.support.test.espresso.matcher.ViewMatchers.withId;
15+
import static android.support.test.espresso.matcher.ViewMatchers.withText;
16+
17+
/**
18+
* Espresso tests to ensure that simple operations result in
19+
* correct output when the number & operations buttons are clicked
20+
*/
21+
22+
@MediumTest
23+
@RunWith(AndroidJUnit4.class)
24+
public class EnsureOperationTests {
25+
26+
@Rule
27+
public ActivityTestRule<MainActivity> activityRule =
28+
new ActivityTestRule<MainActivity>(MainActivity.class);
29+
30+
@Test
31+
public void ensureAdditionWorks() {
32+
onView(withId(R.id.buttonOne)).perform(click());
33+
onView(withId(R.id.buttonTwo)).perform(click());
34+
onView(withId(R.id.buttonAdd)).perform(click());
35+
onView(withId(R.id.buttonTwo)).perform(click());
36+
onView(withId(R.id.buttonOne)).perform(click());
37+
onView(withId(R.id.buttonEqual)).perform(click());
38+
onView(withId(R.id.editText)).check(matches(withText("33")));
39+
}
40+
41+
@Test
42+
public void ensureSubtractionWorks() {
43+
onView(withId(R.id.buttonTwo)).perform(click());
44+
onView(withId(R.id.buttonTwo)).perform(click());
45+
onView(withId(R.id.buttonSubtract)).perform(click());
46+
onView(withId(R.id.buttonOne)).perform(click());
47+
onView(withId(R.id.buttonOne)).perform(click());
48+
onView(withId(R.id.buttonEqual)).perform(click());
49+
onView(withId(R.id.editText)).check(matches(withText("11")));
50+
}
51+
52+
@Test
53+
public void ensureMultiplicationWorks() {
54+
onView(withId(R.id.buttonOne)).perform(click());
55+
onView(withId(R.id.buttonTwo)).perform(click());
56+
onView(withId(R.id.buttonMultiply)).perform(click());
57+
onView(withId(R.id.buttonFive)).perform(click());
58+
onView(withId(R.id.buttonEqual)).perform(click());
59+
onView(withId(R.id.editText)).check(matches(withText("60")));
60+
}
61+
62+
@Test
63+
public void ensureDivisionWorks() {
64+
onView(withId(R.id.buttonOne)).perform(click());
65+
onView(withId(R.id.buttonTwo)).perform(click());
66+
onView(withId(R.id.buttonDivide)).perform(click());
67+
onView(withId(R.id.buttonThree)).perform(click());
68+
onView(withId(R.id.buttonEqual)).perform(click());
69+
onView(withId(R.id.editText)).check(matches(withText("4")));
70+
}
71+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.sample.browserstack.samplecalculator;
2+
3+
import android.support.test.filters.MediumTest;
4+
import android.support.test.rule.ActivityTestRule;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Rule;
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static android.support.test.espresso.Espresso.onView;
12+
import static android.support.test.espresso.action.ViewActions.click;
13+
import static android.support.test.espresso.assertion.ViewAssertions.matches;
14+
import static android.support.test.espresso.matcher.ViewMatchers.withId;
15+
import static android.support.test.espresso.matcher.ViewMatchers.withText;
16+
17+
/**
18+
* Espresso tests to ensure that random operation result are
19+
* handled correctly and correct output is generated and the
20+
* editText box is updated correctly
21+
*/
22+
23+
24+
@MediumTest
25+
@RunWith(AndroidJUnit4.class)
26+
public class EnsureRandomTests {
27+
28+
@Rule
29+
public ActivityTestRule<MainActivity> activityRule =
30+
new ActivityTestRule<MainActivity>(MainActivity.class);
31+
32+
@Test
33+
public void testZeroMultiplication() {
34+
onView(withId(R.id.buttonTwo)).perform(click());
35+
onView(withId(R.id.buttonMultiply)).perform(click());
36+
onView(withId(R.id.buttonZero)).perform(click());
37+
onView(withId(R.id.buttonEqual)).perform(click());
38+
onView(withId(R.id.editText)).check(matches(withText("0")));
39+
}
40+
41+
@Test
42+
public void testZeroDivision() {
43+
onView(withId(R.id.buttonTwo)).perform(click());
44+
onView(withId(R.id.buttonDivide)).perform(click());
45+
onView(withId(R.id.buttonZero)).perform(click());
46+
onView(withId(R.id.buttonEqual)).perform(click());
47+
onView(withId(R.id.editText)).check(matches(withText("∞")));
48+
}
49+
50+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.sample.browserstack.samplecalculator;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumented test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("com.sample.browserstack.samplecalculator", appContext.getPackageName());
25+
}
26+
}

app/src/main/AndroidManifest.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.sample.browserstack.samplecalculator">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/AppTheme">
12+
<activity android:name=".MainActivity">
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN" />
15+
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
</activity>
19+
</application>
20+
21+
</manifest>

0 commit comments

Comments
 (0)