0% found this document useful (0 votes)
225 views14 pages

Web Driver Cheat Sheet

The document provides cheat sheets summarizing the Selenium WebDriver API. It includes sections on basic commands, matchers, synchronization, IntelliJ tips, and CSS/XPath selectors. Contact details are provided for training courses on WebDriver.

Uploaded by

capkarish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
225 views14 pages

Web Driver Cheat Sheet

The document provides cheat sheets summarizing the Selenium WebDriver API. It includes sections on basic commands, matchers, synchronization, IntelliJ tips, and CSS/XPath selectors. Contact details are provided for training courses on WebDriver.

Uploaded by

capkarish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

WebDriver API Cheat Sheets

A short set of Summary Cheat Sheets for Hands


On Working With WebDriver
Contents:

Basic API commands

Hamcrest matchers & Junit

IntelliJ Tips

CSS & Xpath Selectors

Contact Details

Copyright Alan Richardson,


Compendium Developments
@eviltester
Created to support our Selenium
2 WebDriver Training Courses

SeleniumSimplified.com | compendiumdev.co.uk | eviltester.com

API Overview

http://www.mindmeister.com/280141421/selenium-2-webdriver-commands

WebDriver Level Basics

http://www.mindmeister.com/280141421/selenium-2-webdriver-commands

WebElement
Interrogation
Basics

http://www.mindmeister.com/280141421/selenium-2-webdriver-commands

WebElement
Manipulation

http://www.mindmeister.com/280141421/selenium-2-webdriver-commands

Synchronisation

HTML, Web
Domain

Basic API

IntelliJ Tips

Use Code Completion

ctrl+Q for Documentation of Commands

ctrl+click to view the method code

Switch on AutoScroll

Find Symbol

Find Class

Shift + Cntrl + Alt + N


Cntrl + N

Find File

Shift + Ctnrl + N

Synchronisation WebDriverWait

ExpectedConditions static methods


new WebDriverWait(driver,10).until(
ExpectedConditions.titleIs("HTML Form Elements"));

Custom ExpectedCondition

new WebDriverWait(driver,10).until(
optionWithValueDisplayed(By.id("combo2"),"Java") );
private ExpectedCondition<WebElement>

optionWithValueDisplayed(
final String value) {

return new ExpectedCondition<WebElement>() {

};

@Override
public WebElement apply(WebDriver webDriver) {
return webDriver.findElement(
By.cssSelector("option[value='" + value + "']") );
}
10

SlowLoadableCompnent

Public interface

get()

loads and waits for component to be available

extends SlowLoadableComponent<PageObjectClassName>

Call super constructor in constructor


public PageObjectClassName(WebDriver driver) {
super(new SystemClock(), 10);
this.driver = driver;
}

Implement load and isLoaded

isLoaded throws a new Error if not loaded

I often leave the 'load' part empty if I navigate to the page

Hamcrest Matchers & JUnit


@Test

e.g. assertThat(driver.getTitle(), is(not(bob));

is

not

Number

greaterThan,

greaterThanOrEqualTo,

lessThan,

lessThanOrEqualTo - test
ordering

Text

equalToIgnoringCase

equalToIgnoringWhiteSpace

containsString,

endsWith,

startsWith

@Before, @After (method level)

@BeforeClass, @AfterClass (static)

Collections

hasEntry,

hasKey,

hasValue - test a map contains an


entry, key or value

hasItem,

hasItems - test a collection


contains elements

hasItemInArray - test an array


contains an element

notNullValue,
nullValue - test for null

http://code.google.com/p/hamcrest/wiki/Tutorial#A_tour_of_common_matchers

XPATH Selectors

Selectors

CSS Selectors

// - match anywhere

* - any

/ - match from root

#id

//* - any element

.class

//tag

tag

//*[@attribute]

[attribute]

//*[@attribute="value"]

[attribute="value"]

//tag[@attribute="value"]

tag[attribute="value"]

//tag1/tag2

(child)

tag[attr1='val1'][attr2='val2']

//tag1//tag2

(any descendant)

tag[att1='val1'], orThisTag

//tag1/../..

(.. to go up)

//*[.='element text']
[@at1="a" and @at2="b"]
and, or, =, !=, <, >, >=, <-

Functions

= (' or ")
*="anywhere in value"
^="start of value"
$="end of value"
~="spaceSeperatedValue"

contains(@a,"alu")

Paths

starts-with(@a,"v")

A > B (child)

ends-with(@a,"e")

A B (any descendant)

Indexing
//tag[1]

A + B (A's B sibling)
tag:first-child
CSS References

http://reference.sitepoint.com/css/selectorref

http://net.tutsplus.com/tutorials/html-css-techniques/
the-30-css-selectors-you-must-memorize/

http://www.quirksmode.org/css/contents.html

http://www.w3schools.com/cssref/css_selectors.asp
13

XPath References

http://www.w3schools.com/xpath/

http://www.simple-talk.com/dotnet/.net-framework/xpath,-css,-dom-and-selenium-the-rosetta-stone/

Alan Richardson is an Independent Test


Consultant based in the UK. He offers training
and consultancy in Selenium WebDriver,
exploratory and technical web testing.

uk.linkedin.com/in/eviltester

Contact Alan for training and


consultancy tailored to your needs:
[email protected]

Blogs and Web Sites

Online Training Courses

Technical Web Testing 101

Intro to Selenium

Unow.be/at/udemy101

Unow.be/at/udemystart

Selenium 2 WebDriver API

Unow.be/at/udemyapi

Videos
youtube.com/user/EviltesterVideos

SeleniumSimplified.com

EvilTester.com

Books

Testing Papers and Tools

Selenium Simplified

CompendiumDev.co.uk

Unow.be/rc/selsimp

Twitter: @eviltester

14

You might also like