androidScreenshotTest 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. fi
  52. if [ -e $5 ] ; then
  53. color=""
  54. else
  55. color="-Pandroid.testInstrumentationRunnerArguments.COLOR=$5"
  56. fi
  57. if [[ $4 = "all" ]]; then
  58. scripts/runAllScreenshotCombinations "noCI" "$1" "-Pandroid.testInstrumentationRunnerArguments.class=$class$method"
  59. else
  60. ./gradlew --offline gplayDebugExecuteScreenshotTests $record \
  61. -Pscreenshot=true \
  62. -Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotTest \
  63. -Pandroid.testInstrumentationRunnerArguments.class=$class$method \
  64. $darkMode \
  65. $color
  66. fi
  67. sed -i s'#<bool name="is_beta">true</bool>#<bool name="is_beta">false</bool>#'g app/src/main/res/values/setup.xml
  68. unset ANDROID_SERIAL