【图形化编程软件】 sikuli常用函数、简单事件操作 键盘操作 个人总结笔记

sikuli函数、简单事件操作个人总结笔记

 

作者:stormwy

网址:http://blog.csdn.net/stormwy/article/details/7955137


其实sikuli的语法跟python的语法是一样的,大家在学习sikuli时,要看看python的语法,这样就能有更多样的方法来实现丰富的功能。

由于关于sikuli的中文资料实在太少了,我在学习使用sikuli的过程中,记录下下面一些常用操作,以供sikuli学习者参考!

1findAll(图片)

findAll() searches the entire screen for all the matchingvisual patterns and returns a list of locations of those similar patterns. Thiscapability allows us to obtain all the checked items are on the screen. Then,we can simply write a for loop in standard Python syntax and call click() oneach element in the list.

【图形化编程软件】 sikuli常用函数、简单事件操作 键盘操作 个人总结笔记_第1张图片

典型例子:Uncheck AllCheckboxes

2、点击操作

click(x)

左键点击元素x

rightClick(x)

右键点击元素x


3below()


4dragDrop()

This function takes two images asarguments. The first image describes the source GUI object to drag and thesecond image describes the appearance of the destination location where the GUIobject should be dragged to and dropped.


典型例子:Working with Sliders


5right()

表示在右边


6popup(string)

弹出一个提示框
例:
popup("Obama has updated his message")
运行:
【图形化编程软件】 sikuli常用函数、简单事件操作 键盘操作 个人总结笔记_第2张图片


7、键盘操作:


8Resizinga Window

This tutorial demonstrates how to use Sikuli script to resize a window by dragging its bottom-right corner.
 In order to do so, you have to evaluate the current position of this corner on the screen, 
move the mouse pointer to the applicable click point and then perform one or more drag actions.
【图形化编程软件】 sikuli常用函数、简单事件操作 键盘操作 个人总结笔记_第3张图片


9、表示方位的词:

Nearby(number)、above()、below()、left()、right()、getCenter()


10、位置偏移

Location(t.x-30,t.y+30)

其实用图形法会方便和舒服:点击图片,进入设置界面,点击偏移选项卡,然后可以用鼠标设置偏移量,点到哪就偏移到哪,如果想偏移到更远的地方,就滚动鼠标滑轮,可以放大缩小页面,选择偏移点。


11、屏幕翻页


其他键盘操作类型参数见Key (built-in class)


12、读写文件(其实就是python的语法)

#打开 写文件

f=open('c:/wy.txt','a')

t="hello\n"

f . write(t)

f.close()

 

#打开 读文件

f=open('c:/wy.txt','r')

t=f.read()

popup(t)


#open(路径+文件名,读写模式)

#读写模式:r只读,r+读写,w新建(会覆盖原有文件),a追加,b二进制文件.常用模式


13input(“字符串”)

显示一个输入框,以供输入。要输入中文应该在前面加u

input(u“字符串”),不然会乱码


14if语句

If 条件 and 条件:#(注意有冒号,‘#’号表示注释)

       语句


15openApp(应用程序路径名)    

打开应用程序,注意应用程序的路径名里的斜杠“\”要改为双斜杠“\\”。


16、复制、粘贴操作

type("c",KEY_CTRL)  #复制

type("v",KEY_CTRL)  #粘贴


17waitVanish("20120902172907.png",300)

waitVanish()最好带时间,不然还没消失就返回消失的信息了。

我觉得用下面的代替好些

while exists("image.png"):
     wait(1)   
#ifthe image exist it will wait until the image disappear


18sikuli输入中文

input(u"请输入想要获取并下载多少个页面的App资源:")

popup(u”chinese”)

在前面加‘u’避免乱码,‘u’是unicode还是utf8,我就不清楚了。


19、设定循环次数

for x inrange(10): #循环10次,x不用预先定义

       循环体


20、编程小经验

1、用sikuli编程的时候,最好是保存为可执行文件来测试,因为有些功能直接测试是测试不出来的,比如type("c",KEY_CTRL)  #复制,直接运行测试(好像)是无效的,当时我还困惑了很久。后来无意中保存为可执行文件后才发现是可以的。

 

2、用sikuli编程时,多用wait()语句,因为很多时候没有给它一定的识别时间,就容易出错。

还有的就是,进行复制粘贴操作时,如果需要切换到另外一个页面粘贴,再切回来,如果中间不wait一段时间,等粘贴完成,很可能就没有粘贴成功。

 

以上是个人的经验之谈,希望对大家有所帮助!

附录是sikuli官网上http://sikuli.org/docx/的函数检索Index,很多新学习者不知道,所以在这里贴出来。

如果想要知道更多sikuli的详情,我推荐你到官网http://sikuli.org/,

因为中文的关于sikuli的编程资料太少了。


附录:sikuli函数检索

Sikuli Funtions Index

Symbols|A |B |C |D |E |F |G |H |I |K |L |M |N |O |P |R |S |T |W

Symbols

--args <arguments>

command line option

-h,--help

command line option

-i

command line option

-r,--run <sikuli-file>

command line option

-s,--stderr

command line option

