49
@JanMolak @Wakaleo #Devoxx #SerenityJS

Serenity/JS - next generation acceptance testing for modern web applications

Embed Size (px)

Citation preview

Page 1: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

Page 2: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

Page 3: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

Jan Molak, John Smart:

Next GenerationAcceptance Testing

Page 4: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

acceptance tests that help deliver working software that matters

Page 5: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

what’s the root cause ofmost software defects?

Page 6: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

ambiguous, unclear and incorrectrequirements

Page 7: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

44-80%of all software defectssource:- 44% - “Out of Control - Why Control Systems Go Wrong and How to Prevent Failure”- 56% - “An Information Systems Manifesto”- 80% - “Requirements: A quick and inexpensive way to improve testing”

Page 8: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

Behaviour-Driven Development

Page 9: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

Domain-Driven DesignBehaviour-Driven Development

Page 10: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

User-Centred DesignDomain-Driven Design

Behaviour-Driven Development

Page 11: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

reliablescalable

actionable

acceptance tests that are:

Page 12: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

example

feature → scenario

Page 13: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

Feature:Filterthelisttofinditemsofinterest InordertolimitthecognitiveloadJameswouldliketofilterhistodolisttoonlyshowitemsofinterest

Page 14: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

Scenario:ViewingActiveitemsonlyGivenJameshasalistwithWalkthedog,GetacoffeeAndhecompletesWalkthedogWhenhefiltershislisttoshowonlyActivetasksThenhistodolistshouldcontainGetacoffee

Page 15: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

automation, take #1 “a test script”

Page 16: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

GivenJameshasalistwithWalkthedog,Getacoffee——————————————————————————————————————————————————————this.Given(/^.*hasalistwith(.*)$/,(items,done)=>{

done();});

Page 17: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

GivenJameshasalistwithWalkthedog,Getacoffee——————————————————————————————————————————————————————this.Given(/^.*hasalistwith(.*)$/,(items,done)=>{browser.get('http://todomvc.com/examples/angularjs/');

items.split(‘,’).forEach(item=>{element(by.id(‘new-todo’)).sendKeys(item);element(by.id(‘new-todo’)).sendKeys(protractor.Key.ENTER);});

done();});

Page 18: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

GivenJameshasalistwithWalkthedog,Getacoffee——————————————————————————————————————————————————————this.Given(/^.*hasalistwith(.*)$/,(items,done)=>{browser.get('http://todomvc.com/examples/angularjs/');

items.split(‘,’).forEach(item=>{element(by.id(‘new-todo’)).sendKeys(item);element(by.id(‘new-todo’)).sendKeys(protractor.Key.ENTER);});

done();});

Page 19: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

automation, take #2 “a re-structured test script”

Page 20: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

GivenJameshasalistwithWalkthedog,Getacoffee——————————————————————————————————————————————————————this.Given(/^.*hasalistwith(.*)$/,(items,done)=>{lettodoList=newTodoListPage();

todoList.get();

items.split(‘,’).forEach(item=>{todoList.add(item);});

done();});

Page 21: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

