Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun...

Post on 23-Dec-2015

218 views 0 download

Transcript of Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun...

Adapting MVC for Test Automation

Who am I?

●Catalin Comanici

●QA for 10 years, doing test automation for about 6 years

●fun guy and rock star wannabe

Agenda

● What is Model View Controller (MVC)?

● Common approaches and frameworks

● How can we use it?

3

What this is not

● this is not a silver bullet

● this might not work for all projects

● I have not built a complete framework around this approach YET

4

What is MVC

What is MVC

Design pattern separating:● logic● data● view

into different components

6

View• Submits user actions and user

data to Controller

Controller• Submits data to Model• Returns data from

Model to View

Model• Persists data in

databases• Returns data to

Controller

Model

● provides business objects to controller

● data access is uniform regardless of the data source

● if data source or the way data is stored changes, it requires changing only this layer

8

View

● submits actions to Controller

● presents the model in a user friendly way

● usually called UI, GUI …

9

Controler

● links User, View and Model

● responds to user input

● has no implication in business logic but mostly handles application flow

10

Benefits

● clear separation of layers

● code reusability

● enables parallel development and developer specialization

11

Disadvantages

● increased complexity

● not suitable for small applications

12

Common approaches totest automation

Record and playback

Record and playback

Pros:● easy setup● rapid development

Cons:● not easy to customize ● not easy maintain● some workflows cannot be automated

15

Script Modularity Framework

Script Modularity Framework

Pros:● cost efficient maintenance● scalable● changes easily integrated

Cons:● sharing data between scripts is

challenging● test data duplicated

17

Test Library Architecture

Test Library Architecture

Pros:● low cost efficient maintenance and

scalability● great degree of reusability

Cons:● data lives in the test scripts● library can grow to be complicated

19

Keyword-Driven

Keyword-Driven

Pros:● reduced number of test scripts● keywords are highly reusable● Increases flexibility and maintainability

Cons:● high degree of programming knowledge● becomes complicated gradually● process is complex

21

Why change?

Because:

● we write rigid tests

● tests depend on lengthy setup

● maintenance costs can be high

22

How can we use it?

How can we use it?

Implement the best bits:

● clear separation of concerns

● one layer to share data across our tests

● create reusable components

24

Data layer (MODEL)

● one layer to store data and share across all tests

● uniform structure for simple reuse

● aggregate data from setup methods and other tests

25

User interaction layer (View)

● simulates users interaction

● also contains page objects

● submits actions to controller

26

Test layer (Controller)● contains all test assertion

● decides assertions based on context and data

● is called by the user interaction layer

27

28

Test commenting form

30

function testCommentingForm (languageCode){

page.open(languageCode);controller.isPageLoaded();

page.clickAddComment();controller.isCommentFormOpen(languageCode);

page.addComment(”Test”);controller.isSuccessMessVisible();}

3131

function isCommentFormOpen(languageCode){

if(languageCode == ‘us’){ assertEquals(

page.getNameFieldText(), data.getNameFieldTextValue(‘us’));…

} else{ assertEquals(

page.getNameFieldText(), data.getNameFieldTextValue(‘ro’));…

}

}

Benefits

● clear separation of layers

● enables parallel development

● multiple asserts on each step

32

Disadvantages

● if one assert fails, all the tests in that script fail

● requires coding discipline

● coding knowledge above average

33

Solutions

Design patterns:● MVC● Observer pattern

Frameworks:● Spring ● Google Guice

34

Q&A