Skip to content

Commit b2b4f17

Browse files
author
Shauvik Roy Choudhary
committed
working screenshots
1 parent 0483b69 commit b2b4f17

File tree

20 files changed

+273
-26
lines changed

20 files changed

+273
-26
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,21 @@
1-
# android-library
1+
# android-library
2+
3+
4+
5+
### Run single test
6+
7+
```
8+
./gradlew cAT -Pandroid.testInstrumentationRunnerArguments.class=com.moquality.android.AppTest
9+
```
10+
11+
Create screenshots folder
12+
```
13+
adb shell
14+
cd /sdcard/Pictures
15+
mkdir screenshots
16+
```
17+
18+
Screenshots are in the Pictures/screenshots folder. Command to pull.
19+
```
20+
adb pull /sdcard/Pictures/screenshots .
21+
```

androidtest-library/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ apply plugin: 'com.android.library'
22

33
apply plugin: 'com.github.dcendents.android-maven'
44
group='com.moquality'
5+
version = '1.0'
6+
57

68
android {
79
compileSdkVersion 29
@@ -32,6 +34,10 @@ dependencies {
3234

3335
implementation 'androidx.appcompat:appcompat:1.1.0'
3436
testImplementation 'junit:junit:4.12'
37+
38+
implementation 'androidx.test:runner:1.2.0'
39+
40+
3541
androidTestImplementation 'androidx.test:runner:1.2.0'
3642
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
3743
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.moquality.anroidtest_library;
1+
package com.moquality.android;
22

33
import android.content.Context;
44

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.moquality.anroidtest_library" />
2+
package="com.moquality.androidtest_library">
3+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
4+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
5+
</manifest>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.moquality.android;
2+
3+
import android.graphics.Bitmap;
4+
import android.util.Log;
5+
6+
import androidx.test.runner.screenshot.ScreenCapture;
7+
import androidx.test.runner.screenshot.Screenshot;
8+
9+
import java.io.IOException;
10+
11+
public class MoQuality {
12+
13+
public static String TAG = "MQ";
14+
15+
public int log(String message) {
16+
Log.i(TAG, message);
17+
return 0;
18+
}
19+
20+
public void takeScreenshot(String name) throws IOException {
21+
log("Saving screenshot "+name);
22+
ScreenCapture capture = Screenshot.capture();
23+
capture.setName(name);
24+
capture.setFormat(Bitmap.CompressFormat.PNG);
25+
try {
26+
capture.process();
27+
} catch (IOException e) {
28+
e.printStackTrace();
29+
throw e;
30+
}
31+
}
32+
}
33+

androidtest-library/src/main/java/com/moquality/anroidtest_library/MoQuality.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

androidtest-library/src/test/java/com/moquality/anroidtest_library/ExampleUnitTest.java renamed to androidtest-library/src/test/java/com/moquality/android/ExampleUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.moquality.anroidtest_library;
1+
package com.moquality.android;
22

33
import org.junit.Test;
44

app/build.gradle

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,36 @@ android {
1717
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
1818
}
1919
}
20+
21+
adbOptions {
22+
installOptions '-g', '-r'
23+
}
2024
}
2125

