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

Getting Started with GhostDriver (Selenium Camp...

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

Ivan De Marino

March 01, 2013
Tweet

More Decks by Ivan De Marino

Other Decks in Programming

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

    / Confirm / Prompt • Touch • GeoLocation • Local / Session Storage • Logs details at: http://bit.ly/VDYB0Q
  12. 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."
  13. 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"}; ...```
  14. Don't know how to solve a problem? Wait until you

    do! (or someone else does) lesson learned #4