-
Notifications
You must be signed in to change notification settings - Fork 29
/
simple-calculator-test
executable file
·45 lines (36 loc) · 1.02 KB
/
simple-calculator-test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#! /bin/bash
#
# simple-calculator-test:
# - Starts Calculator Activity
# - Finds a Button corresponding to a digit (specified or random)
# - Clicks that Button
#
# prerequisites:
# - adb finds and list the device
# - ./culebratester2 start-server
# - jq installed (https://stedolan.github.io/jq/)
#
set -e
set +x
base_url=http://localhost:9987/v2/
do_curl() {
curl -s -H "accept: application/json" -H "Content-Type: application/json" "$@"
}
if [[ $1 == '-x' ]]
then
shift
set -x
fi
# start activity
pkg='com.google.android.calculator'
cls='com.android.calculator2.Calculator'
status=$(do_curl -X GET --output /dev/stderr -w '%{http_code}' "${base_url}/targetContext/startActivity?pkg=${pkg}&cls=${cls}")
[[ "$status" =~ 2.. ]] || exit 1
# digit to click
digit=${1:-${RANDOM:1:1}}
# find the button
sleep 2
oid=$(do_curl -f -X POST "${base_url}/uiDevice/findObject" \
-d "{'clazz': 'android.widget.Button', 'text':'${digit}'}" | jq .oid)
# click it
do_curl -f -X GET "${base_url}/uiObject2/${oid}/click" >/dev/null