41
PRACTICAL SIKULI USING SCREENSHOTS FOR GUI AUTOMATION AND TESTING Tsung-Hsiang (Sean) Chang MIT CSAIL 1 Collaborators: Tom Yeh, Rob Miller

Practical Sikuli: using screenshots for GUI automation and testing

  • Upload
    vgod

  • View
    78.038

  • Download
    3

Embed Size (px)

DESCRIPTION

This's a Sikuli tutorial I gave to the Megason Lab at Harvard Medical School.

Citation preview

Page 1: Practical Sikuli: using screenshots for GUI automation and testing

PRACTICAL SIKULIUSING SCREENSHOTS FOR GUI AUTOMATION AND TESTING

Tsung-Hsiang (Sean) ChangMIT CSAIL

1

Collaborators: Tom Yeh, Rob Miller

Page 2: Practical Sikuli: using screenshots for GUI automation and testing

WHAT IS SIKULI?2

Page 3: Practical Sikuli: using screenshots for GUI automation and testing

WHAT IS SIKULI?2

Page 4: Practical Sikuli: using screenshots for GUI automation and testing

1

2

3

3

Page 5: Practical Sikuli: using screenshots for GUI automation and testing

Low-level API?Mac’s system design?

4

Page 6: Practical Sikuli: using screenshots for GUI automation and testing

EMPTY THE TRASH CAN5

Page 7: Practical Sikuli: using screenshots for GUI automation and testing

OUTLINE

• What Sikuli is

• How Sikuli works

• Sikuli for GUI automation

• Sikuli for GUI testing

• Conclusions

6

Page 8: Practical Sikuli: using screenshots for GUI automation and testing

How Sikuli Works

7

Page 9: Practical Sikuli: using screenshots for GUI automation and testing

TEMPLATE MATCHING

click(                            )

8

Page 10: Practical Sikuli: using screenshots for GUI automation and testing

TEMPLATE MATCHING

click(                            )

8

Page 11: Practical Sikuli: using screenshots for GUI automation and testing

SYSTEM DESIGN

9

Page 12: Practical Sikuli: using screenshots for GUI automation and testing

1

2

3

DEMO 1:EMPTY TRASH CAN

10

Page 13: Practical Sikuli: using screenshots for GUI automation and testing

REGION AND MATCH

11

match = region.find( or “text pattern”)

Region

Page 14: Practical Sikuli: using screenshots for GUI automation and testing

12

• basic attributes: x, y, width, height

• Match is a Region

• Screen is also a Region

• chained methods: Screen(0).find(W).click(X)

REGION

Page 15: Practical Sikuli: using screenshots for GUI automation and testing

KEY METHODS OF REGION

• find, findAll, exists, wait, waitVanish

• Mouse Actions

click, doubleClick, rightClick, hover, dragDrop

mouseDown, mouseUp

• Keyboard Actions

type(text), paste(text)

keyDown, keyUp

13

Page 16: Practical Sikuli: using screenshots for GUI automation and testing

EX2: FACEBOOK STALKER

14

Page 17: Practical Sikuli: using screenshots for GUI automation and testing

EX2: FACEBOOK STALKER

14

Page 18: Practical Sikuli: using screenshots for GUI automation and testing

RESTRICT SEARCH REGION

15

Page 19: Practical Sikuli: using screenshots for GUI automation and testing

But the Region constant is bad

16

Page 20: Practical Sikuli: using screenshots for GUI automation and testing

APP CLASS

17

• firefox = App.open(“Firefox”)

• firefox.focus(), firefox.close()

• firefox.window([n])

• returns the Region of Firefox’s n-th window

Page 21: Practical Sikuli: using screenshots for GUI automation and testing

FIND IN CERTAIN APP

18

Page 22: Practical Sikuli: using screenshots for GUI automation and testing

EX3: MUTE SPEAKERS

19

