automation, selenium webdriver and page objects

36
Automation, Selenium WebDriver and Page Objects Andrew Boyer

Upload: andrew-boyer

Post on 29-Jan-2018

942 views

Category:

Software


3 download

TRANSCRIPT

Page 1: Automation, Selenium Webdriver and Page Objects

Automation, Selenium WebDriver

and Page Objects

Andrew Boyer

Page 2: Automation, Selenium Webdriver and Page Objects

Developing Automation

Page 3: Automation, Selenium Webdriver and Page Objects

–Andrew Boyer

“Automation code is production code.”

Page 4: Automation, Selenium Webdriver and Page Objects

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

Page 5: Automation, Selenium Webdriver and Page Objects

Good Development Practices

Object-oriented Design

Don’t Repeat Yourself (DRY)

Launch and Iterate

Code Every Day

Page 6: Automation, Selenium Webdriver and Page Objects

But Wait, There’s More!

May Also Need Domain Expertise

Particularly for Specialty Areas

Big Data

Machine Learning

Bioinformatics

Page 7: Automation, Selenium Webdriver and Page Objects

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();

Page 8: Automation, Selenium Webdriver and Page Objects

Web Automation

Page 9: Automation, Selenium Webdriver and Page Objects

Web Automation

Driver

Page Objects

Test Methods

Page 10: Automation, Selenium Webdriver and Page Objects

When To Automate?

In True TDD, Automate Up Front

For Most Projects, Automate After UI Stabilizes

Page 11: Automation, Selenium Webdriver and Page Objects

Driver Classes

Page 12: Automation, Selenium Webdriver and Page Objects

Driver Classes

Allows Replacing Implementation

Handle Multiple Windows

Custom Extensions

e.g. isPresentNoWait

Page 13: Automation, Selenium Webdriver and Page Objects

Driver Classes (2)

Native Javascript Goes Here

onClick Events Sometimes Required

Timeout Management

Actions.perform()

Use WebDriver, not RC

Page 14: Automation, Selenium Webdriver and Page Objects

System Dialogs

Warning:

Selenium Can’t Touch System Dialogs

Like “Save File”

(but alerts are ok)

Page 15: Automation, Selenium Webdriver and Page Objects

Page Object Classes

Page 16: Automation, Selenium Webdriver and Page Objects

Page Object Classes

Represents A Single Page

Locators, Elements, and Operations

Handles Synchronization

Use OO For Similar Pages

Page 17: Automation, Selenium Webdriver and Page Objects

Locators

Speed and Fragility Most Important

ID > CSS > XPath

Generators Create Poor Locators, Tune Them

Page 18: Automation, Selenium Webdriver and Page Objects

Components

Common Reusable Objects For Shared Page Elements

Footer

Header

Menu Bar

Component Object Becomes Member Of Pages

See Also SlowLoadableComponent

Page 19: Automation, Selenium Webdriver and Page Objects

Synchronization

Bad Synchronization Most Common Cause For

Flaky Tests

Page Objects Should Handle Synchronization

With Application

Prevent Test Writers From Needing To Repeat

Themselves

Page 20: Automation, Selenium Webdriver and Page Objects

PageFactory

Initializes WebElements

Call After Page Load In Browser

Useful Place For Extensions Like Optional

WebElements

Page 21: Automation, Selenium Webdriver and Page Objects

Test Classes

Page 22: Automation, Selenium Webdriver and Page Objects

Test Classes

Should Rarely Call Driver Functions

Avoid Explicit Waits

Fail Fast

Don’t Retest Things

Page 23: Automation, Selenium Webdriver and Page Objects

Assertions

Keep Assertions In Tests

Avoid Implicit Waits For Non-present

WebElements

Test Failure vs. Broken Test

Assert vs. Verify

Page 24: Automation, Selenium Webdriver and Page Objects

Hamcrest Matchers

More Human-readable Conditions

Increased Logical Complexity

Page 25: Automation, Selenium Webdriver and Page Objects

Additional Pieces

Page 26: Automation, Selenium Webdriver and Page Objects

Additional Pieces

Test Case Management System

Reporting

Test Data Fixtures

Page 27: Automation, Selenium Webdriver and Page Objects

Tagging and Grouping

Tests

Different Run Cadences (Smoke, Regression)

Run Single Test

Run Tests Based on Feature

Run Tests Based on Requirement

Page 28: Automation, Selenium Webdriver and Page Objects

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)

Page 29: Automation, Selenium Webdriver and Page Objects

Hypothetical

How would you handle promotion testing when a

new feature replaces and old feature, and the

automation for each is incompatible?

Page 30: Automation, Selenium Webdriver and Page Objects

It Varies

Automation Framework Needs Its Own Release

Process

Features Should Be Hidden Behind A Flag

Test Groups Should Control What Gets Run

Where

Page 31: Automation, Selenium Webdriver and Page Objects

Related Technologies

Page 32: Automation, Selenium Webdriver and Page Objects

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)

Page 33: Automation, Selenium Webdriver and Page Objects

Getting Started

Page 34: Automation, Selenium Webdriver and Page Objects

–Michael C. Feathers

Working Effectively With Legacy Code

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

better.”

Page 35: Automation, Selenium Webdriver and Page Objects

Getting Started

Start Small!

Selenium IDE, Then Export

codecademy.com

Page 36: Automation, Selenium Webdriver and Page Objects

Questions?