Skip to content

Commit

Permalink
finish release plugins configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
nenick committed Mar 14, 2016
1 parent 1d07ed0 commit c2e7519
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 3 deletions.
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## Release 0.1.0
#### New in release 0.1.0

First basic functionality to test an android application.
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@ deployment:
# push release artifacts to github
- ./gradlew :library:githubRelease -PgithubUser=$GITHUB_USERNAME -PgithubKey=$GITHUB_WRITE_PUBLIC_REPOS_TOKEN
# push release artifacts to bintray
- ./gradlew -PbintrayUser=$BINTRAY_USERNAME -PbintrayKey=$BINTRAY_KEY -PdryRun=false
- ./gradlew :library:bintrayUpload -PbintrayUser=$BINTRAY_USERNAME -PbintrayKey=$BINTRAY_KEY -PdryRun=false
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package de.nenick.espressotools;

import android.app.Activity;
import android.content.Context;
import android.support.annotation.IdRes;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.Espresso;
import android.support.test.espresso.FailureHandler;
import android.support.test.espresso.base.DefaultFailureHandler;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;

import org.hamcrest.Matcher;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
Expand All @@ -29,6 +34,7 @@ public abstract class EspressoTestCase<A extends Activity> {

@Before
public void setupEspresso() {
Espresso.setFailureHandler(new CustomFailureHandler(activityTestRule.getActivity()));
avoidLockScreen();
}

Expand Down Expand Up @@ -78,4 +84,19 @@ private Class<A> getGenericActivityClass() {
throw new IllegalArgumentException("Please provide generic start activity for " + getClass().getSimpleName() + " (e.g. extends EspressoTestCase<MyStartActivity>)");
}
}

private class CustomFailureHandler implements FailureHandler {
private final FailureHandler delegate;

public CustomFailureHandler(Context targetContext) {
delegate = new DefaultFailureHandler(targetContext);
}

@Override
public void handle(Throwable error, Matcher<View> viewMatcher) {
//ScreenShot.take();
delegate.handle(error, viewMatcher);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package de.nenick.espressotools;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Environment;
import android.util.Log;
import android.view.View;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
* https://mobile.awsblog.com/post/TxP90JPTTBPE17/Getting-started-with-Android-testing-on-AWS-Device-Farm-using-Espresso-Part-2-Se
*/
public class ScreenShot {

private static final String TAG = "SCREENSHOT_TAG";

public static void take(Activity activity, String name) {
final String dir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/test-screenshots/";
final String path = dir + name;

File filePath = new File(dir); // Create directory if not present
if (!filePath.isDirectory()) {
Log.i(TAG, "Creating directory " + filePath);
if(!filePath.mkdirs()) {
Log.i(TAG, "Creating directory failed " + filePath);
}
}

Log.i(TAG, "Saving to path: " + path);

View phoneView = activity.getWindow().getDecorView().getRootView();
phoneView.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(phoneView.getDrawingCache());
phoneView.setDrawingCacheEnabled(false);

OutputStream out = null;

File imageFile = new File(path);

try {
out = new FileOutputStream(imageFile);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
} catch (IOException e) {
Log.e(TAG, e.toString());
}

finally {
try {
if (out != null) {
out.close();
}
} catch (IOException e) {
Log.e(TAG, e.toString());
}
}
}
}
4 changes: 3 additions & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ def currentReleaseTag = { ->
exec {
commandLine 'git', 'describe', '--tags', '--match', 'release*'
standardOutput = stdout
ignoreExitValue = true
}
return stdout.toString().trim()
def releaseTag = stdout.toString().trim()
return releaseTag ? releaseTag : "release-0.0.0"
}

// plugin configuration to publish release artifacts to bintray
Expand Down

0 comments on commit c2e7519

Please sign in to comment.