Automation test scripting techniques

32
Automation Scripting Techniques Zhu Zhong (@ 钟钟 ) 6/30/14

description

Talk about the various scripting techniques used to write automation test scripts. 1. Linear scripts. 2. Structured scripts. 3. Shared scripts. 4. Data-Driven scripts. 5. Keyword-Driven scripts.

Transcript of Automation test scripting techniques

Page 1: Automation test scripting techniques

Automation Scripting Techniques

Zhu Zhong (@钟柱 )6/30/14

Page 2: Automation test scripting techniques

Hello, my name is Zhu Zhong (钟柱 )

12+ years, working on automation test tools

Work(ed, ing) for • Nortel• Alcatel-

Lucent

I like• Write code• Test

automation• Drawing• BBQ• Ocarina

Page 3: Automation test scripting techniques

A Good Book

O 13+ years passed so far, automation scripting techniques haven’t changed since the publishing of this book.

O All the ideas of this slides come from my understanding of this book plus my experience

• by Mark Fewster/ Dorothy Graham• Published: September, 1999

Page 4: Automation test scripting techniques

What’ll We be Talking About?

O We will NOT talk about O How to use an automation test tool

(EasyTest , QTP, Robot Framework, etc)

O Any specific testing techniques (GUI, Web, etc)

O We will talk aboutO Automation test scriptsO Types of scripts & their differencesO Which script technique to choose

Page 5: Automation test scripting techniques

Different Scripting Techniques

O Linear scriptsO Structured scriptsO Shared scriptsO Data-driven scriptsO Keyword-driven scripts

Page 6: Automation test scripting techniques

Different Scripting Techniques

O Linear scriptsO Structured scriptsO Shared scriptsO Data-driven scriptsO Keyword-driven scripts

Page 7: Automation test scripting techniques

Linear ScriptsO A Linear script is what you end up

with when you record a test case performed manually.

(AutoIt)

Page 8: Automation test scripting techniques

Is linear scripts Good or Bad?

Page 9: Automation test scripting techniques

Linear Scripts

O GoodO Quick start automationO Demonstration or trainingO Prepare test data

O BadO Hard coded data into scriptsO Vulnerable to changesO No sharing or reuse

Page 10: Automation test scripting techniques

Different Scripting Techniques

O Linear scriptsO Structured scriptsO Shared scriptsO Data-driven scriptsO Keyword-driven scripts

Page 11: Automation test scripting techniques

Structured Scripts= Linear scripts + if + for/while loop

(scratch)

Page 12: Automation test scripting techniques

Structured Scripts

O GoodO More robustO Reuse

O BadO Require programming skillsO More complexO Test data still ‘hard-coded’ into the

script

Page 13: Automation test scripting techniques

Different Scripting Techniques

O Linear scriptsO Structured scriptsO Shared scriptsO Data-driven scriptsO Keyword-driven scripts

Page 14: Automation test scripting techniques

Shared ScriptsO Shared scripts are scripts that are used (or

shared) by more than one test case.O May be called reusable script/function

library O Hard-coded values -> variables

Page 15: Automation test scripting techniques

Shared Scripts – an example

(EasyTest)

Convert shared script toHOST.checkLinuxVersion

Test case is simplified: just need to call shared script HOST.checkLinuxVersion

Page 16: Automation test scripting techniques

Shared Scripts – shared scripts/functions makes a test case

easier to read/maintain

This is a real test case we used to test EasyTest

(Squish)

Page 17: Automation test scripting techniques

Shared ScriptsO Good

O Similar tests will take less effort to implement

O Reuse: eliminates repetitions. O Keep the changes to a minimum

O BadO Hard to track/find scripts, documents,

names and store.O Shared scripts are often specific to part

of the system under test.

Page 18: Automation test scripting techniques

Different Scripting Techniques

O Linear scriptsO Structured scriptsO Shared scriptsO Data-driven scriptsO Keyword-driven scripts

Page 19: Automation test scripting techniques

Data-Driven Scripts

O A data-driven script stores test data (inputs & expected outcomes) in a separate (data) file rather than in the script itself.

Page 20: Automation test scripting techniques

Data-Driven Scripts- explained

Driver Test

Script

System Under Test

Data File

Data File

Data File

System Under Test

CSVExcelXMLText

Page 21: Automation test scripting techniques

Data-Driven Scripts- Let’s test addition on a calculator

Test Case(s) = Test Data + Driver Test Script

(Python)

Page 22: Automation test scripting techniques

Data-Driven ScriptsO Good

O Similar tests can be added very quickly.O Adding new tests can be done by testers w/o

knowledge of the automation test tool scripting language.

O Separation of roles: Tester (test data file) + automation designer (driver scripts)

O BadO Driver script is complex. Need good programming

skills.O One driver script is only good for one kind of testing.O Changes to either data file or driver script, you’ll

need to change both

Page 23: Automation test scripting techniques

Different Scripting Techniques

O Linear scriptsO Structured scriptsO Shared scriptsO Data-driven scriptsO Keyword-driven scripts

Page 24: Automation test scripting techniques

How to test square root ?Can we re-use addition.py test script?

Driver Test Script

Data FileSystem Under Test

Both Data File & Driver Test Script can’t be re-used, need to create new ones

Page 25: Automation test scripting techniques

Keyword-Driven ScriptsO Keyword-driven comes from Data-driven to

overcome some limitations:O One driver script only works for one kind of

testsO “What to test” is built into both the data file

and driver script, so they need to be synchronized.

O Can we ?O Use one “driver script” to drive all data files?O Put “What to test” in just one data file?

Page 26: Automation test scripting techniques

From Data-Driven to Keyword-Driven

Driver Test Script

Data FileSystem Under Test

Driver Test

Script

System Under Test

Data FileData File

Data FileData FileTest Data File

Keyword

Scripts

Test dataWhat to test

How to testControllogic

Page 27: Automation test scripting techniques

Keyword-Driven Scripts

Driver Test

Script

System Under Test

Data FileData FileTest Data File

Keyword

Scripts

open calculator app

close calculator app

add two numbersresult should be

. . . .

Page 28: Automation test scripting techniques

Keyword-Driven Scripts and Other Scripts-Mindset change: What to test vs. How to test

Other scripts: Detailed info on what & how to test

Keyword-Driven scripts: Just what to test

Sometimes “what to test” is described in your test script comments/document

Page 29: Automation test scripting techniques

Keyword-Driven Scripts-Separation of Concerns

Driver Test

Script

System Under Test

Data FileData FileTest Data File

Keyword

Scripts

Test data +What to test

How to testControl logic

• Tester• No need of

programming skills

• Use Excel/notepad to edit Test Data File

• Tool Designer

• Strong programming skills

• Use C++/ Java/ Python/Ruby to code the 1 and only 1 driver test script

• Automation Expert• Familiar with a scripting

language (Python/ TCL/ test tool language)

• Good knowledge of the System Under Test

Page 30: Automation test scripting techniques

Keyword-Driven ScriptsO Good

O All goodies from Data-DrivenO Test data file is also readable test documentO Separation of concernsO Mindset change: What to test vs. How to test

O BadO Seen as silver bullet, but it’s notO Require good knowledge and experience on both

programming and System Under Test to plan, design and maintain keywords.

O If not well planned, you’ll be happy from the beginning and suffer/fail in the near future.

Page 31: Automation test scripting techniques

I have a question for you.

Which scripting technique is better?

Page 32: Automation test scripting techniques

Do you have a question for me?

Email [email protected] follow me on Sina Weibo @钟柱