Skip to content

Commit bdc7c2b

Browse files
authored
Merge pull request #23 from 07souravkunda/sdk
Add sdk initial changes
2 parents 27ff940 + 4da6951 commit bdc7c2b

File tree

17 files changed

+350
-134
lines changed

17 files changed

+350
-134
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
/build
88
/captures
99
.externalNativeBuild
10+
*.log
11+
.idea

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
* Build the test application: `./gradlew assembleAndroidTest` (apk will be generated in the `app/build/outputs/apk/androidTest/debug/` directory)
1919
* Upload both the apk files to BrowserStack and start a session. Refer our documentation for details: [Using Espresso with BrowserStack](https://www.browserstack.com/app-automate/espresso/get-started)
2020

21+
### Test Reporting & Analytics
22+
23+
* To integrate BrowserStack Test Reporting & Analytics with Espresso, refer to our documentation: [Test Reporting & Analytics on Espresso](https://www.browserstack.com/docs/test-reporting-and-analytics/quick-start/espresso)
24+
25+
### App Accessibility Testing
26+
27+
* To integrate BrowserStack Accessibility to functional tests and generate comprehensive reports of accessibility issues, refer to our documentation: [Integrate Espresso test suite with app accessibility testing](https://www.browserstack.com/docs/app-accessibility/automated-tests/get-started/espresso/integrate-with-app-automate)
28+
2129
## Notes
2230
* You can view your test results on the [BrowserStack app-automate dashboard](https://www.browserstack.com/app-automate)
2331

app/build.gradle

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,64 @@
1-
apply plugin: 'com.android.application'
2-
apply plugin: 'jacoco'
3-
jacoco {
4-
toolVersion='0.7.5.201505241946'
5-
}
6-
buildscript {
7-
repositories {
8-
mavenCentral()
9-
}
1+
plugins {
2+
alias(libs.plugins.android.application)
3+
id 'com.browserstack.gradle-tool'
4+
id 'jacoco'
105
}
116

127
android {
13-
compileSdkVersion 30
14-
dataBinding.enabled = true
8+
namespace 'com.sample.browserstack.samplecalculator'
9+
compileSdk 34
1510

1611
defaultConfig {
1712
applicationId "com.sample.browserstack.samplecalculator"
18-
minSdkVersion 15
19-
targetSdkVersion 30
13+
minSdk 26
14+
targetSdk 34
2015
versionCode 1
2116
versionName "1.0"
22-
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
17+
18+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2319
}
20+
2421
buildTypes {
2522
release {
2623
minifyEnabled false
27-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
28-
}
29-
debug {
30-
testCoverageEnabled true
24+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
3125
}
3226
}
27+
3328
compileOptions {
3429
sourceCompatibility JavaVersion.VERSION_1_8
3530
targetCompatibility JavaVersion.VERSION_1_8
3631
}
32+
33+
dataBinding {
34+
enabled = true
35+
}
3736
}
3837

3938
dependencies {
40-
implementation fileTree(dir: 'libs', include: ['*.jar'])
41-
implementation 'androidx.appcompat:appcompat:1.0.0'
42-
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
43-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
44-
androidTestImplementation 'androidx.test:rules:1.1.1'
45-
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
46-
testImplementation 'junit:junit:4.12'
47-
}
39+
implementation libs.appcompat
40+
implementation libs.material
41+
implementation libs.activity
42+
implementation libs.constraintlayout
43+
testImplementation libs.junit
44+
androidTestImplementation libs.ext.junit
45+
androidTestImplementation libs.espresso.core
46+
47+
androidTestImplementation(group: 'com.browserstack', name: 'browserstack-java-sdk', version: 'latest.release') {
48+
exclude group: 'com.google.code.findbugs', module: 'jsr305'
49+
}
50+
51+
configurations.androidTestImplementation {
52+
exclude group: 'com.google.code.findbugs', module: 'jsr305'
53+
}
54+
}
55+
56+
jacoco {
57+
toolVersion = '0.8.8'
58+
}
59+
60+
task printSdkVersion {
61+
doLast {
62+
println android.compileSdkVersion
63+
}
64+
}

app/src/androidTest/java/com/sample/browserstack/samplecalculator/EnsureInputTests.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.sample.browserstack.samplecalculator;
22

33
import androidx.test.filters.SmallTest;
4-
import androidx.test.rule.ActivityTestRule;
4+
import androidx.test.ext.junit.rules.ActivityScenarioRule;
55
import androidx.test.ext.junit.runners.AndroidJUnit4;
66

77
import org.junit.Before;
@@ -25,14 +25,13 @@
2525
public class EnsureInputTests {
2626

2727
@Rule
28-
public ActivityTestRule<MainActivity> activityRule =
29-
new ActivityTestRule<MainActivity>(MainActivity.class);
30-
31-
private MainActivity mainActivity;
28+
public ActivityScenarioRule<MainActivity> activityScenarioRule =
29+
new ActivityScenarioRule<>(MainActivity.class);
3230

3331
@Before
3432
public void setUp() {
35-
mainActivity = activityRule.getActivity();
33+
// ActivityScenarioRule handles activity initialization automatically
34+
// No need to manually get activity reference in modern testing
3635
}
3736

3837
@Test

app/src/androidTest/java/com/sample/browserstack/samplecalculator/EnsureOperationTests.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.sample.browserstack.samplecalculator;
22

33
import androidx.test.filters.MediumTest;
4-
import androidx.test.rule.ActivityTestRule;
4+
import androidx.test.ext.junit.rules.ActivityScenarioRule;
55
import androidx.test.ext.junit.runners.AndroidJUnit4;
66

77
import org.junit.Before;
@@ -25,14 +25,13 @@
2525
public class EnsureOperationTests {
2626

2727
@Rule
28-
public ActivityTestRule<MainActivity> activityRule =
29-
new ActivityTestRule<MainActivity>(MainActivity.class);
30-
31-
private MainActivity mainActivity;
28+
public ActivityScenarioRule<MainActivity> activityScenarioRule =
29+
new ActivityScenarioRule<>(MainActivity.class);
3230

3331
@Before
3432
public void setUp() {
35-
mainActivity = activityRule.getActivity();
33+
// ActivityScenarioRule handles activity initialization automatically
34+
// No need to manually get activity reference in modern testing
3635
}
3736

3837
@Test

app/src/androidTest/java/com/sample/browserstack/samplecalculator/EnsureRandomTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.sample.browserstack.samplecalculator;
22

33
import androidx.test.filters.MediumTest;
4-
import androidx.test.rule.ActivityTestRule;
4+
import androidx.test.ext.junit.rules.ActivityScenarioRule;
55
import androidx.test.ext.junit.runners.AndroidJUnit4;
66

77
import org.junit.Rule;
@@ -26,8 +26,8 @@
2626
public class EnsureRandomTests {
2727

2828
@Rule
29-
public ActivityTestRule<MainActivity> activityRule =
30-
new ActivityTestRule<MainActivity>(MainActivity.class);
29+
public ActivityScenarioRule<MainActivity> activityScenarioRule =
30+
new ActivityScenarioRule<>(MainActivity.class);
3131

3232
@Test
3333
public void testZeroMultiplication() {
Lines changed: 98 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
package com.sample.browserstack.samplecalculator;
22

3-
import android.content.Context;
4-
import androidx.test.platform.app.InstrumentationRegistry;
3+
import static androidx.test.espresso.action.ViewActions.click;
4+
import static androidx.test.espresso.action.ViewActions.replaceText;
5+
import static androidx.test.espresso.matcher.ViewMatchers.withId;
6+
7+
import android.util.Log;
8+
9+
import androidx.test.espresso.Espresso;
10+
import androidx.test.ext.junit.rules.ActivityScenarioRule;
511
import androidx.test.ext.junit.runners.AndroidJUnit4;
612

13+
import org.junit.Assert;
14+
import org.junit.Assume;
15+
import org.junit.Before;
16+
import org.junit.Ignore;
17+
import org.junit.Rule;
718
import org.junit.Test;
19+
import org.junit.experimental.categories.Category;
820
import org.junit.runner.RunWith;
921

10-
import static org.junit.Assert.*;
22+
import com.browserstack.accessibility.AccessibilityUtils;
1123

1224
/**
1325
* Instrumented test, which will execute on an Android device.
@@ -16,10 +28,89 @@
1628
*/
1729
@RunWith(AndroidJUnit4.class)
1830
public class ExampleInstrumentedTest {
31+
@Rule
32+
public ActivityScenarioRule<MainActivity> activityScenarioRule =
33+
new ActivityScenarioRule<>(MainActivity.class);
34+
35+
@Before
36+
public void myBeforeEach() throws Exception{
37+
Log.d("TRANSFORMATION_LOGS", "From @Before");
38+
}
39+
40+
@Test
41+
public void testCalculatorBasicOperation() {
42+
android.util.Log.d("TRANSFORMATION_LOGS", "IN TEST");
43+
Espresso.onView(withId(R.id.buttonTwo)).perform(click());
44+
Espresso.onView(withId(R.id.buttonAdd)).perform(click());
45+
Espresso.onView(withId(R.id.buttonThree)).perform(click());
46+
Espresso.onView(withId(R.id.buttonEqual)).perform(click());
47+
}
48+
49+
@Test
50+
public void exceptionFailedTest() throws Exception {
51+
Espresso.onView(withId(R.id.buttonFive)).perform(click());
52+
Espresso.onView(withId(R.id.buttonMultiply)).perform(click());
53+
Espresso.onView(withId(R.id.buttonTwo)).perform(click());
54+
Espresso.onView(withId(R.id.buttonEqual)).perform(click());
55+
throw new Exception("EXCEPTION FROM TEST");
56+
}
57+
58+
@Test
59+
@Category(ExampleInstrumentedTest.class)
60+
public void assertionFailedTest() throws Exception {
61+
Log.d("TEST_LOGS", "testStarted");
62+
63+
Espresso.onView(withId(R.id.buttonOne)).perform(click());
64+
Espresso.onView(withId(R.id.buttonAdd)).perform(click());
65+
Espresso.onView(withId(R.id.buttonOne)).perform(click());
66+
Espresso.onView(withId(R.id.buttonEqual)).perform(click());
67+
68+
Log.d("PERFORM_SCAN_LOGS", "beforeScan");
69+
AccessibilityUtils.performEspressoAppAccessibilityScan("");
70+
Log.d("PERFORM_SCAN_LOGS", "afterScan");
71+
72+
Thread.sleep(10000);
73+
74+
Log.d("A11Y_RESULTS_SUMMARY", AccessibilityUtils.getResultsSummary().toString());
75+
Log.d("A11Y_RESULTS", AccessibilityUtils.getResults().toString());
76+
77+
Assert.assertTrue(false);
78+
Thread.sleep(2000);
79+
80+
Log.d("TEST_LOGS", "testEnded");
81+
}
82+
83+
@Test
84+
@Category(MainActivity.class)
85+
public void testTags() throws InterruptedException{
86+
Log.d("TEST_LOGS", "testStarted");
87+
88+
Assert.assertTrue(true);
89+
Thread.sleep(10000);
90+
91+
Log.d("A11Y_RESULTS_SUMMARY", AccessibilityUtils.getResultsSummary().toString());
92+
Log.d("A11Y_RESULTS", AccessibilityUtils.getResults().toString());
93+
94+
Log.d("TEST_LOGS", "testEnded");
95+
}
96+
97+
@Test
98+
@Ignore
99+
public void testIgnored() throws InterruptedException {
100+
Log.d("TRANSFORMATION_LOGS", "testIgnored");
101+
Thread.sleep(2000);
102+
}
103+
104+
@Test
105+
@Ignore("IGNORE MESSAGE")
106+
public void testIgnoredWithMessage() throws InterruptedException {
107+
Log.d("TRANSFORMATION_LOGS", "testIgnoredWithMessage");
108+
Thread.sleep(2000);
109+
}
110+
19111
@Test
20-
public void useAppContext() {
21-
// Context of the app under test.
22-
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
23-
assertEquals("com.sample.browserstack.samplecalculator", appContext.getPackageName());
112+
public void testAssumptionFailure() throws InterruptedException {
113+
Assume.assumeTrue(false);
114+
Thread.sleep(2000);
24115
}
25116
}

app/src/main/AndroidManifest.xml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.sample.browserstack.samplecalculator">
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<uses-permission android:name="android.permission.INTERNET"/>
46

5-
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
67
<application
8+
android:usesCleartextTraffic="true"
79
android:allowBackup="true"
10+
android:dataExtractionRules="@xml/data_extraction_rules"
11+
android:fullBackupContent="@xml/backup_rules"
812
android:icon="@mipmap/ic_launcher"
913
android:label="@string/app_name"
1014
android:roundIcon="@mipmap/ic_launcher_round"
1115
android:supportsRtl="true"
12-
android:theme="@style/AppTheme">
13-
<activity android:name=".MainActivity">
16+
android:theme="@style/AppTheme"
17+
tools:targetApi="31">
18+
<activity
19+
android:name=".MainActivity"
20+
android:exported="true">
1421
<intent-filter>
1522
<action android:name="android.intent.action.MAIN" />
1623

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--
2+
Sample backup rules file; uncomment and customize as necessary.
3+
See https://developer.android.com/guide/topics/data/autobackup
4+
for details.
5+
Note: This file is ignored for devices older that API 23 even if they contain android:fullBackupContent="true".
6+
-->
7+
<full-backup-content>
8+
<!-- TODO: Use <include> and <exclude> to control what is backed up.
9+
<include domain=["file" | "database" | "sharedpref" | "external" | "root"] path="string" />
10+
<exclude domain=["file" | "database" | "sharedpref" | "external" | "root"] path="string" />
11+
-->
12+
</full-backup-content>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--
2+
Sample data extraction rules file; uncomment and customize as necessary.
3+
See https://developer.android.com/about/versions/12/backup-restore#xml-changes
4+
for details.
5+
-->
6+
<data-extraction-rules>
7+
<cloud-backup>
8+
<!-- TODO: Use <include> and <exclude> to control what is backed up.
9+
<include .../>
10+
<exclude .../>
11+
-->
12+
</cloud-backup>
13+
<!--
14+
<device-transfer>
15+
<include .../>
16+
<exclude .../>
17+
</device-transfer>
18+
-->
19+
</data-extraction-rules>

0 commit comments

Comments
 (0)