[sikuli]-怎样在Eclipse与NetBean中使用sikuli

在这篇文章里,我建议如果你想使用python或者java来进行sikuli的编程,请你深入的读一下我的文章,例如如何在java项目中使用sikuli

你还需要知道一些用IDE开发的前置条件,例如如何在IDE里使用Jython

下面的方法只适用在windows 7 32位操作系统,以及Mac os X10.6,linux的使用者可以参考这些配置自己设置他们。

这可能是你选择使用IDE进行sikuli编程的一些理由:

  • 你想开发sikuli插件
  • 你需要debugger你的代码
  • 你需要一个很好的交互
  • 你需要和操作系统交互
  • 你需要一个专业的单元测试

想这样操作sikuli的要求:

安装 Sikuli

  • Windows: 同我之前的文章讲的一样,设置好你的sikuli环境变量
  • Mac: have Sikuli-IDE.app in its standard place /Applications. There is generally no need to put it elsewhere.
  • Linux: you generally have to take care for the environment yourself.

Meanings of shortcuts used:

  • path-to/sikuli-script.jar if we use this, it should be replaced by the absolute path to the file sikuli-script.jar, where you installed Sikuli.

Images and importing other Sikuli scripts

It is recommended to carefully read through Importing other Sikuli Scripts (reuse code and images), since you need to have a concept how to capture, how to name and where to store your images. As a first start, just decide to use Sikuli IDE in parallel to capture and store your images and use the import feature or the image path to make them available in your script.

Netbeans

下面的例子是针对 Netbeans 6.9.的步骤:

安装python插件

你需要安装 Jython 2.5.1.

Go to menu Tools -> Plugins -> Available Plugins

In the list select everything that is in the category Python and install. If suggested by the install process always restart Netbeans.

Configure for using Sikuli script features at runtime

The plugin itself has nothing to configure, that is of value for the Sikuli usage. Everything is done on the project level, though some basic preferences act like plugin globals - we just have to know and accept this ;-)

下面是安装步骤:

  • Start a new project: File -> New Project -> Categories: Python -> Python Project -> click Next
  • In the second step Name and Location (last line), select as Python Platform: Jython 2.5.1.
  • you might want to click Make Default, if you have real Python also available (Remember: Sikuli scripts cannot be run with real Python!)
  • To integrate Sikuli: click the button Manage (only needed with the first project - it is remembered)
  • on the tab Python Path we need an additional entry, that points to path-to/sikuli-script.jar/Lib.
    • Windows: click the button Add and click through to path-to/sikuli-script.jar. Before clicking Open, edit the filename so that it shows sikuli-script.jar\Lib.
    • Mac: since the Netbeans file dialog does not allow to dive into a bundle like Sikuli-IDE.app, we have to edit the preference file directly. Since it is the same with the Java path, we have documented it seperatly below Mac/Netbeans: select library path.
  • on the tab Java Path we need an additional entry, that points to path-to/sikuli-script.jar. If you have other Java libraries, that you need in your project, add them here too.

Now you are able to run your first script. Remember, that in every script including the main script, that you are editing now, as the first line you need from sikuli.Sikuli import *, to have access to the Sikuli features at runtime.

Everytime later on you might come back to the project’s preferences with File -> Project Properties (your-project’s-name) . You will find the above information in the categorie Python.

Prepare to use Code Completion for the Sikuli methods

The NetBeans editor in the Python plugin editor is not able to recognize Python classes and methods, as long as the respective source code is embedded inside a jar-file as it is the fact with Sikuli. If you want Code Completion to work, you have to extract the folder Lib/sikuli from sikuli-script.jar, place it somewhere and add the reference to this folder to the Python Path in the project’s preferences (see above: Configure Python Path).

To extract the folder Lib/sikuli from sikuli-script.jar you might use the jar utility, that comes with the Java JDK or any other utility, that allows to unjar a jar-file.

This is a Mac example how to use the jar uility, supposing it can be found on the system path:

  • in a Terminal window go to an appropriate folder, that should contain Lib/sikuli afterwards
  • run: jar -xf /Applications/Sikuli-IDE.app/Contents/Resources/Java/sikuli-script.jar Lib/sikuli

You might decide, to use a folder, that is already on the Python path. One folder that is designated by Jython to contain complementary sources, that needs to be imported, is the folder Lib/site-packages in the Jython installation directory. If you copy the folder sikuli here, you do not need an additional Python path entry.

Mac/NetBeans: Select library path

To perpare the preference file modification we first add the path to Sikuli-IDE.app on both tabs: click the button Add and click through to /Applications/Sikuli-IDE.app. Depending on your selected language, the folder Applications is named like you see it in the Finder. Save the preferences by clicking close and/or ok.

The preference file is located at /Users/your-name/.netbeans/6.9/build.properties. Since it is hidden, you might have to use the Finder option “Go to Folder” (Shift-Command-G), to open the folder /Users/your-name/.netbeans/.

Open the file build.properties in your favorite editor and search for the text /Applications/Sikuli-IDE.app. It should be at the end of 2 lines beginning with pythonplatform..

On the line beginning pythonplatform. ... .javalib= extend /Applications/Sikuli-IDE.app so that it reads: /Applications/Sikuli-IDE.app/Contents/Resources/Java/sikuli-script.jar.

On the line beginning pythonplatform. ... .pythonlib= extend /Applications/Sikuli-IDE.app so that it reads: /Applications/Sikuli-IDE.app/Contents/Resources/Java/sikuli-script.jar/Lib.

Save the file and restart Netbeans. It is a good idea to check, that the correct entries are found on the 2 tabs now.

Eclipse

This is based on Eclipse Helios 3.6. We suppose you have it running in a setup that allows to at least develop Java applications.

Since this is not a tutorial how to use Eclipse in general, you should be familiar with the basic concepts.

Install Python plugin (PyDev) and Jython

Since the top level language used by Sikuli script is Python, you need the Python plugin PyDev. Different from NetBeans, though PyDev is prepared to use Jython as interpreter, you have to install Jython on your own seperately.

So first install Jython, by downloading the version you want to use from the Jython download page. Sikuli currently is based on Jython 2.5.1, but you may choose Jython 2.5.2 as well. Install it according to Jythons installation HowTo.

After installation, make a test from a commandline by typing jython.bat (Windows) or jython (Mac/Linux) to open an interactive Jython session.

You might type the following (<enter> means pressing the enter/return key)

  • import os <enter>
  • import sys <enter>
  • for e in sys.path: print e <enter> <enter>
  • type exit() <enter> (to leave interactive Jython)

This shows the current Jython configuration of the Python path. Remember the place where Jython is installed.

Now we install the PyDev plugin from inside Eclipse: Menu Help -> Eclipse Marketplace. Either search it or find it on the Popular tab’s lower part. Simply click the Install button and do what you are asked to do ;-)

The next step is to tell Eclipse PyDev, where it can find the Jython interpreter. Navigate to the Eclipse Preferences pane and open the category PyDev and inside the subcategoryInterpreter-Jython. First try to Auto Config by clicking the appropriate button. If this does not work, click the button New, name the entry and navigate to the folder, where Jython was installed and select jython.jar. After clicking ok, a window Selection needed might come up: click Select all and ok to finalize this step.

Other options with PyDev are available, but not relevant for our actual matter (see documentation).

Configure for using Sikuli script features at runtime

Again we have a difference to Netbeans: The PyDev plugin does not allow library references to folders inside of jar-files in the respective configuration dialog (it does not insert them to the Python path), though Jython itself accepts them, when specified on the Python path. So if you want to run and debug your script in Eclipse, you have to extract the folder Lib/sikuli from sikuli-script.jar (find one HowTo here).

As with Netbeans, the library configuration is done in the project itself. So we open a new project:

  • Menu File -> New -> Project -> PyDev -> (open sublist) -> PyDev Project -> click Next button.

On the configuration pane name your project, select Jython as Project type, grammar version 2.5 (higher Python language versions are not supported by Jython 2.5.x) and click the Finish button. Your project is created. Add at least one you-name-it.py file to the source folder and put from sikuli.Sikuli import * as the first line.

In the last step, we tell PyDev, where to find the Sikuli libraries.

Goto Menu Project -> Properties -> select category PyDev - PYTHONPATH and go to the tab External Libraries. We need a reference to path-to/sikuli-script.jar and another one to the extracted folder Lib containing the folder sikuli.

  • reference to path-to/sikuli-script.jar

    • Windows: click button Add zip/jar/egg and select sikuli-script.jar from the Sikuli installation.
    • Mac: As with NetBeans, the file dialog does not allow to step inside Sikuli-IDE.app. So we use the trick, to define a String Substitution Variable: on the respective tab click Add variable, name it e.g. sikuli-script and enter as value: /Applications/Sikuli-IDE.app/Contents/Resources/Java/sikuli-script.jar. Go back to the tab External Libraries and click Add based on variable. In the entry field enter: ${sikuli-script} and click OK.
  • reference to the extracted folder Lib containing the folder sikuli
    • click Add source folder and select the folder Lib in the place you had it extracted.
    • this is not needed, if you have moved the extracted folder sikuli to a folder, that is already on the Python path (e.g. jython-intallation/Lib/site-packages).

Now you are able to run your first script. Remember, that in every script including the main script, that you are editing now, as the first line you need from sikuli.Sikuli import *, to have access to the Sikuli features at runtime.

Everytime later on you might come back to the project’s preferences with Project -> Properties.

