Professional Documents
Culture Documents
T9
Test!Automation!
10/16/2014!11:15:00!AM!
Automation Abstractions:
Presented by:
Alan Richardson
Compendium Developments
Brought(to(you(by:(
(
(
(
340!Corporate!Way,!Suite!300,!Orange!Park,!FL!32073!
888G268G8770!H!904G278G0524!H!sqeinfo@sqe.com!H!www.sqe.com!
!
Alan Richardson
Compendium Developments
Alan Richardson has more than twenty years of professional IT experience,
working as a programmer and at every level of the testing hierarchyfrom tester
through head of testing. Author of the books Selenium Simplified and Java For
Testers, Alan also has created online training courses to help people learn
technical web testing and Selenium WebDriver with Java. He now works as an
independent consultant, helping companies improve their use of automation,
agile, and exploratory technical testing. Alan posts his writing and training videos
on SeleniumSimplified.com, EvilTester.com, JavaForTesters.com, and
CompendiumDev.co.uk.
Automation Abstractions:
Page Objects and Beyond
Alan Richardson
@eviltester
www.SeleniumSimplified.com
www.EvilTester.com
www.CompendiumDev.co.uk
www.JavaForTesters.com
When you start writing automation for your projects, you quickly realize that you need to organize
and design the code.
You will write far more than test code; you also will write abstraction code because you want to
make tests easier to read and maintain.
But how do you design all this code? How do you organize and structure it?
Should you use a domain specific language?
Should you go keyword driven or use Gherkin?
Should you use page objects with POJO or Factories?
Do you create DOM level abstractions?
Where do domain models fit in?
Alan Richardson provides an overview of options available to you when modeling abstraction layers.
Based on his experience with many approaches on real-world commercial projects, Alan helps you
understand how to think about the modeling of abstraction layers.
Illustrated with a number of code examples, Alan shows you a variety of approaches and discusses
the pros and cons associated with each.
https://xp-dev.com/svn/AutomationAbstractions
2
What is Abstraction?
Modelling
Separation of concerns
Logical vs Physical
Functional vs Structural
Interfaces vs Implementations
Data / Entities / Persistence
Functionality / Task Flow
Goals / Strategies
Layers GUI, DB, HTTP
3
Etc.
assertThat(driver.findElement(
By.id("filters")).isDisplayed(), is(true));
assertThat(driver.findElement(
By.id("filters")).isDisplayed(), is(true));
}
WebDriver provides abstractions
Browser
DOM
Web Element
@Test
public void canCreateAToDoWithAbstraction(){
TodoMVCUser user =
new TodoMVCUser(driver, new TodoMVCSite());
user.opensApplication().and().createNewToDo("new task");
ApplicationPageFunctional page =
new ApplicationPageFunctional(driver,
new TodoMVCSite());
assertThat(page.getCountOfTodoDoItems(), is(1));
assertThat(page.isFooterVisible(), is(true));
}
@After
public void stopDriver(){
driver.close();
driver.quit(); NoAbstractionTest.java 8
}
Why Abstraction?
Change implementations
etc.
Gherkin (Given/When/And/Then)
...
11
Abstraction != Implementation
Gherkin != Cucumber
18
Implicit or Explicit Wait?
Implicit Wait
driver.manage().timeouts().
implicitlyWait(15L, TimeUnit.SECONDS);
assertThat(driver.findElement(
By.id("filters")).isDisplayed()
, is(true));
Explicit Wait
driver.manage().timeouts().
implicitlyWait(0L, TimeUnit.SECONDS);
wait.until(ExpectedConditions.elementToBeClickable
(By.id("filters"))); 19
Example: 'NoAbstractionTest.java'
21
POJO
'ApplicationPage.java'
Used in 'SequentialCreationOfTest.java'
Not much refactoring in the example
Simple Class
e.g.
com.seleniumsimplified.todomvc.page.pojo
'ApplicationPage.java'
Not much refactoring in the example 22
Functional vs Structural
Functional
loginAs(username, password)
Structural
enterUsername
enterPassword
clickLoginButton
submitLoginForm(username, password)
24
Functional Vs Structural Example
Why?
Sometimes it is just a naming difference
Handling exceptions in functional but not structural
Higher level methods in Functional
Different concepts e.g. deleteLastItem
25
Page Factory
26
Page Factory Example
@FindBy(how = How.CSS, using="#todo-count strong")
private WebElement countElementStrong;
PageFactory.initElements(driver, this);
this.driver = driver;
27
...
SlowLoadableComponent
29
30
Navigation Options
Instead of
todoMVC.enterNewToDo(New Item)
33
user.createNewToDo(new item)
user.createNewToDo(newItem)
34
Sometimes it is possible to over
think this stuff
Conduct experiments
Refactor
Rethink if
you are maintaining too much
your abstraction layer stops you doing stuff
you are 'working around' your abstraction layers
35
Element
Abstractions
36
Element Abstraction Example
public interface Checkbox {
public boolean isChecked();
public Checkbox check();
public Checkbox uncheck();
public Checkbox toggle();
}
37
Element Abstractions
38
Element Abstraction Pros and Cons
39
Component Abstractions
e.g.
VisibleToDoEntry, VisibleToDoList
Filters, Footer, Header, etc.
40
Component Abstraction Example
todo.markCompleted();
Instead of
page.markTodoCompleted(lastItemPosition);
41
Driver
Inject so instantiate any page or component as
required/desired at any time
Explicit Synchronisation
To make sure that the desired object is available
and ready for use (as defined by synchronisation)
Navigation
Implicit (via taking action e.g. click)
Explicit Navigation Object, not in page object
Open/jump (via driver.get)
To (state model from current, to desired) 43
My modeling biases
Page Objects
Physical
abstract the 'real world'
Components
For common features on the page
Logical
abstract the functionality
Sometimes these are entity methods not page objects
e.g. user.registers().and().logsin()
45
Are there rights and wrongs?
Right / Wrong?
Decisions?
Project/Team/Organisation Standards?
Decisions
48
To the creative mind there is
no right or wrong. Every
action is an experiment, and
every experiment yields its
fruit in knowledge.
The Illuminatus Trilogy
Robert Anton Wilson
49
Marcus Merrell
Self-Generating Test Artifacts for Selenium/WebDriver
https://www.youtube.com/watch?v=mSCFsUOgPpw
Anand Ramdeo
One Step at a Time
https://www.youtube.com/watch?v=dFPgzH_XP1I
50
Homework
52