-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Espresso test wit screenshot compare
- Loading branch information
Showing
6 changed files
with
187 additions
and
2 deletions.
There are no files selected for viewing
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,3 @@ | ||
[submodule "android/git-diff-image"] | ||
path = android/git-diff-image | ||
url = git@github.com:ewanmellor/git-diff-image.git |
Submodule git-diff-image
added at
f12098
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
39 changes: 39 additions & 0 deletions
39
android/mainSample/src/androidTest/java/com/example/virosample/ExtendedMainTest.kt
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,39 @@ | ||
package com.example.virosample | ||
|
||
import android.view.Gravity | ||
import androidx.test.core.graphics.writeToTestStorage | ||
import androidx.test.espresso.Espresso | ||
import androidx.test.espresso.assertion.ViewAssertions.matches | ||
import androidx.test.espresso.contrib.DrawerActions | ||
import androidx.test.espresso.contrib.DrawerMatchers.isClosed | ||
import androidx.test.espresso.matcher.ViewMatchers | ||
import androidx.test.espresso.matcher.ViewMatchers.withId | ||
import androidx.test.espresso.screenshot.captureToBitmap | ||
import androidx.test.ext.junit.rules.activityScenarioRule | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.TestName | ||
import org.junit.runner.RunWith | ||
|
||
|
||
@RunWith(AndroidJUnit4::class) | ||
class ExtendedMainTest { | ||
|
||
@get:Rule | ||
var nameRule = TestName() | ||
|
||
@get:Rule | ||
val activityScenarioRule = activityScenarioRule<MLMainActivity>() | ||
|
||
@Test | ||
fun mainSmokeTest() { | ||
Espresso.onView(withId(R.id.drawer_layout)) | ||
.check(matches(isClosed(Gravity.LEFT))) // Left Drawer should be closed. | ||
.perform(DrawerActions.open()) | ||
Espresso.onView(ViewMatchers.isRoot()) | ||
.captureToBitmap() | ||
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-End") | ||
} | ||
|
||
} |
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,53 @@ | ||
#!/bin/bash | ||
|
||
diffFiles=./screenshotDiffs | ||
mkdir $diffFiles | ||
set -x | ||
./git-diff-image/install.sh | ||
GIT_DIFF_IMAGE_OUTPUT_DIR=$diffFiles git diff-image | ||
|
||
source scripts/lib.sh | ||
|
||
PR=$(echo "$GITHUB_REF_NAME" | sed "s/\// /" | awk '{print $1}') | ||
echo pr=$PR | ||
brew install jq | ||
|
||
echo "delete all old comments, starting with Screenshot differs:$emulatorApi" | ||
oldComments=$(curl_gh -X GET https://api.github.com/repos/"$GITHUB_REPOSITORY"/issues/"$PR"/comments | jq '.[] | (.id |tostring) + "|" + (.user.login | test("github-actions") | tostring) + "|" + (.body | test("Screenshot differs:'$emulatorApi'.*") | tostring)' | grep "true|true" | tr -d "\"" | cut -f1 -d"|") | ||
echo "comments=$comments" | ||
echo "$oldComments" | while read comment; do | ||
echo "delete comment=$comment" | ||
curl_gh -X DELETE https://api.github.com/repos/"$GITHUB_REPOSITORY"/issues/comments/"$comment" | ||
done | ||
|
||
pushd $diffFiles | ||
body="" | ||
COUNTER=0 | ||
ls -la | ||
|
||
# ignore an error, when no files where found https://unix.stackexchange.com/a/723909/201876 | ||
setopt no_nomatch | ||
for f in *.png; do | ||
if [[ ${f} == "*.png" ]] | ||
then | ||
echo "nothing found" | ||
else | ||
(( COUNTER++ )) | ||
|
||
newName="$1-${f}" | ||
mv "${f}" "$newName" | ||
echo "==> Uploaded screenshot $newName" | ||
curl -i -F "file=@$newName" https://www.mxtracks.info/github | ||
echo "==> Add screenshot comment $PR" | ||
body="$body ${f}![screenshot](https://www.mxtracks.info/github/uploads/$newName) <br/><br/>" | ||
fi | ||
done | ||
|
||
if [ ! "$body" == "" ]; then | ||
curl_gh -X POST https://api.github.com/repos/"$GITHUB_REPOSITORY"/issues/$PR/comments -d "{ \"body\" : \"Screenshot differs:$emulatorApi $COUNTER <br/><br/> $body \" }" | ||
fi | ||
|
||
popd 1>/dev/null | ||
|
||
# set error when diffs are there | ||
[ "$(ls -A $diffFiles)" ] && exit 1 || exit 0 |