Slide 1

Slide 1 text

Getting Started with GhostDriver Ivan De Marino Selenium Conference 2013, Boston, USA Find these slides at: http://bit.ly/15wfQnD

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

Setup

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

Code introduce dummy examples

Slide 11

Slide 11 text

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 }

Slide 12

Slide 12 text

Code Page Settings

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

Code Passing CLI arguments & WebDriver-mode

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

Code: scraping Twitter API

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Code: drawing Colorwheel

Slide 20

Slide 20 text

Code: thumbnailer Website Screenshot

Slide 21

Slide 21 text

Present & Future

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

Expose PhantomJS specific features

Slide 24

Slide 24 text

Go multi-process (yes, like ChromeDriver)

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

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