Test your websites with this simple GUI based scripted webtester. Generate simple testscripts directly from surfng on the webpage, enhance them with your commands, with variables, loops, checks, … and finally run automated web tests.
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

162 líneas
4.1 KiB

  1. #!/bin/bash -e
  2. # documentation: run with option --help
  3. ##########################################################################################
  4. #### template for bash scripts #### START BELOW ##########################################
  5. ##########################################################################################
  6. ############################################################################ begin logging
  7. # check if stdout is a terminal...
  8. if test -t 1; then
  9. # see if it supports colors...
  10. ncolors=$(tput colors)
  11. if test -n "$ncolors" && test $ncolors -ge 8; then
  12. bold="$(tput bold)"
  13. underline="$(tput smul)"
  14. standout="$(tput smso)"
  15. normal="$(tput sgr0)"
  16. black="$(tput setaf 0)"
  17. red="$(tput setaf 1)"
  18. green="$(tput setaf 2)"
  19. yellow="$(tput setaf 3)"
  20. blue="$(tput setaf 4)"
  21. magenta="$(tput setaf 5)"
  22. cyan="$(tput setaf 6)"
  23. white="$(tput setaf 7)"
  24. fi
  25. fi
  26. append_msg() {
  27. if test $# -ne 0; then
  28. echo -n ": ${bold}$*"
  29. fi
  30. echo "${normal}"
  31. }
  32. # write a message
  33. message() {
  34. if test $# -eq 0; then
  35. return
  36. fi
  37. echo "${bold}${white}$*${normal}" 1>&2
  38. }
  39. # write a success message
  40. success() {
  41. echo -n "${bold}${green}success" 1>&2
  42. append_msg "$*" 1>&2
  43. }
  44. # write a notice
  45. notice() {
  46. echo -n "${bold}${yellow}notice" 1>&2
  47. append_msg "$*" 1>&2
  48. }
  49. # write a warning message
  50. warning() {
  51. echo -en "${bold}${red}warning" 1>&2
  52. append_msg "$*" 1>&2
  53. }
  54. # write error message
  55. error() {
  56. echo -en "${bold}${red}error" 1>&2
  57. append_msg "$*" 1>&2
  58. }
  59. # run a command, print the result and abort in case of error
  60. # option: --ignore: ignore the result, continue in case of error
  61. run() {
  62. ignore=1
  63. while test $# -gt 0; do
  64. case "$1" in
  65. (--ignore) ignore=0;;
  66. (*) break;;
  67. esac
  68. shift;
  69. done
  70. echo -n "${bold}${yellow}running:${white} $*${normal} … "
  71. set +e
  72. result=$($* 2>&1)
  73. res=$?
  74. set -e
  75. if test $res -ne 0; then
  76. if test $ignore -eq 1; then
  77. error "failed with return code: $res"
  78. if test -n "$result"; then
  79. echo "$result"
  80. fi
  81. exit 1
  82. else
  83. warning "ignored return code: $res"
  84. return 0
  85. fi
  86. else
  87. return 1
  88. fi
  89. }
  90. ############################################################################ error handler
  91. function traperror() {
  92. set +x
  93. local err=($1) # error status
  94. local line="$2" # LINENO
  95. local linecallfunc="$3"
  96. local command="$4"
  97. local funcstack="$5"
  98. IFS=" "
  99. for e in ${err[@]}; do
  100. if test -n "$e" -a "$e" != "0"; then
  101. error "line $line - command '$command' exited with status: $e (${err[@]})"
  102. if [ "${funcstack}" != "main" -o "$linecallfunc" != "0" ]; then
  103. echo -n " ... error at ${funcstack} " 1>&2
  104. if [ "$linecallfunc" != "" ]; then
  105. echo -n "called at line $linecallfunc" 1>&2
  106. fi
  107. echo
  108. fi
  109. exit $e
  110. fi
  111. done
  112. exit 0
  113. }
  114. # catch errors
  115. trap 'traperror "$? ${PIPESTATUS[@]}" $LINENO $BASH_LINENO "$BASH_COMMAND" "${FUNCNAME[@]}" "${FUNCTION}"' ERR SIGINT INT TERM EXIT
  116. ##########################################################################################
  117. #### START HERE ##########################################################################
  118. ##########################################################################################
  119. ######################################################### commandline parameter evaluation
  120. while test $# -gt 0; do
  121. case "$1" in
  122. (--help|-h) cat <<EOF
  123. SYNOPSIS
  124. $0 [OPTIONS]
  125. OPTIONS
  126. --help, -h show this help
  127. DESCRIPTION
  128. EOF
  129. exit;;
  130. (*) error "unknow option $1, try $0 --help"; exit 1;;
  131. esac
  132. if test $# -eq 0; then
  133. error "missing parameter, try $0 --help"; exit 1
  134. fi
  135. shift;
  136. done
  137. ##################################################################################### Main