Page 23: Practical Sikuli: using screenshots for GUI automation and testing

EX3: MUTE SPEAKERS

19

Page 24: Practical Sikuli: using screenshots for GUI automation and testing

SPATIAL OPERATORS

20

Page 25: Practical Sikuli: using screenshots for GUI automation and testing

SPATIAL OPERATORS

20

Page 26: Practical Sikuli: using screenshots for GUI automation and testing

SPATIAL OPERATORS (2)

21

Page 27: Practical Sikuli: using screenshots for GUI automation and testing

TEXT MATCHING AND RECOGNITION

22

• click(“OK”), find(“Cancel”)

• region.text() - read the text in a region

Page 28: Practical Sikuli: using screenshots for GUI automation and testing

VISUAL-EVENT-DRIVEN PROGRAMMING

23

• observes visual events in any Region

• Region.onAppear(Pattern, handler)

• Region.onVanish(Pattern, handler)

• Region.onChange(Pattern, handler)

Page 29: Practical Sikuli: using screenshots for GUI automation and testing

VISUAL-EVENT-DRIVEN PROGRAMMING

24

Page 30: Practical Sikuli: using screenshots for GUI automation and testing

VISUAL-EVENT-DRIVEN PROGRAMMING

24

Page 31: Practical Sikuli: using screenshots for GUI automation and testing

VISUAL DICTIONARY

25

Page 32: Practical Sikuli: using screenshots for GUI automation and testing

GUITESTING

26

Page 33: Practical Sikuli: using screenshots for GUI automation and testing

VISUAL ASSERTION

• make sure the appearance of visual feedback

27

Page 34: Practical Sikuli: using screenshots for GUI automation and testing

VISUAL ASSERTION

• make sure the appearance of visual feedback

27

Page 35: Practical Sikuli: using screenshots for GUI automation and testing

JUNIT INTEGRATION

28

Page 36: Practical Sikuli: using screenshots for GUI automation and testing

SIKULI IN COMMAND LINE

29

usage:Sikuli-­‐IDE  [-­‐-­‐args  <arguments>]  [-­‐h]  [-­‐r  <sikuli-­‐file>]  [-­‐s]  [-­‐t  <sikuli-­‐test-­‐case>]  -­‐-­‐args  <arguments>                          specify  the  arguments  passed  to  Jython's  sys.argv  -­‐h,-­‐-­‐help                                            print  this  help  message  -­‐r,-­‐-­‐run  <sikuli-­‐file>                  run  .sikuli  or  .skl  file  -­‐s,-­‐-­‐stderr                                        print  runtime  errors  to  stderr  instead  of  popping  up  a  message  box  -­‐t,-­‐-­‐test  <sikuli-­‐test-­‐case>      run  .sikuli  as  a  unit  test  case  with  junit's  text  UI  runner

Page 37: Practical Sikuli: using screenshots for GUI automation and testing

CONCLUSIONS

30

Page 38: Practical Sikuli: using screenshots for GUI automation and testing

PLATFORM INDEPENDENCE

• Works on ANY GUI that can be displayed on Windows/Linux/Mac

• Virtual machines

• Remote desktop

• Mobile simulators: Android, iPhone

• Web: Flash, HTML+Javascript

31

Page 39: Practical Sikuli: using screenshots for GUI automation and testing

PROGRAM AGAINST UI

32

Sikuli programs are written against the user interface instead of an API

UI: visible, familiar, always exists API: faster, probably more stable

Page 40: Practical Sikuli: using screenshots for GUI automation and testing

FUTURE WORK

• fast and accurate OCR on screen

• Accessibility API integration

33

Page 41: Practical Sikuli: using screenshots for GUI automation and testing

Thanks!

http://sikuli.org

New Sikuli X 1.0-rc2 released.

Follow us on twitter @sikuli

Thanks to our funding sources: NSF and Quanta Computer (as a part of TParty project.)

or, just google “sikuli”

34