Selenium Automation
Selenium Automation
SELENIUM
Selenium
Confusion!
Selenium
Selenium 2
Selenium IDE
Selenium Webdriver
Selenium RC
Selenium Server
Selenium 1
Selenium Grid
Webdriver
Language bindings
Java
Perl
C#
PHP
Ruby
Haskell
Python
Objective-C
Javascript (Node)
Examples in this presentation will be in Python
Assumptions
# import webdriver
from selenium import webdriver
LOCATING ELEMENTS
Elements
Id
Name
Class name
Tag name
Css selector
Link text
Xpath
Attribute contains:
a[href*=registerForm]
<a href="someExternalDocument.pdf">Read this!</a>
CSS pseudoclasses
<table id="datatable">
<tr>
<th>1</th>
<td>Num 1</td>
<td>Num 2</td>
</tr>
<tr>
<th>2</th>
<td>Num 3</td>
<td>Num 4</td>
</tr>
</table>
XPATH alternatives
<table id="datatable">
<tr>
<th>1</th>
<td>Num 1</td>
<td>Num 2</td>
</tr>
<tr>
<th>2</th>
<td>Num 3</td>
<td>Num 4</td>
</tr>
</table>
//table[@id='datatable']/tr[2]/td[1]
XPATH alternatives
<table id="datatable">
<tr>
<th>1</th>
<td>Num 1</td>
<td>Num 2</td>
</tr>
<tr>
<th>2</th>
<td>Num 3</td>
<td>Num 4</td>
</tr>
</table>
//th[text()='2']/following-sibling::td[1]
Interaction methods
# click the element
element.click()
browser.find_element_by_name("lastName").send_keys("Malone")
browser.find_element_by_id("search").click()
browser.find_element_by_link_text("Andrew P. Malone").click()
Tips
PAGE OBJECTS
Search page
class Search_Page(Page):
locators = {
"last_name": "name=lastName",
"search": "id=search"
}
def go(self):
self.browser.get("https://www.directory.harvard.edu/")
return self
def set_last_name(self, last_name):
self.find(self.locators["last_name"]).send_keys(last_name)
def search(self):
self.find(self.locators["search"]).click()
return Results_List(self.browser)
Search page
class Search_Page(Page):
locators = {
"last_name": "name=lastName",
"search": "id=search"
}
def go(self):
self.browser.get("https://www.directory.harvard.edu/")
return self
def set_last_name(self, last_name):
self.find(self.locators["last_name"]).send_keys(last_name)
def search(self):
self.find(self.locators["search"]).click()
return Results_List(self.browser)
Results list
class Results_List(Page):
locators = {
"name": "link=REPLACE"
}
def click_name(self, name):
self.find(self.locators["name"]
.replace("REPLACE", name)).click()
return Results_Page(self.browser)
Results page
class Results_Page(Page):
locators = {
"title":"xpath=//font[text()='Appointment
Title:']/../following-sibling::td"
}
def title(self):
return self.find(self.locators["title"]).text
Data staging
Creating specific application state for testing
Other uses
RISKS
Scope creep
Be like this!
THANK YOU!
Andrew Malone
Financial Systems Solutions (FSS)
[email protected]
External resources