自动化测试 http://blog.okbase.net/j1154632528 GUI测试__java代码__模拟鼠标操作 http://blog.okbase.net/j1154632528/archive/56375.html j1154632528 2017/9/1 21:30:58  

 

 

一、具体代码如下

package www.woniu.auto;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.io.IOException;

public class RobotMouse {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			
			Runtime.getRuntime().exec("calc.exe");//启动计算器
			Thread.sleep(3000);
			
			
			Robot robot= new Robot();
			robot.mousePress(InputEvent.BUTTON1_MASK);//robot__鼠标__左键__点击
			robot.mouseRelease(InputEvent.BUTTON1_MASK);//robot__鼠标__左键__点击后释放
			Thread.sleep(20000);
			
			robot.mousePress(InputEvent.BUTTON3_MASK);
			robot.mouseRelease(InputEvent.BUTTON3_MASK);
			Thread.sleep(20000);
			
			//程序退出
			robot.keyPress(KeyEvent.VK_ALT);//robot__键盘___Alt__点击
			robot.keyPress(KeyEvent.VK_F4);
			robot.keyRelease(KeyEvent.VK_ALT);
			robot.keyRelease(KeyEvent.VK_F4);//robot__键盘___Alt__点击后释放
			
			
		} catch (AWTException e) {
			// TODO Auto-generated catch block  
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block  InterruptedException  IOException
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block  InterruptedException  IOException
			e.printStackTrace();
		}

	}


}

 

代码如上

 

 

 

 

 

 

 

 

]]>