Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Selenium 2
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Marc Philipp
May 09, 2011
Programming
330
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Selenium 2
Marc Philipp
May 09, 2011
More Decks by Marc Philipp
See All by Marc Philipp
JUnit 6
marcphilipp
1
87
JUnit 6.0
marcphilipp
2
64
Catching up with JUnit
marcphilipp
0
320
Catching up with JUnit 5
marcphilipp
1
210
The JUnit Crew Presents What's New
marcphilipp
2
120
Behind the scenes of JUnit 5 – running an independent open source project by example
marcphilipp
0
140
Running an independent open source project by example
marcphilipp
1
120
Automatisierte Tests mit Machine Learning und verteilter Ausführung beschleunigen
marcphilipp
1
280
Meet the JUnit Team in Person!
marcphilipp
1
230
Other Decks in Programming
See All in Programming
SONY CISC-NEWS NWS-1750 + NWB-225 フレームバッファの NetBSD/news68k ドライバ実装 / OSC2026Hiroshima
tsutsui
0
160
技術的負債の返済は、AI時代の複利で効く投資 — 経営としての意思決定とその遂行
curekoshimizu
1
2k
setup-vp GitLab対応の裏側
naokihaba
0
140
技術的負債を組織課題として解く-増えすぎたマイクロサービスとの戦い-
reimaru
1
2.5k
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
310
AHC070解法紹介
eijirou
0
140
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
240
JPUG勉強会 OSSデータベースの内部構造を理解しよう(第2回)
oga5
0
280
一人だけ、Kiroが静止する日
hideg
0
140
iOSDC Japan 2026 - Swiftで作って学ぼう!データベース自作入門
kaseken
2
410
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
3.1k
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
510
How to build a perfect <img>
jonoalderson
1
6k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
3
4.3k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
1k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
68
58k
Un-Boring Meetings
codingconduct
0
430
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
550
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.3k
Transcript
Selenium
What is Selenium? Testing framework for web applications, 3 variants:
Selenium IDE Firefox add-on Record and playback user actions on a web site Not recommend for stable, long staying test suites © 2011 andrena objects ag. All rights reserved. 2
What is Selenium? (cont.) Selenium RC (Remote Control, Selenium 1)
Java Server that controls various browsers Executes scripted user actions from a programming environment, typically JUnit Has a “string-based” programming API Supports a variety of browsers (Internet Explorer 6, 7, 8, Firefox 2, 3, Safari, Chrome, Opera) Selenium WebDriver (Selenium 2) Java Library, which controls the browser Has a object-oriented programming API Supports Internet Explorer, Firefox, Chrome and HtmlUnit as drivers We recommend using the WebDriver API! © 2011 andrena objects ag. All rights reserved. 3
Selenium WebDriver API An instance implementing the WebDriver interface allows
access to the browser and to retrieve WebElements (input fields, buttons, etc.): get(String url) Loads new web page by URL. findElement(By locator) Finds WebElement or throws exception. findElements(By locator) Finds list of WebElements, possibly empty. . . . © 2011 andrena objects ag. All rights reserved. 4
Locating Elements on a Page Locators: instances of the By
class identifying an element in the HTML page. By.id("okay-button") Selects an element by its HTML id attribute. By.name("okayButton") Selects an element by its HTML name attribute. By.xpath("//div[@class=’navi’]//a[text()=’click’]") Treats the HTML as XML and uses an XPath expression to select an element. © 2011 andrena objects ag. All rights reserved. 5
Locating Elements on a Page (cont.) By.className("mainMenu") Uses a CSS
class name to select an element. By.cssSelector(".mainMenu a") Uses CSS selector syntax to select an element. By.linkText("click here") Finds a link by its text shown on the page. © 2011 andrena objects ag. All rights reserved. 6
Interacting With Elements on a Page element.click() Clicks on an
element. element.sendKeys("some text") Enters text into text field. element.clear() Clears the contents of a text field. element.setSelected() Selects an option element. . . . © 2011 andrena objects ag. All rights reserved. 7
Coding Dojo I Task Write Selenium tests driven by JUnit
that log in and out of a web application Dojo Rules 1. Two people are coding: 1 driver (has keyboard), 1 navigator. 2. They think aloud and comment their actions so the audience understands what’s going on. 3. After 3 minutes: driver leaves, navigator becomes driver. 4. Someone else joins as the new navigator. 5. Repeat. © 2011 andrena objects ag. All rights reserved. 8
Page Objects A page object is a Java class representing
a web page holds a WebDriver instance knows about locators public class LoginPage extends PageObject { public void setUsername(String username) { WebElement usernameField = driver.findElement(By.id(" j_username")); usernameField.clear(); usernameField.sendKeys(username); } ... } © 2011 andrena objects ag. All rights reserved. 9
Web Element Annotations Web elements can additionally be found using
annotations: public class LoginPage extends PageObject { @FindBy(id = "j_username") private WebElement usernameField; public void setUsername(String username) { usernameField.clear(); usernameField.sendKeys(username); } } This will instantiate the LoginPage class and create a proxy for each WebElement by evaluating the @FindBy annotation: PageFactory.initElements(driver, LoginPage.class) © 2011 andrena objects ag. All rights reserved. 10
Page Objects Actions A method that changes to another page
returns a new page object public class LoginPage extends PageObject { @FindBy(id = "registration-link") private WebElement registrationLink; public LoginPage(WebDriver driver) { super(driver); } public RegistrationPage clickRegistrationLink() { registrationLink.click(); return PageFactory.initElements(driver, RegistrationPage. class); } } © 2011 andrena objects ag. All rights reserved. 11
Coding Dojo II Task Write Selenium tests driven by JUnit
that log in and out of a web application using Page Objects! Dojo Rules 1. Two people are coding: 1 driver (has keyboard), 1 navigator. 2. They think aloud and comment their actions so the audience understands what’s going on. 3. After 3 minutes: driver leaves, navigator becomes driver. 4. Someone else joins as the new navigator. 5. Repeat. © 2011 andrena objects ag. All rights reserved. 12
Page Objects Benefits Page objects allow test code be separated
from details about page structures Tests are written on a higher level of abstraction Structural knowledge is reused Reduces overall code size and development effort on page structure changes In summary, Page Objects help write Selenium tests which are More readable More maintainable Less fragile © 2011 andrena objects ag. All rights reserved. 13
Thank you! References and Further Reading: http://www.seleniumhq.org/ http://code.google.com/p/selenium/wiki/PageObjects Marc Philipp
E-Mail
[email protected]
Twitter @marcphilipp andrena objects ag Albert-Nestler-Straße 11 D-76131 Karlsruhe Tel. +49 (0) 721 6105-122 Büro Frankfurt Clemensstraße 8 D-60487 Frankfurt Tel. +49 (0) 69 977 860 38 © 2011 andrena objects ag. All rights reserved. 14