androidScreenshotTest 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/bash
  2. set -e
  3. if [ $# -lt 2 ]; then
  4. echo "1: record: true/false
  5. 2: class name
  6. 3: method name
  7. 4: darkMode: dark/light / \"all\" to run all screenshot combinations
  8. 5: color"
  9. exit
  10. fi
  11. pushd app/src/androidTest/java
  12. class=$(find | grep $2 | grep -E "java$|kt$" | head -n1|sed s'/\//\./'g | sed s'#^\.\.##' | sed s'#\.java##'| sed s'#\.kt##')
  13. if [[ -z $class ]]; then
  14. echo "Class not found!"
  15. exit 1
  16. fi
  17. cd ../../../
  18. if [ $1 == "true" ] ; then
  19. record="-Precord"
  20. else
  21. record=""
  22. fi
  23. if [ -e $3 ] ; then
  24. method=""
  25. else
  26. method="#$3"
  27. # check if method exists
  28. if [[ $(grep -c $3 $(find | grep $2 | grep -E "java$|kt$" | head -n1)) -eq 0 ]]; then
  29. echo "Method not found!"
  30. exit 1
  31. fi
  32. fi
  33. if [ -e $4 ] ; then
  34. darkMode=""
  35. else
  36. darkMode="-Pandroid.testInstrumentationRunnerArguments.DARKMODE=$4"
  37. fi
  38. popd
  39. sed -i s'#<bool name="is_beta">false</bool>#<bool name="is_beta">true</bool>#'g app/src/main/res/values/setup.xml
  40. # check if emulator is running
  41. emulatorIsRunning=false
  42. while read line ; do
  43. if [[ $(adb -s $line emu avd name 2>/dev/null | head -n1) =~ uiComparison.* ]]; then
  44. emulatorIsRunning=true
  45. export ANDROID_SERIAL=$line
  46. break
  47. fi
  48. done < <(adb devices | cut -f1)
  49. if [ "$emulatorIsRunning" == false ] ; then
  50. "$(command -v emulator)" -writable-system -avd uiComparison -no-snapshot -gpu swiftshader_indirect -no-audio -skin 500x833 &
  51. sleep 20
  52. fi
  53. if [ -e $5 ] ; then
  54. color=""
  55. else
  56. color="-Pandroid.testInstrumentationRunnerArguments.COLOR=$5"
  57. fi
  58. if [[ $4 = "all" ]]; then
  59. scripts/runAllScreenshotCombinations "noCI" "$1" "-Pandroid.testInstrumentationRunnerArguments.class=$class$method"
  60. else
  61. ./gradlew --offline gplayDebugExecuteScreenshotTests $record \
  62. -Pscreenshot=true \
  63. -Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotTest \
  64. -Pandroid.testInstrumentationRunnerArguments.class=$class$method \
  65. $darkMode \
  66. $color
  67. fi
  68. sed -i s'#<bool name="is_beta">true</bool>#<bool name="is_beta">false</bool>#'g app/src/main/res/values/setup.xml
  69. unset ANDROID_SERIAL