You are on page 1of 23

Stripping down

Remote WebDriver
How does Selenium actually
drive a remove browser
http://bit.ly/stripping-down-remote-webdriver
Intro
Santiago Suarez Ordoez
>5 years with Selenium and test automation
Selenium committer
Sauce Ninja at Sauce Labs
@santiycr
sso@saucelabs.com
Sauce Labs
Agenda
What's Remote WebDriver
The JSON Wire Protocol
The Desired Capabilities object
Augmenters
Handling local files
API Docs
The codebase
How is Remote WebDriver different
Remote WebDriver is all drivers!!
Pros
Separates where tests run from where the browser is
Allows tests to use browsers not available on the
current OS
Cons
Requires an external server
Introduces extra latency to tests
Graphs!
Demo!!
Step by step
1. get the Selenium server
2. start your remote WebDriver server
3. choose your desired capabilities
4. point Remote WebDriver to the right location
5. run your tests remotely
Show me!!
The JSON Wire Protocol
WebDriver's communication channel
RESTful protocol
JSON over HTTP
Intent in the test, actions through the wire
http://code.google.com/p/selenium/wiki/JsonWireProtocol
The internals
WebDriver API
WebDriver SPI
JSON Wire Protocol
Selenium Server
API vs SPI
API: Object oriented (WebDriver's style)
username = driver.find_element_by_id("username")
username.send_keys("santi")
SPI: Procedural and stateless (RC's style)
find_element(using="id", value="username")
send_keys(element="e0", value="santi")
Show me!!
The Desired Capabilities object
A hash sent to the server
Used to start the right driver
Drivers have special capabilities
Server sends capabilities back
(informing what has been given)
http://code.google.com/p/selenium/wiki/DesiredCapabilities
Choose your tests' capabilities
DesiredCapabilities caps = DesiredCapabilities.firefox();
caps.setCapability("version", "5");
caps.setCapability("platform", Platform.XP);
Dumping the Capabilities object:
Java:
caps.toString()
Python:
print(caps)
Ruby:
caps.to_json
C#:
caps.ToString()
Augmenters
WebDriver augmented = new Augmenter().augment(driver);
File screenshot = ((TakesScreenshot)augmented).
getScreenshotAs(OutputType.FILE);
How about browser profiles?
Stick to the FirefoxProfile class.
Remote base64 encodes and sends it
transparently!!
File file = new File("firebug-1.8.1.xpi");
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
firefoxProfile.setPreference("extensions.firebug.currentVersion",
"1.8.1");
DesiredCapabilities capabilities = new DesiredCapabilities.Firefox();
capabilities.setFirefoxProfile(firefoxProfile);
WebDriver driver = new RemoteWebDriver(capabilities);
How about file uploads?
I introduce you setFileDetector!
driver.setFileDetector(newLocalFileDetector());
fileinput.sendKeys("/Users/sso/local/file");
1. WebDriver detects a path and finds the file
2. Sends it base64 encoded and gets the remote path
3. Uses sendKeys with the new (remote) path
https://gist.github.com/1508946
API Documentation
Java API Docs
Ruby API Docs
Python API Docs
C# API Docs
All linked from:
http://code.google.com/p/selenium/
Where's the code?
Java:
selenium/trunk/java/client/src/org/openqa/selenium/remote
Ruby:
selenium/trunk/rb/lib/selenium/webdriver/remote
Python:
selenium/trunk/py/selenium/webdriver/remote
C#:
selenium/trunk/dotnet/src/WebDriver/Remote
QA?
Thanks!
Santiago Suarez Ordoez
@santiycr
Sauce Labs
http://bit.ly/stripping-down-remote-webdriver

You might also like