Created
January 16, 2023 15:08
-
-
Save Gazer/e1500d9b519ff58a0d32a0f5966ba289 to your computer and use it in GitHub Desktop.
Run UI test 50 times and record a video only when it fails. Handy to get evidence of Flaky tests.
This file contains hidden or 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
#!/bin/bash | |
silent_background() { | |
{ 2>&3 "$@"& } 3>&2 2>- | |
disown &>/dev/null # Close STD{OUT,ERR} for silence if job has already completed | |
} | |
if [ -z $1 ] ; then | |
echo "Pass the class name with full package name and the test method name." | |
echo " " | |
echo "$ ./flaky.sh com.example.TestCase#testMethod" | |
exit 1 | |
fi | |
COMMAND="./gradlew -Pandroid.testInstrumentationRunnerArguments.class=$1 app:connectedAndroidTest" | |
for i in `seq 1 50` ; do | |
echo -n "Test run #$i " | |
silent_background adb shell screenrecord /sdcard/video.mp4 & | |
$COMMAND > log_$i.txt 2>&1 | |
retVal=$? | |
ps ax | grep -v grep | grep screenrecord | cut -d ' ' -f 1 | xargs kill | |
if [ $retVal -eq 1 ]; then | |
echo -n "[Error]: pulling video_$i.mp4" | |
sleep 2 | |
while true ; do | |
ps ax | grep -v grep | grep screenrecord > /dev/null | |
if [ $? -eq 1 ] ; then | |
break; | |
fi | |
echo -n "." | |
sleep 1 | |
done | |
echo -n " " | |
adb pull /sdcard/video.mp4 2>&1 > /dev/null | |
mv video.mp4 video_$i.mp4 | |
fi | |
echo "[Done]" | |
sleep 2 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment