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

Getting Started with GhostDriver (Selenium Camp 2013 / Kiev)

Getting Started with GhostDriver (Selenium Camp 2013 / Kiev)

"... and my experience working on it!".

In this presentation I explain how to start using GhostDriver, the WebDriver implementation for PhantomJS.

Conference: Selenium Camp 2013 (http://seleniumcamp.com/)
Location: Kiev, Ukraine
Date: 1-2 March 2013

Ceceb3557075de3a5344196525a41244?s=128

Ivan De Marino

March 01, 2013
Tweet

Transcript

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

    Kiev, Ukraine Find these slides at: http://bit.ly/VgKsYm and my experience working on it!
  2. CompSci Coder Cook Italian Currently @ Amazon @detronizator / github.com/detro

    #PhantomJS #GhostDriver #andstuff Me @ Snowdonia Railway
  3. WebDriver implementation for PhantomJS ( == GhostDriver) + WebDriver Bindings

    (== PhantomJSDriver) 1.0.2 current stable version (also embedded in PhantomJS) 1.0.3-dev current development version What's GhostDriver
  4. What's GhostDriver WebDriver Script WebDriver Binding Library GhostDriver HTTP +

    REST + JSON (Wire Protocol) http://docs.seleniumhq.org/ https://github.com/detro/ghostdriver http://phantomjs.org
  5. made with http://bramp.github.com/js-sequence-diagrams/

  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>LATEST_VERSION_HERE</version> </dependency> ... or ... dependencies

    { testCompile "com.github.detro.ghostdriver.phantomjsdriver.LATEST_VERSION_HERE" } 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. 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 }
  11. Capabilities: CLI Arguments (from 1.0.3) 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. Selenium Grid (optional) $> phantomjs --webdriver=[LOCAL_IP]:PORT --webdriver-selenium-grid-hub=URL_TO_HUB PhantomJS is launching

    GhostDriver... Ghost Driver running on port PORT start and connect to Grid request PhantomJS to the Grid Selenium sel = new DefaultSelenium("HUB_HOST", HUB_PORT, "*phantomjs", "http://example.com"); ... or ... DesiredCapabilities caps = new DesiredCapabilities.phantomjs(); caps.setBrowserName("phantomjs"); WebDriver driver = new RemoteWebDriver(new URL("HUB_URL"), caps); then proceed with your tests as usual...
  13. Commands not yet implemented • Screen/Device Orientation • JavaScript Alert

    / Confirm / Prompt • Touch • GeoLocation • Local / Session Storage • Logs details at: http://bit.ly/VDYB0Q
  14. Making a WebDriver

  15. None
  16. Code Hardening... is "hard" :-P

  17. Me, when I started the project

  18. Me, now!

  19. The BAD way to raise issues...

  20. The BAD way to raise issues... "My test works in

    Chrome and Firefox but not in PhantomJS. Please fix it." "We need feature X for my work. When do you plan to implement it?" "I got this test and it fails with error 'Not Implemented': why???? It checked with Firefox and Chrome!!! "Great project, but your code needs improvement. Your tests can only work if online. This is not how an Open Source project should be."
  21. GOOD ways to raise an issue Issue #159: Can't switch

    between nested frames Author: jarmo (Jarmo Pertman) Description: When running test spec that can be found here I get the following error message: ... Most probably related to the PhantomJS issue that can be found here Issue #154: Implement #149: Phantom CLI args via Capabilities Author: c089 (Christoph Neuroth) Description: Example usage to accept self-signed certificates: ```String[] args = {"--ignore-ssl-errors=yes"}; ...```
  22. Raising Issues: a Flow Chart

  23. Open Source and Me

  24. More awesome people at: http://docs.seleniumhq.org/about/contributors.jsp and https://github.com/ariya/phantomjs/contributors Open Source is

    a doers culture
  25. WireProtocol is just part of making a WebDriver lesson learned

    #1
  26. Never, ever, EVER(!) fix a bug. Write a test instead!

    lesson learned #2
  27. How to deal with issues while on Holiday? Ignore them!

    lesson learned #3
  28. Don't know how to solve a problem? Wait until you

    do! (or someone else does) lesson learned #4
  29. Someone trashed your code? Ask for a Pull Request! lesson

    learned #5
  30. Questions? Thank you! PhantomJS: http://phantomjs.org GhostDriver: http://github.com/detro/ghostdriver Ivan De Marino:

    http://ivandemarino.me