2. Join us and Book Online
★ Book
★ One
your selenium webdriver training with us
day - intensive 10 hours - 8am to 6pm
★ Locations:
Dublin, Berlin, Dubai, Brussels, New York,
Copenhagen, Zurich
★ Learn
and Apply - Practical
★ Lunch
and Refreshments inclusive
★ Small
classes up to 6 delegates
www.time2test.co.uk
!2
www.seleniumbootcamp.com
10. who we are?
•
Time2test Limited ( UK) based training company
•
Specialise in training for testers
•
Training Locations: UK and Europe
•
Over 15 Courses: Coding for Testers, Webdriver
Automation & Mobile Test Automation
www.time2test.co.uk
!10
www.seleniumbootcamp.com
11. Fast paced course
•
We have limited time
•
We can follow up via Skype if necessary
•
Email us info@time2test.co.uk with questions
www.time2test.co.uk
!11
www.seleniumbootcamp.com
12. About the trainer
“Hi, I am the trainer. This slide is about me and my
technology background.”
www.time2test.co.uk
!12
www.seleniumbootcamp.com
13. Agenda
•
7:45 - 8am - Introductions and Coffee
•
8am - 10am - Morning session
Timings are
approximate
•
Coffee Break 1 - 15 mins
•
10am-1pm - Mid Morning session
•
Lunch Break - 30 mins
•
1pm - 3pm - Afternoon session
Time to catch
the plane
•
Coffee Break 2 - 15 mins
•
3pm - 6pm - Late Afternoon session
www.time2test.co.uk
!13
www.seleniumbootcamp.com
15. what we will cover?
•
Selenium 2 WebDriver API
•
Handling Alerts
•
Using WebDriver to navigate web applications
•
Working with Cookies
•
Basic web Element identification using id,
name
•
Synchronisation strategies
•
Implicit vs Explicit Waits
•
Explicit waits using ExpectedConditions
•
Explicit waits using custom expected
conditions
•
Refactoring to Abstraction layers, Page Object
Models and Domain Objects
•
•
•
Locating web elements using CSS and XPaths
Use of Chrome Developer tools and Firebug
WebDriver commands to Interrogate
WebElements and pages
•
JUnit annotations to structure test code
•
HamCrest commands for test assertions
•
Page Object Modelling Approaches
•
WebDriver commands for Interaction and
Manipulation
•
Running tests on multiple browsers: Firefox,
Google Chrome
•
Using JavaScript in your tests
•
Using Remote WebDriver
www.time2test.co.uk
!15
www.seleniumbootcamp.com
17. What do you already know?
•
Spend 5 minutes on telling us what you already
know about Selenium Webdriver and how you have
used it.
•
Or , tell us about your test automation experience
www.time2test.co.uk
!17
www.seleniumbootcamp.com
18. Style of teaching
•
Follow the the examples created by the trainer and
then try them out on your machine.
•
Help each other out.
www.time2test.co.uk
!18
www.seleniumbootcamp.com
19. course objectives
•
spend 5 mins and note down your objectives and
pass them over to the trainer.
•
We want to meet your expectations.
Feel free to
add
objectives at
any time
www.time2test.co.uk
!19
www.seleniumbootcamp.com
21. overview
•
Eclipse IDE or IntelliJ IDEA
•
jUnit for test automation framework
•
Maven for package dependencies
•
Firefox installed - default preferred browser for
Webdriver
www.time2test.co.uk
!21
www.seleniumbootcamp.com
22. What is Eclipse IDE
•
If you don’t have previous experience then just
follow the trainers’ examples
•
Development platform with magic
www.time2test.co.uk
!22
www.seleniumbootcamp.com
23. What is jUnit?
•
test automation framework to help organise tests
with improved reports
www.time2test.co.uk
!23
www.seleniumbootcamp.com
24. What is Maven?
•
configuration tool to manage package
dependencies and versions without the headache.
www.time2test.co.uk
!24
www.seleniumbootcamp.com
25. What is Firefox?
•
where have you been?
•
webdriver and Firefox show much love
www.time2test.co.uk
!25
www.seleniumbootcamp.com
28. API - must know
Webdriver - control the browser
•
Webdriver driver = new FirefoxDriver();
WebElement - work with elements on the page
•
WebElement myElement =
driver.findElement(By.id(“id”))
it’s an
interface to a
browser
www.time2test.co.uk
!28
www.seleniumbootcamp.com
29. API - must know
•
void get(“url”) - open the web page
•
void quit() - close the browser
•
List<WebElement> findElements(By by) - find
elements (more than one element)
www.time2test.co.uk
!29
www.seleniumbootcamp.com
30. API - find Elements
•
There are many different ways to find elements
•
By.id(“objectId”)
•
By.linkText(“textUsedInTheLink”)
•
By.partialLinkText(“partOftextUsedInTheLink”)
•
By.tagName(“HTMLNodeTag”)
•
By.className(“cssClassOnObject”)
•
By.cssSelector(“cssSelectorOfElement”)
•
By.xpath(“//xpath/To/Element”)
•
By.name(“elementName”)
www.time2test.co.uk
We
prefer to use
cssSelectors
!30
www.seleniumbootcamp.com
31. API - operations
•
void click() - click on an element
•
void submit() - perform a submit
•
String getValue()
•
void sendKeys(“keysToSend”) - input values
•
void clear() - clear the input field
•
String getElementName() -
•
String getAttriubute() -
•
boolean toogle() -
•
void Actions() - perform mouse, drag and drops and keyboard operations
www.time2test.co.uk
!31
www.seleniumbootcamp.com
32. API - windows and frames
working with Browser Windows
•
driver.getWindowHandles()
•
driver.switchTo().window.(“window_name”)
working with frames
•
driver.switchTo().frame.(“frame_name”)
www.time2test.co.uk
!32
www.seleniumbootcamp.com
35. overview
•
use firebug/chrome developer tools to help with
locating webElements
•
cssSelectors
•
XPATHS
•
id
•
name
www.time2test.co.uk
!35
www.seleniumbootcamp.com
36. xpaths v cssSelectors
•
Try to use cssSelectors over XPATHS
•
your automation scripts will run faster
•
use XPATHs to save time
•
finding elements on a page is an art!
www.time2test.co.uk
!36
www.seleniumbootcamp.com
37. xpaths
•
This notation // for xpaths
•
follow the trainer’s examples
•
use a tool to help determine xpaths
www.time2test.co.uk
!37
www.seleniumbootcamp.com
38. xpaths - firepath
•
great tool to assist with xpath determination
•
use with firebug on firefox
www.time2test.co.uk
!38
www.seleniumbootcamp.com
40. css selectors 2
•
partial match on attribute values
^=
$=
*=
www.time2test.co.uk
input[id^=‘ctrl’]
Starting with:
For example, if the ID of an element is ctrl_12,
this will locate and return elements with ctrl at
the beginning of the ID.
input[id$='_userName']
Ending with:
For example, if the ID for an element is a_1_
userName, this will locate and return elements
with _userName at the end of the ID.
input[id*='userName']
Containing:
For example, if the ID of an element is panel_
login_userName_textfield, this will use
the userName part in the middle to match and
locate the element.
!40
www.seleniumbootcamp.com
41. css selector gadget
•
chrome tool extension
•
Search in google for “CSS
Selector Tester”
!
www.time2test.co.uk
!41
www.seleniumbootcamp.com
42. dynamic elements
Does the ID of your element dynamically change?
<p id="bootcamp_dynamic_1234">This p tag has a dynamic id</p>
!
xpath notation to find the p tag on the page
"//p[contains(@id,'bootcamp_dynamic_')]"
!
cssSelector notation to find the p tag on the page
"p[id*='bootcamp_dynamic_']"
www.time2test.co.uk
!42
www.seleniumbootcamp.com
46. jUnit
•
Pick up the style used in our examples and then
apply them
www.time2test.co.uk
!46
www.seleniumbootcamp.com
47. hamcrest
•
Hamcrest is a framework for writing matcher
objects allowing 'match' rules to be defined
declaratively
•
introduces matchers and is more friendly to read
•
use instead of the junit assertions
•
http://edgibbs.com/junit-4-with-hamcrest/
www.time2test.co.uk
!47
www.seleniumbootcamp.com
48. hamcrest usage
•
A good starting place is the assertThat() method
that can now almost always be used in place of the
traditional assertEquals().
•
assertThat() can be found in org.junit.Assert, but it
defines using Hamcrest matchers in the signature:
static <T> void assertThat(T actual,
org.hamcrest.Matcher<T> matcher)
www.time2test.co.uk
!48
www.seleniumbootcamp.com
50. test Structure
•
good style
•
void setUp()
•
void tearDown()
•
all tests should finish with an assertion
•
element locators should be defined in a separate
class - think about constants
www.time2test.co.uk
!50
www.seleniumbootcamp.com
54. cookies
Set<Cookie> cookies=driver.manage().getCookies();
for(Cookie cookie:cookies)
{
System.out.println(cookie.getName()+"
"+cookie.getValue());
}
//To find the number of cookies used by this site
System.out.println("Number of cookies in this site
"+cookies.size());
www.time2test.co.uk
!54
www.seleniumbootcamp.com
56. overview
•
Locating elements on a page is already an art.
•
Locating elements on a page that don’t always appear
in a timely manner is also an art.
•
Implicit vs Explicit Waits
•
Explicit waits using ExpectedConditions
•
Explicit waits using custom expected conditions
•
fluent waits
www.time2test.co.uk
!56
www.seleniumbootcamp.com
57. Implicit waits
!
Just wait for a period to time
//Set the Implicit Wait time Out to 10 Seconds
driver.manage().timeouts().implicitlyWait(10,
TimeUnit.SECONDS);
www.time2test.co.uk
!57
www.seleniumbootcamp.com
58. Explicit waits
Wait until a condition is met
WebDriverWait wait = new
WebDriverWait(driver, 10);
wait.until(ExpectedConditions.titleContains("sele
nium"));
www.time2test.co.uk
!58
www.seleniumbootcamp.com
59. Fluent Waits
•
!
Use the code that is best for your application under test
// Waiting 30 seconds for an element to be present on the page, checking
// for its presence once every 5 seconds.
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(30, SECONDS)
.pollingEvery(5, SECONDS)
.ignoring(NoSuchElementException.class);
!
WebElement foo = wait.until(new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver driver) {
return driver.findElement(By.id("foo"));
}
});
www.time2test.co.uk
!59
www.seleniumbootcamp.com
61. overview
•
what are page objects?
•
how to use page objects?
www.time2test.co.uk
!61
www.seleniumbootcamp.com
62. what are page objects?
•
popular design pattern
•
object orientated class for a page
•
interface to the web page
•
methods for elements
•
encapsulates features represented by the page
www.time2test.co.uk
!62
www.seleniumbootcamp.com
63. benefits of page objects?
•
more readable code
•
logical grouping
•
easy to maintain code
•
tests don’t change if UI changes - just that page
object
•
clean separation between test code and page
specific code
www.time2test.co.uk
!63
www.seleniumbootcamp.com
66. overview
•
running your tests on Firefox
•
running your tests on IE
•
running your tests on Chrome
•
running remotely - selenium grid
www.time2test.co.uk
!66
www.seleniumbootcamp.com
67. RemoteWebDriver
•
WebDriver driver = new RemoteWebDriver(new
URL(“http://server-with-selenium-grid-running: 4444/wd/
hub"), DesiredCapabilities.firefox());
•
This example assumes that Selenium Server is running on
server-with-selenium-grid-running with the default port
of 4444.
•
You can run Selenium Server on any machine
•
For example, I run the test code from my Mac OS X
computer but I run Selenium Server on a Window XP
machine.
www.time2test.co.uk
!67
www.seleniumbootcamp.com
68. cross browser
•
different browsers behave differently
•
perform most testing on Firefox
•
some subset test execution on different browsers
www.time2test.co.uk
!68
www.seleniumbootcamp.com
72. Troubleshooting
•
Can’t click or find an element?
•
Selenium Versions
•
Firefox browser versions
•
Downgrade or upgrade using Maven to manage
the versions.
www.time2test.co.uk
!72
www.seleniumbootcamp.com
77. generate random data
•
create a nice random helper class for your random
test data needs
www.time2test.co.uk
!77
www.seleniumbootcamp.com
78. screenshots
•
take a screenshot when you spot an error or an
exception or for validation purposes.
•
useful to save this artefacts as part of Jenkins CI
( continuous integration)
www.time2test.co.uk
!78
www.seleniumbootcamp.com
79. get all links on page
•
Find elements and put traverse through the List
www.time2test.co.uk
!79
www.seleniumbootcamp.com
82. data driven testing
•
Excel spreadsheets or CSV files to seed your tests
•
TestNG is good with data driven testing
www.time2test.co.uk
!82
www.seleniumbootcamp.com
84. goals and objectives
!
•
•
•
Review your goals.
Have we met your expectations?
Email us and we will setup a follow up Skype
session
www.time2test.co.uk
!84
www.seleniumbootcamp.com