2226
dependencies {
2327
implementation fileTree(dir: 'libs', include: ['*.jar'])
2428
implementation 'androidx.appcompat:appcompat:1.1.0'
29+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
30+
implementation 'com.google.android.material:material:1.0.0'
2531
testImplementation 'junit:junit:4.12'
2632
androidTestImplementation project(":androidtest-library")
33+
34+
// androidTestImplementation 'com.moquality:androidtest-library:1.0'
2735
// androidTestImplementation 'com.github.moquality:android-library:master-SNAPSHOT'
36+
37+
38+
39+
// Core library
40+
androidTestImplementation 'androidx.test:core:1.0.0'
41+
42+
// AndroidJUnitRunner and JUnit Rules
2843
androidTestImplementation 'androidx.test:runner:1.2.0'
44+
androidTestImplementation 'androidx.test:rules:1.2.0'
45+
46+
// Assertions
47+
androidTestImplementation 'androidx.test.ext:junit:1.0.0'
48+
androidTestImplementation 'androidx.test.ext:truth:1.0.0'
49+
androidTestImplementation 'com.google.truth:truth:0.42'
50+
2951
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
3052
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.moquality.android;
2+
3+
import androidx.test.filters.LargeTest;
4+
import androidx.test.rule.ActivityTestRule;
5+
import androidx.test.runner.AndroidJUnit4;
6+
7+
import static androidx.test.espresso.Espresso.onView;
8+
import static androidx.test.espresso.action.ViewActions.click;
9+
import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard;
10+
import static androidx.test.espresso.action.ViewActions.typeText;
11+
import static androidx.test.espresso.assertion.ViewAssertions.matches;
12+
import static androidx.test.espresso.matcher.ViewMatchers.withId;
13+
import static androidx.test.espresso.matcher.ViewMatchers.withText;
14+
15+
16+
import org.junit.Rule;
17+
import org.junit.Test;
18+
import org.junit.runner.RunWith;
19+
20+
import java.io.IOException;
21+
22+
@RunWith(AndroidJUnit4.class)
23+
@LargeTest
24+
public class AppTest {
25+
26+
@Rule
27+
public ActivityTestRule<MainActivity> activityRule
28+
= new ActivityTestRule<>(MainActivity.class);
29+
30+
public MoQuality mq = new MoQuality();
31+
32+
@Test
33+
public void clickButtonTest() throws IOException {
34+
mq.takeScreenshot("before");
35+
onView(withId(R.id.button)).perform(click());
36+
onView(withId(R.id.editText)).check(matches(withText("Clicked")));
37+
mq.takeScreenshot("after");
38+
}
39+
40+
}

app/src/androidTest/java/com/moquality/android/ExampleInstrumentedTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
//import androidx.test.ext.junit.runners.AndroidJUnit4;
77
import androidx.test.runner.AndroidJUnit4;
88

9-
import com.moquality.anroidtest_library.MoQuality;
10-
119
import org.junit.Test;
1210
import org.junit.runner.RunWith;
1311

app/src/main/AndroidManifest.xml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
12
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
23
package="com.moquality.android">
34

5+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
6+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
7+
48
<application
59
android:allowBackup="true"
610
android:icon="@mipmap/ic_launcher"
711
android:label="@string/app_name"
812
android:roundIcon="@mipmap/ic_launcher_round"
913
android:supportsRtl="true"
10-
android:theme="@style/AppTheme" />
11-
</manifest>
14+
android:theme="@style/AppTheme">
15+
<activity
16+
android:name=".MainActivity"
17+
android:label="@string/title_activity_main"
18+
android:theme="@style/AppTheme.NoActionBar"
19+
>
20+
<intent-filter>
21+
<action android:name="android.intent.action.MAIN" />
22+
<category android:name="android.intent.category.LAUNCHER" />
23+
</intent-filter>
24+
</activity>
25+
</application>
26+
27+
</manifest>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.moquality.android;
2+
3+
import android.os.Bundle;
4+
5+
import com.google.android.material.floatingactionbutton.FloatingActionButton;
6+
import com.google.android.material.snackbar.Snackbar;
7+
8+
import androidx.appcompat.app.AppCompatActivity;
9+
import androidx.appcompat.widget.Toolbar;
10+
11+
import android.view.View;
12+
import android.widget.Button;
13+
import android.widget.EditText;
14+
15+
public class MainActivity extends AppCompatActivity {
16+
17+
@Override
18+
protected void onCreate(Bundle savedInstanceState) {
19+
super.onCreate(savedInstanceState);
20+
setContentView(R.layout.activity_main);
21+
Toolbar toolbar = findViewById(R.id.toolbar);
22+
setSupportActionBar(toolbar);
23+
24+
FloatingActionButton fab = findViewById(R.id.fab);
25+
fab.setOnClickListener(new View.OnClickListener() {
26+
@Override
27+
public void onClick(View view) {
28+
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
29+
.setAction("Action", null).show();
30+
}
31+
});
32+
33+
34+
Button btn = findViewById(R.id.button);
35+
btn.setOnClickListener(new View.OnClickListener() {
36+
@Override
37+
public void onClick(View view) {
38+
EditText txt = findViewById(R.id.editText);
39+
txt.setText("Clicked");
40+
}
41+
});
42+
}
43+
44+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
tools:context=".MainActivity">
8+
9+
<com.google.android.material.appbar.AppBarLayout
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content"
12+
android:theme="@style/AppTheme.AppBarOverlay">
13+
14+
<androidx.appcompat.widget.Toolbar
15+
android:id="@+id/toolbar"
16+
android:layout_width="match_parent"
17+
android:layout_height="?attr/actionBarSize"
18+
android:background="?attr/colorPrimary"
19+
app:popupTheme="@style/AppTheme.PopupOverlay" />
20+
21+
</com.google.android.material.appbar.AppBarLayout>
22+
23+
<com.google.android.material.floatingactionbutton.FloatingActionButton
24+
android:id="@+id/fab"
25+
android:layout_width="wrap_content"
26+
android:layout_height="wrap_content"
27+
android:layout_gravity="bottom|end"
28+
android:layout_margin="@dimen/fab_margin"
29+
app:srcCompat="@android:drawable/ic_dialog_email" />
30+
31+
<include layout="@layout/content_main" />
32+
33+
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
app:layout_behavior="@string/appbar_scrolling_view_behavior"
8+
tools:context=".MainActivity"
9+
tools:showIn="@layout/activity_main">
10+
11+
<Button
12+
android:id="@+id/button"
13+
android:layout_width="match_parent"
14+
android:layout_height="100dp"
15+
android:text="@string/click_me"
16+
app:layout_constraintEnd_toEndOf="parent"
17+
app:layout_constraintStart_toStartOf="parent"
18+
app:layout_constraintTop_toTopOf="parent"></Button>
19+
20+
<EditText
21+
android:id="@+id/editText"
22+
android:layout_width="match_parent"
23+
android:layout_height="wrap_content"
24+
android:layout_marginTop="13dp"
25+
android:ems="10"
26+
android:inputType="textPersonName"
27+
android:text="Default text"
28+
app:layout_constraintEnd_toEndOf="parent"
29+
app:layout_constraintHorizontal_bias="0.0"
30+
app:layout_constraintStart_toStartOf="parent"
31+
app:layout_constraintTop_toBottomOf="@+id/button" />
32+
33+
</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/values/dimens.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<dimen name="fab_margin">16dp</dimen>
3+
</resources>

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
<resources>
22
<string name="app_name">android</string>
3+
<string name="title_activity_main">MainActivity</string>
4+
<string name="click_me">Click me</string>
35
</resources>

app/src/main/res/values/styles.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,13 @@
88
<item name="colorAccent">@color/colorAccent</item>
99
</style>
1010

11+
<style name="AppTheme.NoActionBar">
12+
<item name="windowActionBar">false</item>
13+
<item name="windowNoTitle">true</item>
14+
</style>
15+
16+
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
17+
18+
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
19+
1120
</resources>

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ allprojects {
2121
jcenter()
2222
maven {
2323
url 'https://jitpack.io'
24-
credentials { username authToken }
2524
}
25+
mavenLocal()
2626
}
2727
}
2828

gradle.properties

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,4 @@ org.gradle.jvmargs=-Xmx1536m
1616
# https://developer.android.com/topic/libraries/support-library/androidx-rn
1717
android.useAndroidX=true
1818
# Automatically convert third-party libraries to use AndroidX
19-
android.enableJetifier=true
20-
21-
authToken=jp_ssr9q6vpqgjv54e9iqv7kkg8g3
19+
android.enableJetifier=true

0 commit comments

Comments
 (0)