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

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

    View full-size slide

  2. CompSci Coder Cook Italian
    Currently @ Amazon
    @detronizator / github.com/detro
    #PhantomJS #GhostDriver #andstuff
    Me up the Snowdonia Railway (Wales, UK)

    View full-size slide

  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

    View full-size slide

  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

    View full-size slide

  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!!!

    View full-size slide

  6. Download
    $> wget http://phantomjs.googlecode.com/files/phantomjs--.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

    View full-size slide

  7. Bindings

    com.github.detro.ghostdriver
    phantomjsdriver
    1.0.3

    ... 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

    View full-size slide

  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

    View full-size slide

  9. Code
    introduce dummy examples

    View full-size slide

  10. 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
    }

    View full-size slide

  11. Code
    Page Settings

    View full-size slide

  12. PhantomJS CLI
    Usage:
    phantomjs [switches] [options] [script] [argument [argument [...]]]
    Options:
    --cookies-file=
    ...
    --ignore-ssl-errors=
    ...
    --load-images=
    --proxy=
    --proxy-auth=
    --proxy-type=
    ...
    --webdriver= Starts in 'Remote WebDriver mode'...
    --webdriver-logfile= File where to write the WebDriver's Log...
    --webdriver-loglevel= WebDriver Logging Level...
    --webdriver-selenium-grid-hub= URL to the Selenium Grid HUB...
    -w,--wd Equivalent to '--webdriver' option above

    View full-size slide

  13. 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);
    ...

    View full-size slide

  14. Code
    Passing CLI arguments & WebDriver-mode

    View full-size slide

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

    View full-size slide

  16. Code: scraping
    Twitter API

    View full-size slide

  17. Code: drawing
    Colorwheel

    View full-size slide

  18. Code: thumbnailer
    Website Screenshot

    View full-size slide

  19. Present & Future

    View full-size slide

  20. Commands not yet implemented
    ● Screen/Device Orientation
    ● JavaScript Alert / Confirm / Prompt
    ● Touch
    ● GeoLocation
    ● Local / Session Storage
    ● Logs
    details at: http://bit.ly/VDYB0Q

    View full-size slide

  21. Expose PhantomJS specific features

    View full-size slide

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

    View full-size slide

  23. 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

    View full-size slide