Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Getting Started with GhostDriver (Selenium Conference 2013 / Boston)

Getting Started with GhostDriver (Selenium Conference 2013 / Boston)

In this presentation I explain how to start using GhostDriver, the WebDriver implementation for PhantomJS.
Also, I provide some examples of "alternative uses" of GhostDriver - link to the code is in the slides

Conference: Selenium Conference 2013 (http://www.seleniumconf.org/)
Location: Boston, MA, USA
Date: 10-12 June 2013

Ceceb3557075de3a5344196525a41244?s=128

Ivan De Marino

June 11, 2013
Tweet

Transcript

  1. Getting Started with GhostDriver Ivan De Marino Selenium Conference 2013,

    Boston, USA Find these slides at: http://bit.ly/15wfQnD
  2. CompSci Coder Cook Italian Currently @ Amazon @detronizator / github.com/detro

    #PhantomJS #GhostDriver #andstuff Me up the Snowdonia Railway (Wales, UK)
  3. GhostDriver, PhantomJS and WebDriver WebDriver Script WebDriver Binding Library GhostDriver

    HTTP + REST + JSON (Wire Protocol) http://docs.seleniumhq.org/ https://github.com/detro/ghostdriver http://phantomjs.org
  4. PhantomJS "Headless" WebKit browser 1.9.x GhostDriver WebDriver implementation for PhantomJS

    1.0.3 PhantomJS Driver WebDriver Bindings for GhostDriver 1.0.3 ENCAPSULATION 2.0.x 1.1.x 1.1.x stable dev
  5. Why should I care? Headless: good for build servers &

    CI Fast (don't have measurements, sorry) A real browser engine (no emulation) Site scraping & thumbnailing No idea - And that is the point!!!
  6. Setup

  7. Download $> wget http://phantomjs.googlecode.com/files/phantomjs-<version>-<OS>.zip && unzip ... download PhantomJS OR,

    clone & build PhantomJS $> git clone https://github.com/ariya/phantomjs.git && cd phantomjs $> ./build.sh $> ... ... go make some coffee ... $> cd bin && ./phantomjs $> export PATH=`pwd`:$PATH ... this is optional ... (optional) clone GhostDriver (instead of embedded version) $> git clone https://github.com/detro/ghostdriver.git
  8. Bindings <dependency> <groupId>com.github.detro.ghostdriver</groupId> <artifactId>phantomjsdriver</artifactId> <version>1.0.3</version> </dependency> ... or ... dependencies

    { testCompile "com.github.detro.ghostdriver.phantomjsdriver.1.0.3" } Java Python $> [sudo] easy_install selenium or $> [sudo] pip install selenium Ruby $> gem install selenium-webdriver .Net PM> Install-Package Selenium.WebDriver
  9. Capabilities DesiredCapabilities caps = new DesiredCapabilities(); // If executable not

    added to $PATH caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "/path/to/phantomjs"); // If don't want to use embedded GhostDriver caps.setCapability(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY, "/path/to/ghostdriver/src/main.js"); WebDriver driver = new PhantomJSDriver(caps); Java for Python / Ruby / .Net check documentation
  10. Code introduce dummy examples

  11. Capabilities: Page Settings DesiredCapabilities caps = new DesiredCapabilities(); // Change

    setting X to Y on every Web Page created during this WebDriver session // NOTE: Can use PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX caps.setCapability("phantomjs.page.settings.X", "Y"); ... Possible Settings (might change in the future) page.settings => { "XSSAuditingEnabled": false, "javascriptCanCloseWindows": true, "javascriptCanOpenWindows": true, "javascriptEnabled": true, "loadImages": true, "localToRemoteUrlAccessEnabled": false, "userAgent": "... AppleWebKit/534.34 ... PhantomJS/1.9.0 (development) ...", "webSecurityEnabled": true }
  12. Code Page Settings

  13. PhantomJS CLI Usage: phantomjs [switches] [options] [script] [argument [argument [...]]]

    Options: --cookies-file=<val> ... --ignore-ssl-errors=<val> ... --load-images=<val> --proxy=<val> --proxy-auth=<val> --proxy-type=<val> ... --webdriver=<val> Starts in 'Remote WebDriver mode'... --webdriver-logfile=<val> File where to write the WebDriver's Log... --webdriver-loglevel=<val> WebDriver Logging Level... --webdriver-selenium-grid-hub=<val> URL to the Selenium Grid HUB... -w,--wd Equivalent to '--webdriver' option above
  14. Capabilities: passing args to PhantomJS DesiredCapabilities caps = new DesiredCapabilities();

    // Provide Array of String that will be passed as args to the PhantomJS executable String[] args = new String[] { "--ignore-ssl-errors=yes" }; caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, args); ...
  15. Code Passing CLI arguments & WebDriver-mode

  16. Examples https://github.com/detro/phantomjsdriver-examples

  17. Code: scraping Twitter API

  18. None
  19. Code: drawing Colorwheel

  20. Code: thumbnailer Website Screenshot

  21. Present & Future

  22. Commands not yet implemented • Screen/Device Orientation • JavaScript Alert

    / Confirm / Prompt • Touch • GeoLocation • Local / Session Storage • Logs details at: http://bit.ly/VDYB0Q
  23. Expose PhantomJS specific features

  24. Go multi-process (yes, like ChromeDriver)

  25. None
  26. Questions? Thank you! PhantomJS: http://phantomjs.org GhostDriver: http://github.com/detro/ghostdriver Ivan De Marino:

    http://ivandemarino.me Examples: https://github.com/detro/phantomjsdriver-examples