`
MyEyeOfJava
  • 浏览: 1149833 次
  • 性别: Icon_minigender_1
  • 来自: 北京
博客专栏
7af2d6ca-4fe1-3e9a-be85-3f65f7120bd0
测试开发
浏览量:71078
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

    压缩包中的唯一文件"Sikuli-X-1.0rc3 (r905)-win32.exe"是Sikuli X的安装程序,适用于32位Windows操作系统。用户只需运行这个文件,按照向导提示进行安装,即可在自己的机器上部署Sikuli X环境,开始进行GUI自动化...

    sikuli-script.jar

    在java中使用sikuli所需要的jar包。 对应sikuli的1.0最新版本。

    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-X.zip

    1. "Sikuli-X-1.0rc3 (r905)-win32.exe":这是Sikuli的一个早期版本的Windows安装程序,版本号为1.0 Release Candidate 3,修订版为905。用户可以运行这个程序来安装Sikuli,以便在Windows环境下使用。 2. "西西...

    sikuli-ide

    sikuli-ide.exe sikuli的安装包

    sikuli-setup.jar

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

    sikuli-ui自动化简易工具

    - **跨平台支持**:Sikuli 支持 Windows、Mac OS X 和 Linux 操作系统,适应各种环境的自动化需求。 - **简单易用的脚本语言**:Sikuli 使用 Python 的一种方言,称为 Sikuli Script,语法简洁,易于学习。 - **集成...

    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 IDE便携版

    只需将包含"Sikuli-r930-win32"的压缩包解压到任意位置,即可开始工作,节省了安装和配置的时间。 Sikuli IDE内部集成了Jython解释器,允许用户用类似Python的语法编写测试脚本。它提供了丰富的API,用于创建、匹配...

    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 1.0.1-All-Stable

    它的核心功能是基于图像识别,使得用户可以编写脚本来模拟人类在屏幕上的操作,如点击按钮、填写表单、拖放对象等。这个技术尤其适用于那些无法通过传统编程方式交互的界面,比如网页中的Flash元素或者桌面应用的...

    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