classTodoListPage{get(){browser.get('http://todomvc.com/examples/angularjs/');}add(item:string){element(by.id(‘new-todo’)).sendKeys(item); element(by.id('new-todo')).sendKeys(protractor.Key.ENTER); }complete(item:string){element(by.xpath('//*[@class="view"andcontains(.,"'+item+'")]'+ '//input[@type="checkbox"]')).click();}//…}

Page 22: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

classTodoListPage{get(){browser.get('http://todomvc.com/examples/angularjs/');}add(item:string){element(by.id(‘new-todo’)).sendKeys(item); element(by.id('new-todo')).sendKeys(protractor.Key.ENTER); }complete(item:string){element(by.xpath('//*[@class="view"andcontains(.,"'+item+'")]'+ '//input[@type="checkbox"]')).click();}//…}

Page 23: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

automation, take #3 “a screenplay”

Page 24: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

hierarchical task analysis

Page 25: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

hierarchical task analysis

actor

Page 26: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

hierarchical task analysis

goal

Page 27: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

hierarchical task analysis

tasks

Page 28: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

hierarchical task analysis

interactions

Page 29: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

Feature:FilterthelisttofinditemsofinterestInordertolimitthecognitiveloadJameswouldliketofilterhistodolisttoonlyshowitemsofinterest

Scenario:ViewingActiveitemsonlyGivenJameshasalistwithWalkthedog,GetacoffeeAndhecompletesWalkthedogWhenhefiltershislisttoshowonlyActivetasksThenhistodolistshouldcontainGetacoffee

Page 30: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

Feature:FilterthelisttofinditemsofinterestInordertolimitthecognitiveloadJameswouldliketofilterhistodolisttoonlyshowitemsofinterest

Scenario:ViewingActiveitemsonlyGivenJameshasalistwithWalkthedog,GetacoffeeAndhecompletesWalkthedogWhenhefiltershislisttoshowonlyActivetasksThenhistodolistshouldcontainGetacoffee

actor

Page 31: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

Feature:FilterthelisttofinditemsofinterestInordertolimitthecognitiveloadJameswouldliketofilterhistodolisttoonlyshowitemsofinterest

Scenario:ViewingActiveitemsonlyGivenJameshasalistwithWalkthedog,GetacoffeeAndhecompletesWalkthedogWhenhefiltershislisttoshowonlyActivetasksThenhistodolistshouldcontainGetacoffee

actor goal

Page 32: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

Scenario:ViewingActiveitemsonlyGivenJameshasalistwithWalkthedog,GetacoffeeAndhecompletesWalkthedogWhenhefiltershislisttoshowonlyActivetasksThenhistodolistshouldcontainGetacoffee

actor goal

tasks

Page 33: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

ToviewActiveitemsonly,Jamesattemptsto:

Startwithalistcontaining:Walkthedog,GetacoffeeCompleteatodoitemcalled:WalkthedogFilterlisttoshowonlyActivetasksExpecttosee:Getacoffee

actor goal

tasks

Page 34: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

ToviewActiveitemsonly,Jamesattemptsto:

Startwithalistcontaining:Walkthedog,GetacoffeeOpenbrowseron‘todomvc.com/examples/angularjs/'ResizebrowserwindowtomaximumAddatodoitemcalled‘Walkthedog’Addatodoitemcalled‘Getacoffee’...

actor goal

tasks

Page 35: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

ToviewActiveitemsonly,Jamesattemptsto:

Startwithalistcontaining:Walkthedog,GetacoffeeOpenbrowseron‘todomvc.com/examples/angularjs/'ResizebrowserwindowtomaximumAddatodoitemcalled‘Walkthedog’Addatodoitemcalled‘Getacoffee’Enterthevalue‘Getacoffee’HittheEnterkey...

actor goal tasks inter-

actions

Page 36: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

ToviewActiveitemsonly,Jamesattemptsto:

Startwithalistcontaining:Walkthedog,GetacoffeeOpenbrowseron‘todomvc.com/examples/angularjs/'ResizebrowserwindowtomaximumAddatodoitemcalled‘Walkthedog’Addatodoitemcalled‘Getacoffee’Enterthevalue‘Getacoffee’HittheEnterkey...

Page 37: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

ToviewActiveitemsonly,Jamesattemptsto:

Start.withATodoListContaining(‘Walkthedog’,…)Open.browserOn(‘todomvc.com/examples/angularjs/’)ResizeBrowserWindow.toMaximum()AddATodoItem.called(‘Walkthedog’)AddATodoItem.called(‘Getacoffee’)Enter.theValue(‘Getacoffee’).into(TodoList.New_Todo_Field).thenHit(protractor.Key.Enter)

Page 38: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

ToviewActiveitemsonly,Jamesattemptsto:

Start.withATodoListContaining(‘Walkthedog’,…)Open.browserOn(‘todomvc.com/examples/angularjs/’)ResizeBrowserWindow.toMaximum()AddATodoItem.called(‘Walkthedog’)AddATodoItem.called(‘Getacoffee’)Enter.theValue(‘Getacoffee’).into(TodoList.New_Todo_Field).thenHit(protractor.Key.Enter)

Page 39: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

Serenity/JS Screenplay Pattern

Page 40: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

letjames=Actor.named(‘James’);actor

Page 41: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

letjames=Actor.named(‘James’).whoCan(BrowseTheWeb.using(protractor.browser));

actor has

abilities

Page 42: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

james.attemptsTo(Start.withATodoListContaining(items));

actor performs

tasks

Page 43: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

this.Given(/^.*hasalistwith(.*)$/,(items)=>{returnjames.attemptsTo(Start.withATodoListContaining(items));});

actor performs

tasks

Page 44: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

exportclassStartimplementsTask{performAs(actor:PerformsTasks):PromiseLike<void>{returnactor.attemptsTo(Open.browserOn('/examples/angularjs/'),ResizeBrowserWindow.toMaximum(),AddTodoItems.called(this.initialItems));}}

tasks consist of

tasks

Page 45: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

exportclassAddATodoItemimplementsTask{performAs(actor:PerformsTasks):PromiseLike<void>{returnactor.attemptsTo(Enter.theValue(‘Walkthedog’).into(TodoList.New_Todo_Field),Hit.the(protractor.Key.Enter).into(ToDoList.New_Todo_Field) ); }}

tasks consist of

inter-actions

Page 46: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

exportclassAddATodoItemimplementsTask{

@step('{0}addsatodoitemcalled"#name"')performAs(actor:PerformsTasks):PromiseLike<void>{//…}

constructor(privatename:string){}}

tasks can be

annotated

Page 47: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

to create powerful reports

Page 48: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

lights, camera,Demo!

Page 49: Serenity/JS - next generation acceptance testing for modern web applications

@JanMolak @Wakaleo#Devoxx #SerenityJS

github.com/jan-molak/serenity-js