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

35
Adapting MVC for Test Automation

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

Page 1: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

Adapting MVC for Test Automation

Page 2: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

Who am I?

●Catalin Comanici

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

●fun guy and rock star wannabe

Page 3: 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

Page 4: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

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

Page 5: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

What is MVC

Page 6: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

What is MVC

Design pattern separating:● logic● data● view

into different components

6

Page 7: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

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

Page 8: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

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

Page 9: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

View

● submits actions to Controller

● presents the model in a user friendly way

● usually called UI, GUI …

9

Page 10: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

Controler

● links User, View and Model

● responds to user input

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

10

Page 11: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

Benefits

● clear separation of layers

● code reusability

● enables parallel development and developer specialization

11

Page 12: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

Disadvantages

● increased complexity

● not suitable for small applications

12

Page 13: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

Common approaches totest automation

Page 14: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

Record and playback

Page 15: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

Record and playback

Pros:● easy setup● rapid development

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

15

Page 16: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

Script Modularity Framework

Page 17: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

Script Modularity Framework

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

Cons:● sharing data between scripts is

challenging● test data duplicated

17

Page 18: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

Test Library Architecture

Page 19: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

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

Page 20: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

Keyword-Driven

Page 21: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

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

Page 22: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

Why change?

Because:

● we write rigid tests

● tests depend on lengthy setup

● maintenance costs can be high

22

Page 23: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

How can we use it?

Page 24: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

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

Page 25: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

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

Page 26: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

User interaction layer (View)

● simulates users interaction

● also contains page objects

● submits actions to controller

26

Page 27: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

Test layer (Controller)● contains all test assertion

● decides assertions based on context and data

● is called by the user interaction layer

27

Page 28: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

28

Page 29: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

Test commenting form

Page 30: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

30

function testCommentingForm (languageCode){

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

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

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

Page 31: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

3131

function isCommentFormOpen(languageCode){

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

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

} else{ assertEquals(

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

}

}

Page 32: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

Benefits

● clear separation of layers

● enables parallel development

● multiple asserts on each step

32

Page 33: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

Disadvantages

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

● requires coding discipline

● coding knowledge above average

33

Page 34: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

Solutions

Design patterns:● MVC● Observer pattern

Frameworks:● Spring ● Google Guice

34

Page 35: Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.

Q&A