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

Getting Started with GhostDriver (Selenium Conf...

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

Ivan De Marino

June 11, 2013
Tweet

More Decks by Ivan De Marino

Other Decks in Programming

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. 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
  7. 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
  8. 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
  9. 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 }
  10. 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
  11. 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); ...
  12. Commands not yet implemented • Screen/Device Orientation • JavaScript Alert

    / Confirm / Prompt • Touch • GeoLocation • Local / Session Storage • Logs details at: http://bit.ly/VDYB0Q
  13. 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