|
| 1 | +hogwarts() { |
| 2 | + echo ' |
| 3 | +# __ __ |
| 4 | +# / /_ ____ ____ __ ______ ______/ /______ |
| 5 | +# / __ \/ __ \/ __ `/ | /| / / __ `/ ___/ __/ ___/ |
| 6 | +# / / / / /_/ / /_/ /| |/ |/ / /_/ / / / /_(__ ) |
| 7 | +# /_/ /_/\____/\__, / |__/|__/\__,_/_/ \__/____/ |
| 8 | +# /____/ |
| 9 | +' |
| 10 | + echo "Hogwarts Testing Kit" |
| 11 | + echo |
| 12 | + |
| 13 | + local help install start |
| 14 | + ARGS="install start" pp "$@" |
| 15 | + |
| 16 | + if [ -n "$help" -o "$#" = 0 ]; then |
| 17 | + echo "hogwarts provide such functions" |
| 18 | + grep "() *{" $BASHGEMS_HOME/lib/hogwarts.sh |
| 19 | + return |
| 20 | + fi |
| 21 | + if [ -n "$install" ]; then |
| 22 | + eval hogwarts_install_$install |
| 23 | + fi |
| 24 | +} |
| 25 | + |
| 26 | +#use some command with proxy |
| 27 | +#proxy npm install -g appium |
| 28 | +proxy() { |
| 29 | + local http_proxy https_proxy |
| 30 | + if curl -s http://www.baidu.com -x http://127.0.0.1:3128 &>/dev/null; then |
| 31 | + http_proxy=http://127.0.0.1:3128 https_proxy=$http_proxy "$@" |
| 32 | + else |
| 33 | + http_proxy=http://39.105.132.200:$(date +6%m%d) https_proxy=$http_proxy "$@" |
| 34 | + fi |
| 35 | +} |
| 36 | + |
| 37 | +chromedriver_list() { |
| 38 | + curl https://raw.githubusercontent.com/appium/appium/master/docs/en/writing-running-appium/web/chromedriver.md 2>/dev/null | grep "|" | grep -v "2.[0-9] " | grep -v "2.1[0-9]" |
| 39 | + echo chromedriver in CN: https://npm.taobao.org/mirrors/chromedriver |
| 40 | + echo chromedriver in US: http://chromedriver.storage.googleapis.com/ |
| 41 | + echo chromedriver vs chrome version: https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md |
| 42 | +} |
| 43 | + |
| 44 | +hogwarts_install_test() { |
| 45 | + echo "${FUNCNAME[1]} -> ${FUNCNAME[0]}" |
| 46 | +} |
| 47 | +hogwarts_install_stf() { |
| 48 | + brew install rethinkdb graphicsmagick zeromq protobuf yasm pkg-config |
| 49 | + npm install -g stf |
| 50 | +} |
| 51 | + |
| 52 | +Hogwarts_start_stf() { |
| 53 | + rethinkdb & |
| 54 | + stf local |
| 55 | +} |
| 56 | + |
| 57 | +hogwarts_install_jenkins() { |
| 58 | + local image=jenkins/jenkins:lts |
| 59 | + docker run -ti --rm --entrypoint="/bin/bash" $image -c "whoami && id" |
| 60 | + echo "maybe you need chown -R 1000 ~/jenkins/hogwarts" |
| 61 | + docker run -d --name jenkins_hogwarts \ |
| 62 | + -p 8080:8080 -p 50000:50000 \ |
| 63 | + -v ~/jenkins/hogwarts:/var/jenkins_home \ |
| 64 | + $image |
| 65 | + echo "you need use such password for init" |
| 66 | + docker exec jenkins_hogwarts sh -c 'cat /var/jenkins_home/secrets/initialAdminPassword' |
| 67 | +} |
| 68 | + |
| 69 | +hogwarts_install_appium() { |
| 70 | + if which node; then |
| 71 | + npm version |
| 72 | + else |
| 73 | + echo you should install node 8 or above |
| 74 | + if which brew; then |
| 75 | + brew install node |
| 76 | + else |
| 77 | + echo you should install brew by /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" |
| 78 | + fi |
| 79 | + fi |
| 80 | + which java || echo you should install java |
| 81 | + which adb || echo you should install android sdk and put adb directory in your PATH |
| 82 | + echo search appium versions |
| 83 | + proxy npm view appium versions --json | tail |
| 84 | + echo start install appium |
| 85 | + proxy npm install -g appium --verbose |
| 86 | + echo start install ios testing toolkit |
| 87 | + if which brew; then |
| 88 | + brew info libimobiledevice || brew install libimobiledevice |
| 89 | + brew info ios-webkit-debug-proxy || brew install ios-webkit-debug-proxy |
| 90 | + fi |
| 91 | + echo start install ios-deploy |
| 92 | + npm info ios-deploy || npm install -g ios-deploy --verbose |
| 93 | + appium --version |
| 94 | +} |
| 95 | + |
| 96 | +hogwarts_get_capabilitys_android() { |
| 97 | + local info=$(adb logcat -d "*:S" "ActivityManager:I" | grep -i displayed | grep -o '[^/ ]*/[^: ]*') |
| 98 | + local package=$(echo "$info" | awk -F/ '{print $1}' | tail -1) |
| 99 | + local activity=$(echo "$info" | grep $package | head -1 | awk -F/ '{print $2}') |
| 100 | + echo " |
| 101 | + { |
| 102 | + \"platformName\": \"android\", |
| 103 | + \"deviceName\": \"hogwarts\", |
| 104 | + \"automationName\": \"uiautomator2\", |
| 105 | + \"appPackage\": \"$package\", |
| 106 | + \"appActivity\": \"$activity\" |
| 107 | + } |
| 108 | + " |
| 109 | +} |
| 110 | + |
| 111 | +hogwarts_start_avd() { |
| 112 | + local name=$(emulator -list-avds | grep $1) |
| 113 | + ( |
| 114 | + cd $(dirname $(which emulator)) |
| 115 | + emulator @$name |
| 116 | + ) |
| 117 | +} |
0 commit comments