-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from fs/take-screenshots-when-ui-tests-failed
Take screenshots when ui tests failed
- Loading branch information
Showing
11 changed files
with
185 additions
and
40 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
adb=$ANDROID_HOME/platform-tools/adb | ||
package=$1 | ||
|
||
if [ "$#" = 0 ]; then | ||
echo "No parameters found, run with sh set_animation_permissions.sh <package>" | ||
exit 0 | ||
fi | ||
|
||
# get all the devices | ||
devices=$($adb devices | grep -v 'List of devices' | cut -f1 | grep '.') | ||
|
||
for device in $devices; do | ||
echo "Setting permissions to device" $device "for package" $package | ||
$adb -s $device shell pm grant $package android.permission.SET_ANIMATION_SCALE | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<manifest | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.flatstack.android" | ||
> | ||
|
||
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/> | ||
<uses-permission android:name="android.permission.WAKE_LOCK"/> | ||
<!-- Disable animations on debug builds so that the animations do not interfere with Espresso | ||
tests. Adding this permission to the manifest is not sufficient - you must also grant the | ||
permission over adb! --> | ||
<uses-permission android:name="android.permission.SET_ANIMATION_SCALE"/> | ||
|
||
</manifest> |
34 changes: 34 additions & 0 deletions
34
app/src/androidTest/java/com/flatstack/android/MainScreenTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.flatstack.android; | ||
|
||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import com.flatstack.android.main_screen.MainActivity; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static android.support.test.espresso.Espresso.onView; | ||
import static android.support.test.espresso.assertion.ViewAssertions.matches; | ||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withId; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withText; | ||
import static org.hamcrest.Matchers.allOf; | ||
|
||
/** | ||
* Created by ereminilya on 6/4/17. | ||
*/ | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class MainScreenTest { | ||
|
||
@Rule | ||
public ScreenshotActivityRule<MainActivity> testRule = | ||
new ScreenshotActivityRule<>(MainActivity.class); | ||
|
||
@Test | ||
public void whenAppLaunch_androidBaseVisible() throws Exception { | ||
onView(allOf(withId(R.id.title), withText(R.string.app_name))) | ||
.check(matches(isDisplayed())); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
app/src/androidTest/java/com/flatstack/android/ScreenshotActivityRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.flatstack.android; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.espresso.Espresso; | ||
import android.support.test.espresso.base.DefaultFailureHandler; | ||
import android.support.test.rule.ActivityTestRule; | ||
|
||
import com.squareup.spoon.Spoon; | ||
|
||
import org.junit.runner.Description; | ||
import org.junit.runners.model.Statement; | ||
|
||
/** | ||
* Created by ereminilya on 6/4/17. | ||
*/ | ||
|
||
public class ScreenshotActivityRule<T extends Activity> extends ActivityTestRule<T> { | ||
|
||
public ScreenshotActivityRule(Class<T> activityClass) { | ||
super(activityClass); | ||
} | ||
|
||
@Override | ||
public Statement apply(Statement base, Description description) { | ||
String testClassName = description.getClassName(); | ||
String testMethodName = description.getMethodName(); | ||
Context context = InstrumentationRegistry.getTargetContext(); | ||
Espresso.setFailureHandler((error, matcher) -> { | ||
Spoon.screenshot(getActivity(), "failure", testClassName, testMethodName); | ||
new DefaultFailureHandler(context).handle(error, matcher); | ||
}); | ||
return super.apply(base, description); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters