Last active
August 29, 2015 13:56
-
-
Save brettscott/8859873 to your computer and use it in GitHub Desktop.
Ghostdriver debugging REST interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ------------------------------------------------------------------ | |
# Start Session | |
echo "/session :" | |
request="curl --include --data "{\"desiredCapabilities\":[{\"phantomjs.page.settings.userAgent\":\"iphone\"},{\"browserName\":\"phantomjs\"}]}" http://localhost:4444/wd/hub/session" | |
# Example response: {"sessionId":"67b0bfd0-8f4c-11e3-94f9-11808a4b2852","status":0,"value":{"browserName":"phantomjs","version":"1.9.2","driverName":"ghostdriver","driverVersion":"1.0.4","platform":"linux-unknown-64bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":false,"databaseEnabled":false,"locationContextEnabled":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"},"phantomjs.page.settings.userAgent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0 BBC-GNL-BDD"}} | |
response=$($request) | |
echo "Response:" | |
echo "$response" | |
echo " " | |
echo " " | |
# Obtain Session Id | |
# Example: 67b0bfd0-8f4c-11e3-94f9-11808a4b2852 | |
sessionString=$(egrep -io '"sessionId":"([^"]+)"' <<<"$response") | |
sessionId=$(echo "$sessionString" | cut -c14-49) | |
echo "SessionId: $sessionId" | |
echo " " | |
echo " " | |
# ------------------------------------------------------------------ | |
# Request Page | |
echo "/url :" | |
request="curl --include --data "{\"url\":\"http://localhost/index.html\"}" http://localhost:4444/wd/hub/session/$sessionId/url" | |
# Example response: {"sessionId":"67b0bfd0-8f4c-11e3-94f9-11808a4b2852","status":0,"value":{}} | |
response=$($request) | |
echo "Response:" | |
echo "$response" | |
echo " " | |
echo " " | |
# ------------------------------------------------------------------ | |
# Get Element contents (attempt #1) | |
echo "/element :" | |
request="curl --include --data "{\"using\":\"id\",\"value\":\"test\"}" http://localhost:4444/wd/hub/session/$sessionId/element" | |
# Example response: {"sessionId":"67b0bfd0-8f4c-11e3-94f9-11808a4b2852","status":0,"value":"Hello World"} | |
response=$($request) | |
echo "Response:" | |
echo "$response" | |
echo " " | |
echo " " | |
# ------------------------------------------------------------------ | |
# Get Element contents (attempt #2) | |
echo "/element :" | |
request="curl --include --data "{\"using\":\"id\",\"value\":\"test\"}" http://localhost:4444/wd/hub/session/$sessionId/element" | |
# Example response: {"sessionId":"67b0bfd0-8f4c-11e3-94f9-11808a4b2852","status":0,"value":{"ELEMENT":":wdc:1391612863730"}} | |
response=$($request) | |
echo "Response:" | |
echo "$response" | |
echo " " | |
echo " " | |
# Get Element ID | |
# Example: :wdc:1391612863730 | |
elementString=$(egrep -io '"ELEMENT":"([^"]+)"' <<<"$response") | |
elementId=$(echo "$elementString" | cut -c12-29) | |
echo "ElementId: $elementId" | |
echo " " | |
echo " " | |
# Example response: {"sessionId":"67b0bfd0-8f4c-11e3-94f9-11808a4b2852","status":0,"value":"Hello World"} | |
echo "/element/$elementId/text :" | |
request="curl --include --get http://localhost:4444/wd/hub/session/$sessionId/element/$elementId/text" | |
response=$($request) | |
echo "Response:" | |
echo "$response" | |
echo " " | |
echo " " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment