Use of Sikulix automation tools

1. Introduction to Sikuli-x

Sikuli is a technology for identifying and controlling GUI components for UI automation testing. It was developed and designed by researchers at MIT. Sikuli means the eye of God in the language of the Huichol Indians in Mexico. The working mode of Sikuli is the same as that of the human eye, directly recognizing images.

Sikuli-x is the latest version of Sikuli, which supports automation of Mac OS X, Windows and Linux operating systems

Sikuli-x is written in java, so it needs the support of java environment

2. Environment construction

(1) Download jdk, configure environment variables

(2) Download sikulix-IDE

http://sikulix.com/ official website address

https://raiman.github.io/SikuliX1/downloads.html  

 

Click a link to download, put it in a separate folder after the download is complete, double-click to start the IDE

3. IDE usage and method introduction


As shown in the figure, the interface consists of six parts: the main menu bar, the toolbar, the method bar, the editing area, the log bar and the status bar. The one I downloaded has no method bar

 The commonly used methods provided by Sikuli mainly include four types: search, mouse action, keyboard action, and event observation

For a detailed introduction to the method, see https://blog.csdn.net/airfer/article/details/47726939 sikuli function, simple event operation personal summary notes

Simple to use:

a=10
app_path = 'C:\Program Files (x86)\NGVONE\Client\TopSAP.exe'
openApp(app_path)               #打开app
wait("1577694539817.png")       #等待界面出现
click("1577694966548.png")      #点击图片中心
#type('test000')
paste('test000')                #在鼠标处进行粘贴操作
#type(Keys.ENTER)
wait(5)
click("1577696921363.png")
wait(2)
type('111111')         
wait(1)
type(Key.ENTER)             #按下回车键
wait("1577764002167.png",10)
click("1577770208466.png")
wait(5)
if exists("1577784432204.png"):        #判断预期图片是否出现
    a=20
    
click("1577770540714.png")
click("1577770441068.png")
wait(2)
click("1577770467721.png")
print a

 


It may be a bit slow when running, because it searches for elements on the entire screen. It can be used to fix the area of ​​​​the search element to speed up the search for elements. Of course, there are also disadvantages. If the program changes the area, it will not be recognized.

Region(596,325,220,315).wait("1481855580087.png") limits the search image area

4. Call Sikuli in python

Since Sikuli is written in java, you can use jpython in python, or install JPype in python to call java code

This article introduces the following methods of using JPype

1. First install the Jpype package: open the command line and enter pip install JPype1 to install, it will prompt that the installation is successful. If the installation fails, it may be caused by the lack of VCForPython27 in Windows. You need to install this component. Download link: https://pan.baidu.com/s /1ILVxjb3K4hMvviCbefpfIw Extraction code: 7uri ; If you can’t install it after downloading, you can only download the compressed package of Jpype1 for installation. After downloading the installation package, find the command where the file is located and execute pip install JPype1-0.6.3.tar.gz

2. Download the jar package of sikuli, address: https://raiman.github.io/SikuliX1/downloads.html

3. Put the jar package downloaded in the previous step into a directory

from jpype import *
import time
# 需安装VCForPython27
# C:\Program Files\Java\jdk1.8.0_181\jre\bin\server\jvm.dll
print getDefaultJVMPath()  #jvm默认路径
startJVM(getDefaultJVMPath(), "-ea", r"-Djava.class.path=E:\Test3\sikulixapi-2.0.1.jar")#path是刚才放的jar包位置,启动java虚拟机
java.lang.System.out.println("hello world")#调用java打印方法
app = JClass('org.sikuli.script.App')
app_path = r'C:\Program Files (x86)\NGVONE\Client\TopSAP.exe'
# app.open(app_path)
Screen = JClass("org.sikuli.script.Screen")#获取java类
screen = Screen()                         #生成类对象
Key = JClass("org.sikuli.script.Key")
key = Key()
Pattern = JClass('org.sikuli.script.Pattern')
KeyModifier = JClass('org.sikuli.script.KeyModifier')
screen.doubleClick(r"E:\Test3\pic\1.png")#调用类对象的方法,双击快捷图片启动
screen.click(r'E:\Test3\pic\1577694966548.png')
time.sleep(1)
screen.type("test000")
time.sleep(2)
screen.click(r'E:\Test3\pic\1577696921363.png')
screen.type("111111")
screen.type(Key.ENTER)
screen.wait(1)
 
shutdownJVM()#关闭虚拟机


5. Sikuli-xIDE tool generates code command line calls

The code generated by Sikuli-xIDE is a folder with the suffix .sikuli, open it to see a python file and pictures in the code

  

 

command line call

import os
os.popen(r'E:\sikulix\sikulix.jar -r C:\Users\hp\Desktop\2.sikuli')
The parameter is the path where the ide is located and the path where the script is located
-r means run

reference documents

https://blog.csdn.net/zhengshaolong8125/article/details/53690689 Sikuli-X is simple to use
http://sikulix.com/ official website
https://blog.csdn.net/shuihupo/article/details/79714949 python Install jpype
https://blog.csdn.net/lb245557472/article/details/83957563 Python calls Sikuli Jar package
https://testerhome.com/topics/12706 Automation tool Sikuli-X simple use
https://raiman.github .io/SikuliX1/downloads.html SikuliX Downloads
https://blog.csdn.net/GG9527li/article/details/86726417 Python jpype calls Sikuli to realize image click, input, drag and other operations
https://testerhome.com/topics /17225 ATX SikuliX usage notes
https://blog.csdn.net/airfer/article/details/47726939 sikuli function, simple event operation personal summary notes
https://blog.csdn.net/lb245557472/article/details/83957563 Python Call Sikuli Jar package
 

Guess you like

Origin blog.csdn.net/qq_30273575/article/details/131398842