-t,--test <sikuli-file>

command line option

A

above() (Location method)

(Region method)

ActionLogs (Settings attribute)

addHotkey() (Env method)

addImagePath() (built-in function)

ALT (built-in variable)

App (built-in class), [1]

B

below() (Location method)

(Region method)

Bundle Path

C

capture() (Screen method)

changes (SikuliEvent attribute)

circle() (in module guide)

click() (Region method)

clickable() (in module guide)

close() (App class method)

(App method)

closeApp() (built-in function)

CMD (built-in variable)

command line option

--args <arguments>

-h,--help

-i

-r,--run <sikuli-file>

-s,--stderr

-t,--test <sikuli-file>

CTRL (built-in variable)

D

DebugLogs (Settings attribute)

DelayAfterDrag (Settings attribute)

DelayBeforeDrop (Settings attribute)

dialog() (in module guide)

doubleClick() (Region method)

drag() (Region method)

dragDrop() (Region method)

dropAt() (Region method)

E

exact() (Pattern method)

exists() (Region method)

exit() (built-in function)

F

find() (Finder method)

(Region method)

findAll() (Region method)

Finder (built-in class),[1]

Finder() (Finder method)

focus() (App class method)

(App method)

focusedWindow() (App class method)

G

getAutoWaitTimeout() (Region method)

getBottomLeft() (Region method)

getBottomRight() (Region method)

getBounds() (Screen method)

getBundlePath() (built-in function)

getCenter() (Region method)

getClipboard() (Env method)

getFilename() (Pattern method)

getFindFailedResponse() (Region method)

getH() (Region method)

getImagePath() (built-in function)

getLastMatch() (Region method)

getLastMatches() (Region method)

getLocationFromPSRML() (Region method)

getMouseLocation() (Env method)

getNumberScreens() (Screen method)

getOS() (Env method)

getOSVersion() (Env method)

getParameter() (Vision method)

getRegionFromPSRM() (Region method)

getScore() (Match method)

getScreen() (Region method)

getSikuliVersion() (Env method)

getTarget() (Match method)

getTargetOffset() (Pattern method)

getThrowException() (Region method)

getTopLeft() (Region method)

getTopRight() (Region method)

getW() (Region method)

getX() (Location method)

(Region method)

getY() (Location method)

(Region method)

guide (module)

H

hasNext() (Finder method)

highlight() (Region method)

hover() (Region method)

I

Image Search Path

SIKULI_IMAGE_PATH

import .sikuli

InfoLogs (Settings attribute)

input() (built-in function)

inside() (Region method)

isLockOn() (Env method)

K

Key (built-in class)

keyDown() (Region method)

KeyModifier (built-in class)

keyUp() (Region method)

L

left() (Location method)

(Region method)

load() (built-in function)

Location (built-in class)

Location() (Location method)

M

Match (built-in class), [1]

match (SikuliEvent attribute)

META (built-in variable)

MinSimilarity (Settings attribute)

morphTo() (Region method)

mouseDown() (Region method)

mouseMove() (Region method)

mouseUp() (Region method)

MoveMouseDelay (Settings attribute)

moveTo() (Region method)

N

nearby() (Region method)

next() (Finder method)

O

observe() (Region method)

ObserveMinChangedPixels (Settings attribute)

ObserveScanRate (Settings attribute)

offset() (Location method)

(Region method)

onAppear() (Region method)

onChange() (Region method)

onVanish() (Region method)

open() (App class method)

(App method)

openApp() (built-in function)

P

paste() (Region method)

Pattern (built-in class),[1]

pattern (SikuliEvent attribute)

Pattern() (Pattern method)

popup() (built-in function)

R

rectangle() (in module guide)

Region (built-in class),[1],[2],[3],[4], [5], [6], [7], [8], [9]

region (SikuliEvent attribute)

Region() (Region method)

removeHotkey() (Env method)

removeImagePath() (built-in function)

right() (Location method)

(Region method)

rightClick() (Region method)

run() (built-in function)

S

Screen (built-in class),[1],[2]

Screen() (Screen method)

selectRegion() (Screen method)

setAutoWaitTimeout() (Region method)

setBundlePath() (built-in function)

setFindFailedResponse() (Region method)

setH() (Region method)

setLocation() (Location method)

setParameter() (Vision method)

setRect() (Region method)

setROI() (Region method)

setShowActions() (built-in function)

setThrowException() (Region method)

Settings (built-in class)

setW() (Region method)

setX() (Region method)

setY() (Region method)

SHIFT (built-in variable)

show() (in module guide)

SIKULI_IMAGE_PATH

Image Search Path

SikuliEvent (built-in class)

similar() (Pattern method)

SlowMotionDelay (Settings attribute)

stopObserver() (Region method)

switchApp() (built-in function)

T

targetOffset() (Pattern method)

text() (in module guide)

(Region method)

tooltip() (in module guide)

type (SikuliEvent attribute)

type() (Region method)

W

wait() (Region method)

WaitScanRate (Settings attribute)

waitVanish() (Region method)

wheel() (Region method)

WIN (built-in variable)

window() (App method)

你可能感兴趣的:(游戏测试)