Code Completion works from the start without any further configuration and even steps into the Java classes where appropriate.

 

不用看全文,光黑体字就完全可以明白了,不翻译了。

时间: 2025-01-21 10:24:05

[sikuli]-怎样在Eclipse与NetBean中使用sikuli的相关文章

如何在java中使用sikuli进行自动化测试

很早之前写过一篇介绍sikuli的文章.本文简单介绍如何在java中使用sikuli进自动化测试. 图形脚本语言sikuli   sikuli IDE可以完成常见的单击.右击.移动到.拖动等鼠标操作,java引用sikuli-script.jar同样可以执行这些常见的鼠标操作,因此即可方便的编写java实现识别图片并模拟点击/拖动目标控件. sikuli-script.jar:http://download.csdn.net/download/hqd1986/4557974 将sikuli-sc

Eclipse V3.1中的Java泛型支持

Java 中的泛型 几乎从第一个版本开始,Java 技术的创立者们就已经开始讨论对该语言添加 泛型支持.C++ 通过标准模板库对泛型进行支持,但是由于缺少所有其他类(嵌 入在 Java 语言中的Object 类中)的一个统一父类,泛型的实现也受到阻碍.Java编程语言的泛型支持是其历史上最重大的语法变化.由于某些显而易见的原因,工具支持比其他 SDK 升级的步法要慢得多.尽管如此,现在 Eclipse V3.1 已经对这些语言的新特性有了出色的支持.本文重点介绍其中的一些新特 性. Java 5

eclipse rcp 代码中获取action对象

问题描述 eclipse rcp 代码中获取action对象 请问有没有什么办法可以在Activator中获取extensions中添加的工具栏或者菜单栏按钮对象,这样可以在代码中控制每一个action对应图标的样式,以及各action的可用和不可用状态.

在Eclipse的DDMS中的File Explorer找不到files文件夹

问题描述 在Eclipse的DDMS中的File Explorer找不到files文件夹 尝试着想用openFileOutput方法存储信息,本来应该能在data/data/../file文件夹中找到我存储的文件,却发现没有file文件夹,只有cache和lib文件夹,这是为什么? 以下是代码: public void Save(String text){ FileOutputStream out = null; BufferedWriter writer = null; try{ out =

eclipse maven项目中一个war类型的项目加载进tomcat时,只加载了WEB-INF

问题描述 eclipse maven项目中一个war类型的项目加载进tomcat时,只加载了WEB-INF 我遇到这样一个问题,我有一个maven的项目,其中有一个war类型的子模块,当我想在tomcat7上面运行时,我查看了其下面的项目,发现仅仅是加载了WEB-INF文件夹里面只有classs文件也就是只有java跟resource中的东西没有webapp文件夹下的内容,甚至连其下面的web.xml文件都没有加载进来,JSP及其他文件夹都没有加载..

如何在eclipse rcp_gef应用中实现eclipse的outline视图的工具条栏?

问题描述 如何在eclipse rcp_gef应用中实现eclipse的outline视图的工具条栏? 如图,这是系统的outline,有工具条的 如图,这是gef应用中做的outline,无工具条 如图,这就是要实现的工具条以及其上的功能,亦是问题之所在 求高手,求解! 这是MyGraphicalEditor类中实现outline的代码: protected class OutlinePage extends ContentOutlinePage { private ScrollableThu

eclipse j2ee版本中怎么没有database explorer?

问题描述 想在eclipse中反向生成hibernate实体类,但是却在eclipse j2ee版本中找不到database,有没有什么插件,给个地址 问题补充:Rainbow702 写道 解决方案 是不是你没打开那个视图啊?到 show perspective 中去找看看解决方案二: 嗯,晚上我也查了一下,我说的那两者都有,但你要的那个的确是没有找着,不好意思解决方案三: 不是,eclipse 肯定也是有 show view 这个的解决方案四: 那你看看 show view 呢,我记得是有的解

jta-我不知道如何在netbean中给表赋值!!求大神

问题描述 我不知道如何在netbean中给表赋值!!求大神 public void QueryAll() { SAXReader reader=new SAXReader(); String classPath=ClassLoader.getSystemResource("").getPath(); System.out.println(classPath); filename=classPath+"students.xml"; File file=new File

报错-eclipse 运行过程中经常跳出错误提示

问题描述 eclipse 运行过程中经常跳出错误提示 解决方案 应该是你的项目有问题才会出现这种问题,检查你的项目. 解决方案二: 这是你导入的别人的工程吗,可能是你的环境没有引入项目需要的jar,或者原来项目引用的文件在你的环境中missing. 解决方案三: eclipse中经常提示:TheserializableclassAddUserFormdoes错误解决方法eclipse运行JSP文件时,提示tomcat错误 解决方案四: 将该工程关闭!就可以了,应该是你运行的项目带着其他项目一同运