androidScreenshotTest 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. cd 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. sed -i s'#<bool name="is_beta">false</bool>#<bool name="is_beta">true</bool>#'g src/main/res/values/setup.xml
  39. # check if emulator is running
  40. emulatorIsRunning=false
  41. while read line ; do
  42. if [[ $(adb -s $line emu avd name 2>/dev/null | head -n1) =~ uiComparison.* ]]; then
  43. emulatorIsRunning=true
  44. export ANDROID_SERIAL=$line
  45. break
  46. fi
  47. done < <(adb devices | cut -f1)
  48. if [ "$emulatorIsRunning" == false ] ; then
  49. "$(command -v emulator)" -writable-system -avd uiComparison -no-snapshot -gpu swiftshader_indirect -no-audio -skin 500x833 &
  50. fi
  51. if [ -e $5 ] ; then
  52. color=""
  53. else
  54. color="-Pandroid.testInstrumentationRunnerArguments.COLOR=$5"
  55. fi
  56. if [[ $4 = "all" ]]; then
  57. scripts/runAllScreenshotCombinations "noCI" "$1" "-Pandroid.testInstrumentationRunnerArguments.class=$class$method"
  58. else
  59. ./gradlew --offline gplayDebugExecuteScreenshotTests $record \
  60. -Pscreenshot=true \
  61. -Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotTest \
  62. -Pandroid.testInstrumentationRunnerArguments.class=$class$method \
  63. $darkMode \
  64. $color
  65. fi
  66. sed -i s'#<bool name="is_beta">true</bool>#<bool name="is_beta">false</bool>#'g src/main/res/values/setup.xml
  67. unset ANDROID_SERIAL