david piper - how to never use webdriver...

54
How to never use WebDriver again Modern Javascript CI DAVID PIPER | FRONTEND DEVELOPER | ATLASSIAN

Upload: others

Post on 30-May-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

How to never use WebDriver againModern Javascript CI

DAVID PIPER | FRONTEND DEVELOPER | ATLASSIAN

Page 2: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

Comprehensive Javascript test framework designed to replace WebDriver

INTRODUCTION

Page 3: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

Nice to have Benefits usually outweigh the

costs of maintenance

Three categories of CI tools

Optional If you won’t commit to

maintaining them, don’t.

Essential Don’t leave home without these tools and services

Page 4: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

What aren’t we going to talk about?

Page 5: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

MODERN JAVASCRIPT CI

Page 6: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

MODERN JAVASCRIPT CI

Page 7: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

MODERN JAVASCRIPT CI

Page 8: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

i18n:翻譯

MODERN JAVASCRIPT CI

Page 9: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

i18n:翻譯

MODERN JAVASCRIPT CI

Page 10: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

i18n:翻譯

MODERN JAVASCRIPT CI

Page 11: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

i18n:翻譯

MODERN JAVASCRIPT CI

Page 12: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

i18n:翻譯

MODERN JAVASCRIPT CI

Page 13: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

i18n:翻譯

MODERN JAVASCRIPT CI

Page 14: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

i18n:翻譯

MODERN JAVASCRIPT CI

Page 15: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

i18n:翻譯

MODERN JAVASCRIPT CI

Page 16: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

i18n:翻譯

MODERN JAVASCRIPT CI

Page 17: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

What are we going to talk about?

Page 18: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

JAVASCRIPT CI?

Page 19: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

OBSOLETE JAVASCRIPT CI

Page 20: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

MODERN JAVASCRIPT CI

UI component tests1

Page 21: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

enzyme

Page 22: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

enzyme+

jsdom

Page 23: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

MODERN JAVASCRIPT CI

Pact (contract) tests2

Page 24: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

TRADITIONAL PACT FLOW: CONSUMER

http://dius.com.au/2016/02/03/microservices-pact/

Page 25: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

TRADITIONAL PACT FLOW: PROVIDER

http://dius.com.au/2016/02/03/microservices-pact/

Page 26: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

Authentication No support intended for authentication. You don’t

want to bake credentials in. Must be injected in the

Provider tests.

Problems with the traditional flow

Live Provider Either spin up the service in CI, or test a live service. You

need to manage your test data as well.

Consumer driven Consumers cannot ‘break’.

There is no hard requirement for the Consumer to conform

to the Provider.

Page 27: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

MODERN JAVASCRIPT CI

Swagger validation3

Page 28: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

A complete* API description, published by the Provider service

SWAGGER SPECIFICATIONS

Page 29: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

Code comments E.g: JavaDoc. Still a manual

and error-prone process.

Ways to generate Swagger specs

Code annotations Make your tooling generate

your Swagger for you

Manually Don’t do this for large

services.

Page 30: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

Authentication

Remember these?

Live ProviderConsumer driven

Page 31: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

Write Pact tests Libraries are available for a large number of frontend projects: docs.pact.io

Swagger validation Verify that the API expectations in the Pactfiles can be met by the Provider’s published spec:bitbucket.org/atlassian/swagger-request-validator

Upload to Pact broker This could be any file upload service, but there’s an official one already built at: github.com/pact-foundation/pact_broker

Consumer flow

Page 32: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

Pull latest pact file(s) These will come from the Pact broker

Swagger validation Verify that the API expectations in the Pactfiles can be met by the Provider’s published spec:bitbucket.org/atlassian/swagger-request-validator

Provider flow

Page 33: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

What do we have so far?

Page 34: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

Pact tests

Page 35: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

Pact tests Pact files

Page 36: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

Pact tests Pact files Swagger Validation

Page 37: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

Pact tests Pact files Swagger Validation Swagger spec.

published by Provider

Page 38: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

Pact tests Pact files Swagger Validation Swagger spec.

published by Provider

Pact Broker

Page 39: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

Pact tests Pact files Swagger Validation Swagger spec.

published by Provider

Pact Broker

Pulled by Provider for Swagger Validation

Page 40: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

We’re nearly there

Page 41: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

MODERN JAVASCRIPT CI

Unpact

bitbucket.org/atlassianlabs/unpact

4

Page 42: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

A Javascript library that guarantees your test mocks are consistent with your Pact expectations.

UNPACT

Page 43: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

UNPACT

const spec = { age: spec(24).type(), name: spec(‘David’).regex(‘[a-z]+’), roles: spec([ { title: spec(‘Developer’).regex(‘.+’), }, { title: spec(‘Quality Engineer’).regex(‘.+’), }, ]).array(),};export default spec; // Used to generate Pactsexport const mock = unpact(pactSpec);// Test mocks

Page 44: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

UNPACT

const spec = { age: spec(24).type(), name: spec(‘David’).regex(‘[a-z]+’), roles: spec([ { title: spec(‘Developer’).regex(‘.+’), }, { title: spec(‘Quality Engineer’).regex(‘.+’), }, ]).array(),};export default spec; // Used to generate Pactsexport const mock = unpact(pactSpec);// Test mocks

Page 45: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

MODERN JAVASCRIPT CI

Integration tests

Page 46: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

Pact tests Pact files Swagger Validation Swagger spec.

published by Provider

Pact Broker

Pulled by Provider for Swagger Validation

Page 47: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

Pact tests Pact files Swagger Validation Swagger spec.

published by Provider

Pact Broker

Pulled by Provider for Swagger ValidationUnpact

(or equivalent)

Guaranteed test mocks

Page 48: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

Pact tests Pact files Swagger Validation Swagger spec.

published by Provider

Pact Broker

Pulled by Provider for Swagger Validation

Guaranteed test mocks

Mock server

Unpact (or equivalent)

Page 49: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

Pact tests Pact files Swagger Validation Swagger spec.

published by Provider

Pact Broker

Pulled by Provider for Swagger Validation

Guaranteed test mocks

Mock server

UI tests

Unpact (or equivalent)

Page 50: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

Pact tests Pact files Swagger Validation Swagger spec.

published by Provider

Pact Broker

Pulled by Provider for Swagger ValidationUnpact

(or equivalent)

Guaranteed test mocks

Mock server

UI tests (full DOM)

Page 51: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

Pact tests Pact files Swagger Validation Swagger spec.

published by Provider

Pact Broker

Pulled by Provider for Swagger Validation

Guaranteed test mocks

Mock server

UI tests (full DOM)

Integration tests≡

Unpact (or equivalent)

Page 52: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

SUMMARY

Page 53: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

FRONTEND INTEGRATION TESTING FRAMEWORK

UI component tests

Pact (contract) tests

Swagger validation

Unpact

12

34

Page 54: David Piper - How to never use WebDriver againaadays.pl/wp-content/uploads/2017/10/David-Piper-How-to...Authentication No support intended for authentication. You don’t want to bake

Thank you!

DAVID PIPER | FRONTEND DEVELOPER | ATLASSIAN