Skip to content

Instantly share code, notes, and snippets.

@billmeyer
Last active December 17, 2019 04:14
Show Gist options
  • Save billmeyer/6b727b9381823bbf52135e193511cee6 to your computer and use it in GitHub Desktop.
Save billmeyer/6b727b9381823bbf52135e193511cee6 to your computer and use it in GitHub Desktop.
Command Line Selenium Session

Create the Session

NOTE: Be sure to set the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables first!

    curl -v -u ${SAUCE_USERNAME}:${SAUCE_ACCESS_KEY} \
        https://ondemand.saucelabs.com/wd/hub/session -X POST \
        -d '{"desiredCapabilities": {"browserName":"firefox"}}' | jq "."

Find the "sessionId" in the output:

    {
      "status": 0,
      ...
      "sessionId": "77056626e8e74d3c9b2f13e7a96a5ce8",
      "hCode": 9059012,
      "class": "org.openqa.selenium.remote.Response"
    }

Set an environment variable for the value:

set SESSIONID=77056626e8e74d3c9b2f13e7a96a5ce8

Navigate

    curl -v -u ${SAUCE_USERNAME}:${SAUCE_ACCESS_KEY} \
        https://ondemand.saucelabs.com/wd/hub/session/${SESSIONID}/url \
        -X POST -d '{"url": "http://google.com"}' | jq "."

Destroy the session

    curl -v -u ${SAUCE_USERNAME}:${SAUCE_ACCESS_KEY} \
        https://ondemand.saucelabs.com/wd/hub/session/${SESSIONID} \
        -X DELETE | jq "."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment