`
MyEyeOfJava
  • 浏览: 1124852 次
  • 性别: Icon_minigender_1
  • 来自: 北京
博客专栏
7af2d6ca-4fe1-3e9a-be85-3f65f7120bd0
测试开发
浏览量:70171
533896eb-dd7b-3cde-b4d3-cc1ce02c1c14
晨记
浏览量:0
社区版块
存档分类
最新评论

[sikuli]-设置环境,图片,OS等

阅读更多

General Settings and Access to Environment Information

Sikuli Level

Sikuli internally uses the class Settings to store globally used settings. Publicly available attributes may be accessed by using Settings.[name-of-an-attribute] to get it’s value and Settings.attribute = value to set it. It is highly recommended to only modify attributes, that are described in this document or when you really know, what you are doing.

Actually all attributes of some value for scripting are described in the topic Controlling Sikuli Scripts and their Behavior.

Jython/Python Level

You may use all settings, that are defined in standard Python/Jython and that are available in your system environment. The modules sys and time are already imported, so you can use their methods without the need for an import statement.

sys.path may be one of the most valuable settings, since it is used by Python/Jython to locate modules, that are referenced using import module. It is a list of path’s, that is e.g. maintained by Sikuli to implement Importing other Sikuli Scripts as a standard compliant feature.

If you want to use sys.path, it is recommended to do it as shown in the following example, to avoid appending the same entry again:

myPath = "some-absolute-path"
if not myPath in sys.path:
        sys.path.append(myPath)

Java Level

Java maintains a global storage for settings (key/value pairs), that can be accessed by the program/script. Sikuli uses it too for some of it’s settings. Normally it is not necessary to access these settings at the Java level from a Sikuli script, since Sikuli provides getter and setter methods for accessing values, that make sense for scripting. One example is the list of paths, that Sikuli maintains to specify additional places to search for images (please refer to Importing other Sikuli Scripts for more information).

If needed, you may access the java settings storage as shown in the following example:

import java

# get a value
val = java.lang.System.getProperty("key-of-property")

# set a property's value
java.lang.System.getProperty("key-of-property", value)

Image Search Path

Sikuli maintains a list of locations to search for images when they are not found in the current .sikuli folder (a.k.a. bundle path). This list is maintained internally but can be inspected and/or modified using the following functions:

getImagePath()

Get a list of paths where Sikuli will search for images.

# getImagePath() returns a Java array of unicode strings
imgPath = list(getImagePath()) # makes it a Python list
# to loop through
for p in imgPath:
        print p
addImagePath(a-new-path)

Add a new path to the list of image search paths

removeImagePath(a-path-already-in-the-list)

Remove a path from the list of image search paths

Note: paths must be specified using the correct path separators (slash on Mac and Unix and double blackslashes on Windows).

This list is automatically extended by Sikuli with script folders, that are imported (see: Importing other Sikuli Scripts), so their contained images can be accessed. If you want to be sure of the results of your manipulations, you can use getImagePath and check the content of the returned list. When searching images, the path’s are scanned in the order of the list. The first image file with a matching image name is used.

Note: Behind the scenes this list is maintained in the java property store with the key SIKULI_IMAGE_PATH. This can be preset when starting the JVM using the environment variable SIKULI_IMAGE_PATH and can be accessed at runtime using the approach as mentioned under Accessing Settings - Java level. Be aware, that this is one string, where the different entries are separated with a colon ( : ).

The default bundle path can also be accessed and modified by the two functions below:

setBundlePath(path-to-a-folder)

Set the path for searching images in all Sikuli Script methods. Sikuli IDE sets this automatically to the path of the folder where it saves the script (.sikuli). Therefore, you should use this function only if you really know what you are doing. Using it generally means that you would like to take care of your captured images by yourself.

Additionally images are searched for in the SIKULI_IMAGE_PATH, that is a global list of other places to look for images. It is implicitly extended by script folders, that are imported (see: Reuse of Code and Images).

getBundlePath()

Get a string containing a fully qualified path to a folder containing your images used for finding patterns. Note: Sikuli IDE sets this automatically to the path of the folder where it saves the script (.sikuli). You may use this function if, for example, to package your private files together with the script or to access the picture files in the .sikuli bundles for other purposes. Sikuli only gives you to access to the path name, so you may need other python modules for I/O or other purposes.

Other places, where Sikuli looks for images, might be in the SIKULI_IMAGE_PATH.

Other Environment Information

Env.getOS()
Env.getOSVersion()

Get the type ( getOS() ) and version ( getOSVersion() ) of the operating system your script is running on.

An example using these methods on a Mac is shown below:

# on a Mac
myOS = Env.getOS()
myVer = Env.getOSVersion()

if myOS == OS.MAC:
        print "Mac " + myVer # e.g., Mac 10.6.3
else:
        print "Sorry, not a Mac"

myOS = str(Env.getOS())
if myOS == "MAC" or myOS.startswith("M"):
        print "Mac " + myVer # e.g., Mac 10.6.3
else:
        print "Sorry, not a Mac"

New in version X1.0-rc2.

Env.getSikuliVersion()

Get the version of Sikuli.

Returns:
a string containing the version text of the IDE window title without “Sikuli “

An example for Sikuli X-1.0rc2:

if not Env.getSikuliVersion() == "X-1.0rc2":
        print "This script needs Sikuli X-1.0rc2"
        exit(1)
Env.getClipboard()

Get the content of the clipboard if it is text, otherwise an empty string.

Note: Be careful, when using Env.getClipboard() together with paste(), since paste internally uses the clipboard to transfer text to other applications, the clipboard will contain what you just pasted. Therefore, if you need the content of the clipboard, you should call Env.getClipboard() before using paste().

Tip: When the clipboard content was copied from a web page that mixes images and text, you should be aware, that there may be whitespace characters around and inside your text, that you did not expect. In this case, you can use Env.getClipboard().strip() to get rid of surrounding white spaces.

New in version X1.0-rc2.

Env.isLockOn(key-constant)

Get the current status ( on / off ) off the respective key. Only one key can be specified.

Parameters: Returns:
  • key-constant – one of the key constants Key.CAPS_LOCKKey.NUM_LOCKKey.SCROLL_LOCK

True if the specified key is on, False otherwise

Further information about key constants can be found in Class Key.

New in version X1.0-rc2.

Env.getMouseLocation()

Get the current location of the mouse cursor.

Returns:
Location object of the position of the mouse cursor on the screen.

 

分享到:
评论

相关推荐

    Sikuli-Script-2.0.4.jar

    Sikuli-Script,可以结合selenium使用,操作浏览器的插件栏地址栏之类的HTML结构之外的区域。本jar包是2021年1月的最新版本。后续应该有更新的。

    Sikuli-X-1.0rc3 (r905)-win32

    GUI自动化测试的好工具,python语法,代码中可插入界面截图,鼠标会自动寻找并点击等等

    sikuli-script.jar

    sikuli整合java的jar包,将sikuli-script的jar包导入java,可创建screen事件,能调用sikuili文件

    sikuli-slides_windows-x64_1_5_0

    sikuli-slides_windows-x64_1_5_0

    Sikuli-X-1.0rc3 (r905)-win32.exe

    点点鼠标,即可实现软件测试自动化,很简单,快来试试吧

    sikuli-slides_windows_1_5_0

    sikuli-slides_windows_1_5_0

    sikuli-ide

    sikuli-ide.exe sikuli的安装包

    sikuli-setup.jar

    一款基于图像匹配技术的开源自动化测试框架。可以与其他测试框架集成使用。附上一篇介绍文:http://www.softwaretestinghelp.com/sikuli-tutorial-part-1/# 文中有sikuli的简介、安装及一些使用方法

    sikuli-ui自动化简易工具

    sikuli-ui自动化简易工具

    Sikuli-1.0.1-Supplemental-LinuxVisionProxy.zip

    New per 2014 Feb 20th: Having problems with bundled libVisionProxy.so? Try to build it using this package. NEW VERSION: More Automatics! Should do the job on more Linux systems (for version 1.0.1 ONLY...

    Sikuli-X.zip

    sikuli 自动化测试,会截图就会自动化测试

    sikuli-1.1.2.jar安装包及依赖包(直接启动,免联网下载安装)

    Sikuli是基于图形的脚本语言,本资源包含最新版1.1.2的sikuli安装包及相关依赖包,下载点击runsikulix.cmd可一键启动,无需联网下载安装。 新版的1.1.2版本亲测可支持jdk1.8.

    sikuli 32位和补丁包

    三、 我们将下载的文件sikuli-r930-win32.zip解压,然后得到一个SIKULI-IDE 的目录,把SIKULI-IDE目录下的所有文件替换Sikuli X下的所有文件。(这种做法有点2了!)做这一步的目的是r930关联文件修复了了最近的bug ...

    Sikuli IDE便携版

    Sikuli IDE便携版,直接引用到项目,就可使用,方便快捷

    图形化测试工具Sikuli

    Sikuli-1.0.1-Supplemental-LinuxVisionProxy

    sikuli-autoit-genie-util

    AutoIt、Genie、Sikuli 的跨平台实用程序 ... 该项目分为两部分: (1) AutoITExecutor--它是用于处理原生windows事件以及flash自动化的...需要为要在其上运行测试的特定平台设置环境。 有关特定平台要求,请参见下文。 作

    sikuli-ubuntu-vagrant-box:带有 Sikuli 的 Ubuntu 桌面 vagrant box

    #手动的东西转到框中的顶部工具栏并将语言从德语更改为英语打开桌面上的 sikuli 文件夹并在其中运行 jar ... 选中每个框,然后单击“立即设置” 现在你可以通过双击 sikuli 文件夹中的 sikuli-ide.jar 来运行 sikuli

    Sikuli Script

    MIT的研究人员设计了一种新颖的图形脚本语言Sikuli,计算机用户只须有最基本的编程技能(比如会写print"hello world"),他不需要去写出一行行代码,而是用屏幕截图的方式,用截出来的图形元素组合出神奇的程序。

Global site tag (gtag.js) - Google Analytics