关于 LDTP 操纵 windows 控件。

LDTP doc: java

https://ldtp.freedesktop.org/user-doc/

对于 web 自动化,咱们用 Selenium, 可是对于 windows 控件,咱们能够使用 LDTP。
python

 

 首先,须要引用的 jar 包。
web

 

CobraWinLDTP-3.0.0.msi (这个是须要安装的,安装到 C:\Program Files (x86)\VMware\CobraWinLDTP, 而核心的文件就是
CobraWinLDTP.exe。也就是它真正操做了 windows 控件。) 
commons-codec-1.6.jar
commons-logging-1.1.2.jar
LDTP.jar
ws-commons-util-1.0.2.jar
xmlrpc-client-3.1.3.jar
xmlrpc-common-3.1.3.jar
 

 

上面第一个是安装 vmware 的 LDTP。 windows

Ldtp不须要安装 python,也不须要安装 jep,它只须要外部有 CobraWinLDTP.exe,并按照 client-server 的方式工做。ldtp.jar是client,先经过启动进程的方式运行CobraWinLDTP.exe,而后经过xmlrpc协议,把java的命令变成调用CobraWinLDTP.exe的命令,从而能够识别控件、操纵控件

 

(对,java调用pywinauto时,须要依赖jep这个桥梁来把java的命令变成python端的,jep就是负责传递命令的)
app

 

因为 CobraWinLDTP.exe 是 server 端,因此先须要在命令行中启动 CobraWinLDTP.exe。
命令行

 

而后看代码:code

 

package ldtp;

import com.cobra.ldtp.Ldtp;

public class TestLdtp {
    public static void main(String[] args) {
        Ldtp ldtp = new Ldtp("abc");
        String[] wins = ldtp.getWindowList();
        for (String win : wins)
        {
            System.out.println(win);
        }
    }
}
====打印结果====

 

 

paneTaskbar
frmEclipse SDK
frm?????? - ??? - Mozilla Firefox
frmNew Tab
frmWeChat
frmD:\EclipseSpaceNew\LdtpTestNew\lib
frmC:\Program Files (x86)\VMware\CobraWinLDTP
frmAdministrator: Command Prompt - CobraWinLDTP.exe
frmUntitled - Paint
lst0
paneProgram Manager

 

上面代码中的 "abc" 是随便一个名字。这段代码能够打印出全部的 frame。而后你找到你须要的,就能够继续操做了。
orm

 

下面是打开 notepad 后一些操做的代码

server

 

package ldtp;

import com.cobra.ldtp.Ldtp;

public class TestLdtp {
    public static void main(String[] args) {
        String winStr = "frmUntitled - Notepad"; //Open Notepad first please
        Ldtp ldtp = new Ldtp(winStr);
        String[] wins = ldtp.getWindowList(); //Print all windows
        for (String win : wins)
        {
            System.out.println(win);
        }
        ldtp.activateWindow(winStr);
        System.out.println("=================");
        String[] objects = ldtp.getObjectList(); //Print all objects
        for (String ob : objects)
        {
            System.out.println(ob);
        }
//        ldtp.click("mnuView"); //This can click the View menu
        ldtp.selectMenuItem("View;Status Bar"); //Click View > Status Bar
        ldtp.appendText("txtTextEditor", "hello allen");
    }
}

 

 

====打印结果====

 

 

paneTaskbar frmEclipse SDK frmUntitled - Notepad frm?????? - ??? - Mozilla Firefox frmNew Tab frmslc12dkq-16-2012-OBIEEServer - Remote Desktop Connection Manager v2.2 frmD:\sw\UIAVerify2.0_x86 frmNow Playing frmAdministrator: Command Prompt - CobraWinLDTP.exe frmD:\00???? pane1 pane2 paneChatContactMenu lst0 paneProgram Manager ================= txtTextEditor uknVertical btnLineup btnLinedown uknHorizontal btnColumnleft btnColumnright ukn2 ukn3 lbl0 lblLn1,Col1 ukn4 mnuSystem mnuSystem1 btnMinimize btnMaximize btnClose mnuApplication mnuFile mnuEdit mnuFormat mnuView mnuHelp
 
相关文章
相关标签/搜索