All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.phoenix.aop.ActionInvocationHandler Maven / Gradle / Ivy

Go to download

update:检查点bug修复,增加js执行的驱动,commandExecutor方法bug修复,驱动更新支持最新Firefox47/chrome51/IE10/IE11/IE Edge

There is a newer version: 1.5.0
Show newest version
package org.phoenix.aop;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Arrays;
import java.util.Date;
import java.util.LinkedList;

import org.phoenix.model.CaseLogBean;
import org.phoenix.model.UnitLogBean;
import org.phoenix.utils.ScreenShot;
import org.phoenix.utils.SystemInfo;

/**
 * @author mengfeiyang
 * 使用动态代理需要实现InvocationHandler接口
 * 
 */
public class ActionInvocationHandler implements InvocationHandler {
	private Object target = null;
	private LinkedList unitLog;
	private CaseLogBean caseLogBean;

	public ActionInvocationHandler(Object target,LinkedList unitLog,CaseLogBean caseLogBean) {
		this.target = target;
		this.unitLog = unitLog;
		this.caseLogBean = caseLogBean;
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args) {
		Object result = null;
		try{
			result = method.invoke(this.target, args);
			if(!method.getName().equals("webAPIAction") && !method.getName().equals("checkPoint") && !method.getName().equals("webElement") && !method.getName().equals("toString") && !method.getName().equals("getData")){
				unitLog.add(new UnitLogBean("步骤 [ "+method.getName()+" ]执行成功,参数值:"+Arrays.toString(args)+",执行结果返回值:"+result,method.getName(),"STEP","SUCCESS","",caseLogBean));
				PhoenixLogger.info("步骤 [ "+method.getName()+" ]执行成功,参数值:"+Arrays.toString(args)+",执行结果返回值:"+result);
			}
		}catch(Exception e){
			String picPath = null;
			String picWebPath = null;
			if(SystemInfo.isWindows()){
				long picName = new Date().getTime();
				picPath = ScreenShot.TakeScreenshot(caseLogBean.getAttachPath()+"/screenshot/"+picName+".jpg");
				picWebPath = "点击查看";
			} else {
				picPath = picWebPath = "Linux系统下不支持截图";
			}
			unitLog.add(new UnitLogBean("步骤 [ "+method.getName()+" ]执行失败,参数值:"+Arrays.toString(args)+",异常信息:"+e.getClass().getSimpleName()+",msg:"+e.getMessage()+",caused by:"+e.getCause().toString(),method.getName(),"STEP","FAIL",picWebPath,caseLogBean));
			PhoenixLogger.info("步骤 [ "+method.getName()+" ]执行失败,参数值:"+Arrays.toString(args)+",异常信息:"+e.getClass().getSimpleName()+",msg:"+e.getMessage()+",caused by:"+e.getCause().toString()+",截图路径:"+picPath);
		}
		return result;
	}

	public Object getProxy() {
		return Proxy.newProxyInstance(this.target.getClass().getClassLoader(),this.target.getClass().getInterfaces(), this);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy