Skip to content

Instantly share code, notes, and snippets.

@ngsankha
Created March 7, 2017 10:05
Show Gist options
  • Save ngsankha/e946fa5923c82ef369b8ff8b86bdec4d to your computer and use it in GitHub Desktop.
Save ngsankha/e946fa5923c82ef369b8ff8b86bdec4d to your computer and use it in GitHub Desktop.
#!/bin/bash
URL="http://localhost:19065"
BROWSER="firefox"
#######################
STATUS_CODE=`curl -s -o /dev/null -w "%{http_code}" $URL/status`
if STATUS_CODE==200; then
echo "Server ready"
SESSION_ID=`curl -s -u sankha1:AnyXX1mpzakvChYMgrC4 --data '{"desiredCapabilities":{"browserName":"firefox", "platform":"MAC"}}' $URL/session |
python -c 'import json,sys;obj=json.load(sys.stdin);print obj["sessionId"];'`
echo "Obtained Session ID $SESSION_ID"
RNDSTR=`python -c 'import random, string; print("".join(random.choice(string.letters + string.digits) for i in xrange(10000)));'`
echo "Navigating to google.com"
curl -s --data '{"url":"http://www.google.com"}' $URL/session/$SESSION_ID/url > /dev/null
ELEMENT=`curl -s --data '{"using":"xpath", "value":"//*[@id=\"lst-ib\"]"}' $URL/session/$SESSION_ID/element |
python -c 'import json,sys;obj=json.load(sys.stdin);print obj;'`
echo $ELEMENT
echo "Searching for browserstack"
curl -s --data '{"value": ["b", "r", "o", "w", "s", "e", "r", "s", "t", "a", "c", "k"]}' $URL/session/$SESSION_ID/element/$ELEMENT/value > /dev/null
curl -s -X POST $URL/session/$SESSION_ID/element/$ELEMENT/submit > /dev/null
sleep 2
TITLE=`curl -s $URL/session/$SESSION_ID/title |
python -c 'import json,sys;obj=json.load(sys.stdin);print obj["value"];'`
echo "Page title: $TITLE"
curl -s -X DELETE $URL/session/$SESSION_ID > /dev/null
echo "Closed session $SESSION_ID"
else
echo "Server not responding"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment