Automation, Selenium Webdriver and Page Objects

Preview:

Citation preview

Automation, Selenium WebDriver

and Page Objects

Andrew Boyer

Developing Automation

–Andrew Boyer

“Automation code is production code.”

Developing Automation

Get dev buy-in to help extend and maintain

framework

Choose a good language

Use good development practices

Show benefit of test automation

Good Development Practices

Object-oriented Design

Don’t Repeat Yourself (DRY)

Launch and Iterate

Code Every Day

But Wait, There’s More!

May Also Need Domain Expertise

Particularly for Specialty Areas

Big Data

Machine Learning

Bioinformatics

Fluent Programming

HomePage page = driver.load(HOME_PAGE);

page.setUser(user);

page.setPassword(password);

page.clickLogin();

ProfilePage profile = page.openProfile();

- vs -

ProfilePage page = HomePage

.login(user, password)

.openProfile();

Web Automation

Web Automation

Driver

Page Objects

Test Methods

When To Automate?

In True TDD, Automate Up Front

For Most Projects, Automate After UI Stabilizes

Driver Classes

Driver Classes

Allows Replacing Implementation

Handle Multiple Windows

Custom Extensions

e.g. isPresentNoWait

Driver Classes (2)

Native Javascript Goes Here

onClick Events Sometimes Required

Timeout Management

Actions.perform()

Use WebDriver, not RC

System Dialogs

Warning:

Selenium Can’t Touch System Dialogs

Like “Save File”

(but alerts are ok)

Page Object Classes

Page Object Classes

Represents A Single Page

Locators, Elements, and Operations

Handles Synchronization

Use OO For Similar Pages

Locators

Speed and Fragility Most Important

ID > CSS > XPath

Generators Create Poor Locators, Tune Them

Components

Common Reusable Objects For Shared Page Elements

Footer

Header

Menu Bar

Component Object Becomes Member Of Pages

See Also SlowLoadableComponent

Synchronization

Bad Synchronization Most Common Cause For

Flaky Tests

Page Objects Should Handle Synchronization

With Application

Prevent Test Writers From Needing To Repeat

Themselves

PageFactory

Initializes WebElements

Call After Page Load In Browser

Useful Place For Extensions Like Optional

WebElements

Test Classes

Test Classes

Should Rarely Call Driver Functions

Avoid Explicit Waits

Fail Fast

Don’t Retest Things

Assertions

Keep Assertions In Tests

Avoid Implicit Waits For Non-present

WebElements

Test Failure vs. Broken Test

Assert vs. Verify

Hamcrest Matchers

More Human-readable Conditions

Increased Logical Complexity

Additional Pieces

Additional Pieces

Test Case Management System

Reporting

Test Data Fixtures

Tagging and Grouping

Tests

Different Run Cadences (Smoke, Regression)

Run Single Test

Run Tests Based on Feature

Run Tests Based on Requirement

Build Tools

Ant / Maven / Make / Gradle

Continuous Integration / Deployment (Jenkins, Bamboo,

TeamCity)

Version Control (Git, Svn, Perforce)

Static Inspections (FindBugs, CheckStyle)

Cloud Services (AWS, Google, Microsoft)

Devops Scripting (Puppet, Chef, Docker, Bash)

Hypothetical

How would you handle promotion testing when a

new feature replaces and old feature, and the

automation for each is incompatible?

It Varies

Automation Framework Needs Its Own Release

Process

Features Should Be Hidden Behind A Flag

Test Groups Should Control What Gets Run

Where

Related Technologies

Related Tools

SQL (esp. Transactions)

SGML-related (HTML, XML, CSS, XPath)

Javascript / JQuery

Dependency Injection (Spring)

Browser Dev Consoles (+ Firebug)

Networking (RFCs, Charles Proxy, Wireshark)

Getting Started

–Michael C. Feathers

Working Effectively With Legacy Code

“We feel overwhelmed. It isn’t going to get any

better.”

Getting Started

Start Small!

Selenium IDE, Then Export

codecademy.com

Questions?

Recommended